From: Andrey Misiurov <amisiurov@cloudlinux.com>
To: "Rémi Denis-Courmont" <remi@remlab.net>,
"David S . Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>
Cc: "Simon Horman" <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
"Andrey Misiurov" <amisiurov@cloudlinux.com>,
"Rémi Denis-Courmont" <courmisch@gmail.com>
Subject: [PATCH net v2] phonet: do not autobind a socket to port 0
Date: Tue, 1 Dec 2026 07:40:39 +0100 [thread overview]
Message-ID: <20261201064121.2113989-1-amisiurov@cloudlinux.com> (raw)
In-Reply-To: <20261119122127.1708071-1-amisiurov@cloudlinux.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 2747 bytes --]
pn_sock_get_port() walks the local port range to pick a free port for an
autobinding socket. net.phonet.local_port_range may start at 0 because the
sysctl lower bound is 0, so the very first candidate can be port 0.
For port 0 pn_find_sock_by_sa() falls back to matching by resource and
usually returns NULL, so port 0 is accepted. The socket then gets
pn->sobject = pn_object(0, 0) == 0 and is hashed into bucket 0. The next
lookup that walks bucket 0 -- another autobind, the same socket's next
sendmsg, or an incoming packet to an object whose low nibble is 0 -- hits
BUG_ON(!pn->sobject) in pn_find_sock_by_sa():
kernel BUG at net/phonet/socket.c:77!
Oops: invalid opcode: 0000 [#1] PREEMPT SMP KASAN
CPU: 1 PID: 6883 Comm: phonet_bug
RIP: 0010:pn_find_sock_by_sa+0x3a9/0x590 [phonet]
Call Trace:
pn_sock_get_port+0x1da/0x4b0 [phonet]
pn_socket_bind+0x312/0x580 [phonet]
pn_socket_autobind+0xaf/0x160 [phonet]
pn_socket_sendmsg+0x4b/0xe0 [phonet]
__sock_sendmsg+0x1ab/0x200
__sys_sendto+0x1eb/0x300
__x64_sys_sendto+0xe8/0x1d0
do_syscall_64+0x102/0x2d0
entry_SYSCALL_64_after_hwframe+0x76/0x7e
It is deterministic once net.phonet.local_port_range is configured to
include port 0. Skip port 0 when searching for a free port; 0 is reserved
for the unbound state and must never be handed out.
Fixes: 87ab4e20b445 ("Phonet: proc interface for port range")
Acked-by: Rémi Denis-Courmont <courmisch@gmail.com>
Signed-off-by: Andrey Misiurov <amisiurov@cloudlinux.com>
---
v2:
- correct the Fixes tag: the real introducer is 87ab4e20b445, which made
the port range configurable with a lower bound of 0; the previous tag
5b0c911bcdbd was a later, unrelated change (Sashiko AI review).
- drop the inaccurate "unprivileged" wording -- opening an AF_PHONET
socket requires CAP_SYS_ADMIN (Sashiko AI review).
- the sysctl still accepting a lower bound of 0 is left to a separate
patch; this one keeps the allocator-side fix.
v1: https://lore.kernel.org/all/20261119122127.1708071-1-amisiurov@cloudlinux.com/
Found during a review of the CVE-2026-53292 backport.
Reproduced on debian13 6.12.88 (CONFIG_PHONET):
set net.phonet.local_port_range to "0 0", then send on an unbound AF_PHONET
SOCK_DGRAM socket so it autobinds -> the port-0 BUG above. With this patch
the same sequence no longer crashes.
net/phonet/socket.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -490,6 +490,8 @@
port_cur++;
if (port_cur < pmin || port_cur > pmax)
port_cur = pmin;
+ if (!port_cur)
+ continue;
pn_sockaddr_set_port(&try_sa, port_cur);
tmpsk = pn_find_sock_by_sa(net, &try_sa);
prev parent reply other threads:[~2026-12-01 6:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 12:21 [PATCH net] phonet: do not autobind a socket to port 0 Andrey Misiurov
2026-11-20 8:17 ` Rémi Denis-Courmont
2026-11-23 12:36 ` netdev-bot+sashiko
2026-11-28 14:12 ` Simon Horman
2026-12-01 6:40 ` Andrey Misiurov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201064121.2113989-1-amisiurov@cloudlinux.com \
--to=amisiurov@cloudlinux.com \
--cc=courmisch@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=remi@remlab.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.