Article View: muc.lists.freebsd.bugs
Article #765[Bug 301166] ng_socket: ngc_send() accepts an arglen that does not match the sent message, so ngs_rcvmsg() copies kernel heap in...
From: bugzilla-noreply
Date: Thu, 26 Nov 2026 21:05
Date: Thu, 26 Nov 2026 21:05
97 lines
5771 bytes
5771 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301166
Bug ID: 301166
Summary: ng_socket: ngc_send() accepts an arglen that does not
match the sent message, so ngs_rcvmsg() copies kernel
heap into the caller's socket
Product: Base System
Version: 15.1-RELEASE
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: laamalif@proton.me
A netgraph control message can claim a payload larger than
the bytes actually sent, and the reply path trusts the claim:
the sender reads kernel heap back through its own socket.
Host root and vnet-jail root can trigger it; a jailed root
receives host kernel heap.
To reproduce, load ng_socket, build the attached reproducer,
and run it twice as root: the control sends a well-formed
NGM_NODEINFO message, the trigger 8 bytes with arglen 4096 at
bytes 4 through 7, addressed to the node path ".". On
15.1-RELEASE-p7:
$ kldload ng_socket
$ ./ng_arglen_probe --cookie
caller: uid=0 euid=0 mode=control
sent 56 bytes (arglen field = 0)
read returned 128 bytes
header size 56, payload 72 bytes (arglen said 72)
non-zero non-sent payload bytes: 7 of 72
$ ./ng_arglen_probe
caller: uid=0 euid=0 mode=trigger
sent 8 bytes (arglen field = 4096)
read returned 4152 bytes
header size 56, payload 4096 bytes (arglen said 4096)
non-zero non-sent payload bytes: 816 of 4096
first 64 payload bytes:
00 00 00 00 00 00 00 00 72 74 73 6f 6c 64 00 6e 74 00 00 00 00 00 00 00 72 74
73 6f 6c 64 00 00
00 00 00 00 00 00 00 00 73 68 00 00 00 00 00 00 00 00 00 00 00 00 00 00 73 68
00 0c 00 f8 ff ff
The control's reply is the correct 128-byte node description
whose payload is the node name. The trigger's reply carries
kernel memory from past the 9-byte allocation: in the paste,
"rtsold" and "nt" from neighboring allocations, further bytes
resolving to 0xfffff800-range kernel pointers. On
16.0-CURRENT the same trigger returned repeated
0xffffffff8323a0e0 pointers and 0xdeadc0de values.
Under jail -c with vnet, the reproducer run as the jail's
root returned the same 4152-byte result; one run's payload
carried "tail" and "ntpd", another "sshd-session". The VIMAGE
privilege switch in sys/kern/kern_jail.c grants a vnet jail's
root PRIV_NETGRAPH_CONTROL, admitting it to the control
socket.
In sys/netgraph/ng_socket.c, ngc_send() allocates len + 1
bytes and validates only header.version, never comparing
header.arglen to len; the socket node's receive handler then
m_devget()s sizeof(struct ng_mesg) + arglen bytes from the
allocation into the sender's queue. The generic handlers
in ng_base.c that read the message argument check its length
first; the socket node's does not. A large
positive arglen would walk the copy toward unmapped memory, so
the missing check is also a crash risk.
The fix restores the invariant the NG_MKMESSAGE producers
already maintain, that arglen equals the bytes following the
header. Built into the module against the 15.1-RELEASE-p7
source and loaded, the trigger fails at sendto with EINVAL and
the control still returns the correct node description; a
vnet jail gets the same rejection, and the stock module
restored leaks again.
I did not run 14.4 or any other branch, the patched module on
CURRENT, or the crash variant, and ran everything on amd64
only. The reproducer exits 0 when it ran, 1 on a runtime error,
2 on usage; --cookie selects the control.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID:
<bug-301166-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 301166] ng_socket: ngc_send() accepts an arglen that does not match the sent message, so ngs_rcvmsg() copies kernel heap into the caller's socket Date: Thu, 26 Nov 2026 21:05:32 +0000 Organization: Newsgate at muc.de e.V. Approved: news-admin@muc.de Distribution: world Message-ID: <bug-301166-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="77435"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795727132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6apKuggacVgAhf5DN2lJtVkjJFldMFRf7GA6g1Nvdq4=; b=ASJ06dR+gE1XNuqhyiEeAj/pSmvQtIkl+p5t2X3CCvJJFDK41QxOLx7yXknW0OKL8ZRqGS 9nGUgOm29fXIkRG7TbMDpvhj8vaouBIaK6xhFp6dE5yvVkI1C+SGShbab+GLr3ANfgikEY Tzcc96TEa/TvVnpdNmWj3fHiZ8s0MAMCw/103SOF3/Jh9lEGZH2OVVUYTp0WxzcgCa7lzA /XUIuPw39VJnpNytycSaMedyWaDEC7ppHFOEIKL5t6EbtUqzfYBwcydIF6CN9h499mdbhs ey5PVtDhsrAXUKXCgo3XTEal05bWvd9OhfdAIkpT7T2ZGHFhybTSpNF+Rl0CdQ== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes