From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796107300; b=zRY4OAq67K+AOAPUx0AD+S/zmZzD6YNyDsbr6hRi8EIsVNOlOP5Fq7vm9IDu3xr+JdAh DypbusvFtVN/ShYouOgAZ3xKVCz4sP4ff0NlEKvbLND7R5n20pNCmk36r/L/khtHS2ZZR 9ynZAfHKGcmL/cZGTHcASPKE1H1Val3UU/CKKCs4qYsDsYS3t0BCUSKcBJZTuLIRA2BSV F0YIGd/gSffdsD2jofbNORy2Nvxk1tNyh6EK8nQa/bgGEmxtgAMp+7j0hFytHIRurQvmp HoicCb08zApM+PERUbKUOk3knicOiYRaK8/1KCwgo9gahkhfMDtAHIwy6MQGuOt2UmQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796107300; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=qnJRenLIGItsud48PxJZI+XLOkaYRtTxla+5dojCGiQ=; b=HIuSpaKJseLrtqV7X+e2AcKTeXktbXBenJDQaTnmSmoTnyttIuWc7CryZyRJ8rVvLgf4 4GikcOeyEgKQ3rlQLTBldRi0kA3m06sl6Y63W8KRhACQ6Z7WCuDmL3Su+jZbO6ic+cJ4+ l7q9ksYfuDiXJOcuIf+JDHsT1Uk8BXoTX57Hbrnk3lgFdB6NPJ8itRDe7g/pIhMxiES9U x9+Oh8hjIwpnzsnLc9yDWKHYJVo+1c0Z+qaEeuTgl3y3vAABVpEJJ0YJ6rVClfL19+ksc eO9BQU0g/WRxPVnXPddmxQnmSnGYCxX2V9eCGyT7ZbJwAQLgjBoY7QwIl9hMLHODWhg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=cloudlinux.com; spf=pass smtp.mailfrom=cloudlinux.com; dkim=pass header.d=cloudlinux.com header.i=@cloudlinux.com header.a=rsa-sha256 header.s=google header.b=FRDBW7w5; arc=none smtp.remote-ip=209.85.128.52 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FE2F606A332 for ; Tue, 1 Dec 2026 06:41:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4FE2F606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=cloudlinux.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudlinux.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudlinux.com header.i=@cloudlinux.com header.a=rsa-sha256 header.s=google header.b=FRDBW7w5 Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4a35ac4475dso80441195e9.2 for ; Mon, 30 Nov 2026 22:41:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudlinux.com; s=google; t=1796107297; x=1796712097; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=qnJRenLIGItsud48PxJZI+XLOkaYRtTxla+5dojCGiQ=; b=FRDBW7w5abal+x7WBDN0CucwOOpJjvB/M+r01f2rpAAIPGRp88k+OJro04jMndRJtV ODtSydKLRZcCLjyE8gEKewRHwe24idJqTOvGbYjFglowz0TIaIhgDzQEfnTcYATHgwWu Ne6YG7uGdWpJNNYWBm+1bSiJ0+olQqP4aLtbf+E7hCcBf+QvzzRPIC65AYVD5/x0Fs8X IJb9p1u5skdzgG7g+CIhEeLD/t+iRntbGIXNOdRIDyKn1Bq21lQdCh07v3J1h0L+/t/b 4APsCHmU/tnkTbrJOkrOv+8ajc+nF0MAFEkPYQXTPqu7ipnJGmgF6YqIs2639ROGS/Og RU6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796107297; x=1796712097; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=qnJRenLIGItsud48PxJZI+XLOkaYRtTxla+5dojCGiQ=; b=GMTTstj1fTq9S4ksHCZct8Iy5U0SQfXjh+nhiUguAGB88rTZiRR1MTRjtT2NoXVK9E GiDSuB/ijX3/izjBBPLFQmqXnC1N69FZqur95HcMJyl5P97ZVpl6ATcrUSWef7w9Yd5p owep+2i+8h3Dmz4DS+/aH3MwhHVW+2uyssSR2SRcRpF6J5zF0MQLvBQeWGsU1Xmn+9o4 rVtyxhiN9S2Xckm80pCcuf20fdH/LYXS18ICBcg9kvsKin+YlnnP4Mor9wztcBJp4mRf wYWA9tBjHRbJnvc6ZkrXLlVCaOV91pIr9XwjlHR7MYl+7uBIjKlLMo/KQ20ZJp17hnFn lU8Q== X-Forwarded-Encrypted: i=1; AL+hErEsOvCxMtQEhaC4ULxZwGXMPOvLccpZqT3n65o1TOC5NxLKx/nWo2QrvG8ZuavMadp7D2UFicTiDn38N5s=@vger.kernel.org X-Gm-Message-State: APuU4Z8Wn+1PEzW0cRscCFYWQfsZHlaKvF/M/q+TtCGo9Scfn1joRAGA V4PsTODQtmfu4F1eZDmMFNuW0A+eF8XSeBCcN2o/Ac+CRXyylt4JY9HrjjBVT4VCmv0= X-Gm-Gg: AZFdTZdVVnDqs5+7IMk3h0BLNg8b4UbcEXj4hZtcNvYWXod+rE4+D10qt9tTzkYcjFE YKOgApvt88rFHQ3xPMdOCufqHZGX9zw1lJ53rnKTMgP6jmkW6vNDV84ER6WCJDagj2WClZxO0LU s+vCrZD7oKsXPc6ZrBILmdd6yob6FJauSktWhGVf3PpV+K3Oi/zCFX6bJJa2Mab2nxrZi2YSYZ4 RE2HdOsEzkErcz+xMuT2l0iFpuFwqh5ErAe0ySJrF83SBMD8VLx8V3YaxgY20JUR5PTYWx3k/Dt bqqr7y5JYXfeB4sWZ+jTRASuKmbnDyU8wy9WQdmHGxfdFhZjezv7hIVsL9EQ1qGqMZ2clAA8WK6 UdcrQJKgiMhe5U2xI1KSdmDO5ab6WKTBGgU75ymOLut4R0hJK4+annGU5LbYvBua4NgVViXNppk c8XE36xxvbAejJB2vW3kkJX0fC7V9IcXbgF9EAKGyHyheJ8Bd+LTz6ttq+tn2qCfpSlUzkOPXhp tJul7pW++QzFcpbOmcfC8DofpNH3I4SiUMKEXBMdQhQ/IT4Ezl6okH0bYewBRzxayxIgYusMLOc BnAnvhfeyT/1cuMvN8y/VdYL X-Received: by 2002:a05:600c:83c3:b0:4a1:7e77:c382 with SMTP id 5b1f17b1804b1-4bb8880ad68mr707318705e9.5.1796107297659; Mon, 30 Nov 2026 22:41:37 -0800 (PST) Received: from dev1.kernelcare.com ([2a01:4f8:172:1c85::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884b8429sm1557455165e9.14.2026.11.30.22.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 22:41:37 -0800 (PST) From: Andrey Misiurov To: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andrey Misiurov , =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Subject: [PATCH net v2] phonet: do not autobind a socket to port 0 Date: Tue, 1 Dec 2026 07:40:39 +0100 Message-ID: <20261201064121.2113989-1-amisiurov@cloudlinux.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20261119122127.1708071-1-amisiurov@cloudlinux.com> References: <20261119122127.1708071-1-amisiurov@cloudlinux.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=y Content-Transfer-Encoding: 8bit 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 Signed-off-by: Andrey Misiurov --- 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);