๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20963

Re: [PATCH net] phonet: do not autobind a socket to port 0

#20963
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 12:36
145 lines
13001 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 2 ยท Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The Fixes: tag points to the wrong commit.
- [Medium] The commit message says the crash is "deterministic and
  triggerable by an unprivileged socket".
- [Low] After this patch the sysctl and the allocator disagree about port
  0.

--

phonet: do not autobind a socket to port 0

This patch makes pn_sock_get_port() skip port 0 when it searches for a
free port during autobind. Without it, a net.phonet.local_port_range that
starts at 0 lets a socket be hashed with sobject == 0. The next walk of
hash bucket 0 then hits BUG_ON(!pn->sobject) in pn_find_sock_by_sa().

> It is deterministic and triggerable by an unprivileged socket. Skip port 0
> when searching for a free port; 0 is reserved for the unbound state and must
> never be handed out.

[Severity: Medium]

Is the "unprivileged" part accurate? pn_socket_create() refuses to create
any AF_PHONET socket without CAP_SYS_ADMIN in the initial user namespace:

net/phonet/af_phonet.c:pn_socket_create() {
    ...
	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;
    ...
}

Port 0 is also only a candidate after a range starting at 0 is written to
net.phonet.local_port_range. That sysctl is registered only in init_net,
with mode 0644:

net/phonet/sysctl.c:phonet_sysctl_init() {
	phonet_table_hrd = register_net_sysctl(&init_net, "net/phonet", phonet_table);
    ...
}

The default range is DYNAMIC_PORT_MIN..DYNAMIC_PORT_MAX (0x40..0x7f), which
does not include 0.

The incoming packet path in the commit message also needs a socket already
hashed with sobject 0, so it needs the same setup.

So the crash seems to need init namespace root to set the range, plus a
process with CAP_SYS_ADMIN. This commit message came out of a CVE backport
review. Could it state the privilege requirements more precisely?

> Fixes: 5b0c911bcdbd ("net: phonet: do not BUG_ON() in pn_socket_autobind() on failed bind")

[Severity: Medium]

Is this the right commit for the Fixes tag? 5b0c911bcdbd only changed the
-EINVAL handling in pn_socket_autobind():

	if (err != -EINVAL || unlikely(!pn_port(pn_sk(sock->sk)->sobject)))
		return err;

The port 0 crash described here never takes that branch. With
local_port_range set to "0 0", the first autobind succeeds:

pn_socket_autobind()
  pn_socket_bind()
    pn_sock_get_port()    port_cur == 0, nothing found in bucket 0
    pn->sobject = pn_object(0, 0) == 0
    sk->sk_prot->hash()   socket hashed into bucket 0
  returns 0

On the next autobind, this check in pn_socket_bind() still passes, because
pn_port(pn->sobject) is 0:

	if (sk->sk_state != TCP_CLOSE || pn_port(pn->sobject)) {
		err = -EINVAL; /* attempt to rebind */
		goto out;
	}

get_port() then walks bucket 0 again and hits BUG_ON(!pn->sobject) in
pn_find_sock_by_sa(). The code before 5b0c911bcdbd takes exactly the same
path.

The search loop and the BUG_ON() go back to ba113a94b750 ("Phonet: common
socket glue"). The configurable pmin/pmax in pn_sock_get_port() and the
local_port_range_min of {0, 0} come from 87ab4e20b445 ("Phonet: proc
interface for port range"). Both are from 2008.

Should this be the following instead?

Fixes: 87ab4e20b445 ("Phonet: proc interface for port range")

The current tag suggests only kernels with 5b0c911bcdbd are affected. That
matters for stable routing.

> diff --git a/net/phonet/socket.c b/net/phonet/socket.c
> index ad12b746d4fca..eaa7d6a228f25 100644
> --- a/net/phonet/socket.c
> +++ b/net/phonet/socket.c
> @@ -490,6 +490,8 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
>  			port_cur++;
>  			if (port_cur < pmin || port_cur > pmax)
>  				port_cur = pmin;
> +			if (!port_cur)
> +				continue;

[Severity: Low]

This isn't a bug, but the sysctl and the allocator now disagree about
port 0. net/phonet/sysctl.c still allows 0 as the lower bound:

static int local_port_range_min[2] = {0, 0};

proc_local_port_range() passes that as .extra1 to proc_dointvec_minmax().
Its only other check is range[1] < range[0], so writing "0 0" still
succeeds.

After this change, that range has no usable ports. The loop runs once,
skips 0, and pn_sock_get_port() returns -EADDRINUSE. sendmsg, connect and
listen on unbound sockets then fail through pn_socket_autobind(), with
nothing pointing at the configuration. A range of "0 N" quietly behaves
like "1 N".

The commit message says 0 "must never be handed out". Would it make sense
to raise local_port_range_min to {1, 1}, so the write is rejected, and keep
this skip as a backstop? That would make writes of "0 N" return -EINVAL,
so it may be a call for the maintainers.

>  
>  			pn_sockaddr_set_port(&try_sa, port_cur);
>  			tmpsk = pn_find_sock_by_sa(net, &try_sa);

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119122127.1708071-1-amisiurov%40cloudlinux.com
Technical Details
Message-ID: <179543740229.3135.7763014717205061989@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369340-linux-kernel-netdev=dewy.ru
References: <20261119122127.1708071-1-amisiurov@cloudlinux.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369340-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] phonet: do not autobind a socket to port 0
Date: Mon, 23 Nov 2026 12:36:42 +0000
Organization: Usenet Network
Message-ID: <179543740229.3135.7763014717205061989@kernel.org>
References: <20261119122127.1708071-1-amisiurov@cloudlinux.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="3875180"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:HUw5JjQWyQXwqIBCxAMnHXaL3Gw= sha256:ApJ0ZjT2xSFdtzWG8dgVCxnzL/hTiaScEy4eqV3ypBc= sha1:EKbVuOC9WFZliqmk9lcbz3Fmrxw= sha256:E0F3skzsFTD5Jt5PzeakJdlumf/dCr6C7gWWkkpIWgI=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 9DFF0125DB0; Mon, 23 Nov 2026 15:37:33 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6EGl7Pr0_7bt; Mon, 23 Nov 2026 15:37:29 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-369340-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 5A605125DAA; Mon, 23 Nov 2026 15:37:21 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 93DEB2E526; Mon, 23 Nov 2026 12:36:55 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795437404; b=jf0S94E5K7DdlCWpYl4VZgCZpfh77e69NCa0sk1OwwDsNbskBT2p3sh1xtzs972oq2I6 GB3qtJXWGEgFwJO2IgFSlJVskYBBJ97prpwKkZTodbMjT3Uw/pVV7c932G8dAi92pzsf3 vxEp2gU9TPWPQBdTqNTmsfeEGabXxeUxVYgwbPYKHwJahBI+ZJff+3xo7nUCKhXOoKkCY gfDA23N6q/qd5NgjG80MjfbaUwOWxeXeexVY7Xd3KRsSgecCrMd7LmizOrpvqKlYcdcbn 3J4WIPe//QKG7IsaESKfHqTMRBSR2Qzig5wcDEe3B9ZxMTKlDpz2ScfAlOew1B0Bpng==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795437404; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=RcfCnrZOkRa2FxDbd/xz35KCsZvIVfnVJFvLRnPvNAs=; b=tuCC0Ied2asXh6aBYydyVVceqiL4/IMetA8d/MIPMr38h6f3UqBtndkV94p35Jsslw3n zbpPltcSRt2DhVLVNv3YafPbfqm+lxSD+IC+GvC85N6jXbXTGxoRgNU2gIlg5vL/z2Rbc Yf4IN2Wla4hkyvFk+TvauderniOdMAKazZKQhdL9dsWFzzqC8wKm+e/Eq4D+TGG7j85fU kKBiu+sODIbzl72fRq67Tqal728yYNpar/FPISvw79U1V3moL/8d1pmBx0JAM4Rsx+P36 nOZoCHc3d9y0jEyee75GbrzaNz2h2uN7tyf7AVTGW2mVPkB5GNCSW7vc97bP0jgQA2Q==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=A0BPR2u+; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D266606A33C; Mon, 23 Nov 2026 12:36:44 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=A0BPR2u+
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795437403; b=xkrgqB4CEweaK3OfPotSgEXClQC/cdiGhpSXQwoWTlysiq6zkNuaGUzw0Nnk5RXl6f4O eUx3xyc4wKuYV4e8QZEy87Zegk/k7yvtUOoEZb/vnWkUQn0lT/Kicn1ZIQqKp1POiESTs qQsh3SSye3b4BHo8NjH5/WiZ0fIPb9HIe0JVBNsidtskR4EjY6e9kbDRcafjib0mforhU O6tey/cUaT/keQk4Qk6kl9kph0xf8WpJ++iHQmMQyNYm7VpVPG8i6lWvBGlyTlD6dR4ZG jdutvF42Cd9b7v/lYwkJmk39tyBuRbhMcM4aliDlsyZWag/eB5l9xQkcoEzF0t4Sc7Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795437403; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=RcfCnrZOkRa2FxDbd/xz35KCsZvIVfnVJFvLRnPvNAs=; b=0ARIINaB7Wifh/Hsbb4LA2DXvyJlAywpzRB42azHj4Y6fD7Gb8FYJApWx3kgzCXvpB+y B47nHYDgnwn1CEDkpOlLDsZhYMY8/0VHo+AzIEim/4Y41NyJrZZQ18sGijszjkTW2lc+W sdDqgNHQRm7I8O0snw+ZuEesqrdWF/R5pev32mDkL3B5KjBHM/3Ks0K8BsdUmQ+gReOzN FKsJv9GET2aTbxsB7OSIRJztAxz/I5MuNK/oRYu4EfCq82ka7iefuNEn9ZJe/PyzrHJD+ aS6WpJ29VHfXk+BJHf6CHImkNetb6cBJvQXnIhRtd+pQQuPU7WP/mjNwQ5jaS1W8TbA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=A0BPR2u+; arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EA66606A32C; Mon, 23 Nov 2026 12:36:43 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B435C1F000D3; Mon, 23 Nov 2026 12:36:42 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795437403; bh=RcfCnrZOkRa2FxDbd/xz35KCsZvIVfnVJFvLRnPvNAs=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=A0BPR2u+dDWQ54Ewu6NpAaXhhhC13gRsvUJvNNvLtY07mLj+zxKE8v4WoiFSYuPWM Qya2srnj82fluEsenjpnv17VJmne35JAefie7mjDqCUAxvGmmPGA37yWrwwevx23aV +9wgldEMW7wkgxcgqlbJlFpA7vhpOw4Tq0lCAwdyHiUcr86wlE5AdurPtGvoPLwewM Ujnmxwuft/58Rfq/zncCO/9u0AR1hHqDCOH0/SL5L1M/z9Ai/SVvu8/etkEZic5HgI 8X+WEp64S3xgILiB3OfRwhi984pqBX5xBMj+STXqHQUxp28Qd+6oaKZgyZ0kd1BghN 6/0mys/xebscw==
X-Cc: courmisch@gmail.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, zhangdandan@uniontech.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
X-In-Reply-To: <20261119122127.1708071-1-amisiurov@cloudlinux.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list