From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796386408; b=xM09wohhLFoIDwrksSagS/WKp+ESWY4HO0x8DZRxOPHFZKR4ykpuXwhsuWJmTel0QW2l MViBu59VdJPKu98TUofEYTKpuv3y6AsE9p2aDHHRsfCAIo7izYlbJh7vsMuP+m9OKyRO0 f+N7hPOXTuhtkJ6TxqeKxVyiiCJvPQqtgtL/WRYWczZNY94qzUPLND7q/elv7ogYGhW+z HWT9hgD+XLBc57TmpkPneiKiNlotDGiV6cBKnOVJq3/nNV4X5rN9P+NOXpc2pRtA0xJiC q47iOp9hseX531LkpgOfB3MQh5rpz/XwaGrcU+WCLKZozYafnXblYOs5ucFXTXoxWvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386408; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=xinpzZEQsHE7oo91shRe8jHdk0l/USdwd4GctnJ3jCs=; b=Vq9HwKl+bdzOEbYutMPTDdjBRM9XLOSrl9e7+96Lb8YU9vABGojkMSsTSJKwtwnhhxzA ZQQReS5xf59tzBJ8XJBM5siuqz9cV0257vP7FRxBCZUzx/mkw76ck3CnPv4jO75RxoNGT xNe8sH429COCAzBSXiYz+TSw9SZDvkp+cyQSIc7RNgKLxMW9h3BKqtWRHV7d7Bm+fPmVK 5Wwdv01cxOFfH6wHR/ClM0eueG/04d6mxDnqjboDireuHxijQCYfIjt2Gw6DHMrLBWbzg CRbU1JM37SO1fsaFKRM3BY2IeYgHtpp8QGEyQ75DRo0PmTw648oKc5CgHkE0A6NLBqQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=g7HMoPof; arc=none smtp.remote-ip=100.103.45.18 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 04223606A32D; Fri, 4 Dec 2026 12:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=g7HMoPof Received: by smtp.kernel.org (Postfix) with ESMTPSA id 725251F00897; Fri, 4 Dec 2026 12:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386407; bh=xinpzZEQsHE7oo91shRe8jHdk0l/USdwd4GctnJ3jCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=g7HMoPofgQ2e4610L5Xl2vx8J2Wt32dw0GgXTH9FzDZZCv69Tkf2Rmym7qHtC4GYh F4pFkq1aOghhxonQhj0L5MLhIZfrU5d2HRV8CyzYBgt5MQarSqXHdjcoWOD0M4vtxd bV7mf+Xh7cSk6j9SXr7VH3jTzS4D2zsV7uJBpj8E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shihuang Liu , Alexei Starovoitov , Kuniyuki Iwashima , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 0950/1167] net: sock_reuseport: Check program type on the migration path Date: Fri, 4 Dec 2026 19:06:17 +0900 Message-ID: <20261204100726.934061891@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shihuang Liu [ Upstream commit cbaaeff649b7aa09170cb31db001e5468c2726c0 ] A BPF_PROG_TYPE_SOCKET_FILTER program can be loaded with expected_attach_type set to BPF_SK_REUSEPORT_SELECT_OR_MIGRATE and attached to a SO_REUSEPORT TCP group. Closing a listener that still has queued children then runs it with a struct sk_reuseport_kern context even though it was verified against struct sk_buff, which KASAN reports as a stack-out-of-bounds in ___bpf_prog_run(). Reaching this without CAP_BPF requires kernel.unprivileged_bpf_disabled=0; with CONFIG_BPF_UNPRIV_DEFAULT_OFF=y, the Kconfig default, the sysctl starts at 2. reuseport_migrate_sock() decides from prog->expected_attach_type alone, a field user space sets that does not identify the program type. Require BPF_PROG_TYPE_SK_REUSEPORT there and in reuseport_stop_listen_sock(); socket filters still work as selectors, so the selection path is unchanged. Fixes: d5e4ddaeb6ab ("bpf: Support socket migration by eBPF.") Signed-off-by: Shihuang Liu Signed-off-by: Alexei Starovoitov Reviewed-by: Kuniyuki Iwashima Acked-by: Jakub Kicinski Link: https://patch.msgid.link/20261118153541.172499-1-shlomojune6@gmail.com Signed-off-by: Sasha Levin --- net/core/sock_reuseport.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c index e7685956b09d7..fe6cec288fb11 100644 --- a/net/core/sock_reuseport.c +++ b/net/core/sock_reuseport.c @@ -461,6 +461,18 @@ void reuseport_detach_sock(struct sock *sk) } EXPORT_SYMBOL(reuseport_detach_sock); +/* + * Only a BPF_PROG_TYPE_SK_REUSEPORT program is verified against + * struct sk_reuseport_kern, which is the context bpf_run_sk_reuseport() + * passes to it. expected_attach_type is set by user space and does not + * identify the program type. + */ +static bool reuseport_is_migration_prog(const struct bpf_prog *prog) +{ + return prog && prog->type == BPF_PROG_TYPE_SK_REUSEPORT && + prog->expected_attach_type == BPF_SK_REUSEPORT_SELECT_OR_MIGRATE; +} + void reuseport_stop_listen_sock(struct sock *sk) { if (sk->sk_protocol == IPPROTO_TCP) { @@ -475,7 +487,7 @@ void reuseport_stop_listen_sock(struct sock *sk) lockdep_is_held(&reuseport_lock)); if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_migrate_req) || - (prog && prog->expected_attach_type == BPF_SK_REUSEPORT_SELECT_OR_MIGRATE)) { + reuseport_is_migration_prog(prog)) { /* Migration capable, move sk from the listening section * to the closed section. */ @@ -645,7 +657,7 @@ struct sock *reuseport_migrate_sock(struct sock *sk, hash = migrating_sk->sk_hash; prog = rcu_dereference(reuse->prog); - if (!prog || prog->expected_attach_type != BPF_SK_REUSEPORT_SELECT_OR_MIGRATE) { + if (!reuseport_is_migration_prog(prog)) { if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_migrate_req)) goto select_by_hash; goto failure; -- 2.53.0