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=1796382006; b=dkNuNsySN5aX+zYzkZangPMbM5gJ/raVARe8K7I3uWgD72PgmckTEAdvHZfBsjliKLAn 2YROZ2YQ7TEAWACKpEi7E4aREf12gjmtRTWrjul5bbyuVEPvnZK6AbRpa1Rel6TGDeW1d sf9BZj1HTzKDzPDliPug++Z1PWgkHpyavouGCkPAx41vxocqZaRR2+ErTCAR+osJUpw3A CGIkezKv2q5LTqqC9dcfITwN5N+n2MuWWX4d9XXRQ9LDCjeSKeoBUeyVGcriz+cN5lt47 7IAApCVkTR21HK5Pa7CDG3rWMgBtgFTCYK0qltJRv2Dk5SbHTvTUheY8NjI7olMYc4A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382006; 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=5ccLULdAVAkwNi0P4+AoGhQoRM3u1W5GC47vpVw+jK4=; b=GpAtMcW1OmM+7o1bsy/k6TPAgshjqIPTr60WrrmQ+uNMGGHF6cwZTi7ZkeQ4G+J9WsYt cfV6SVae0aCMdrSEsS5pKuFJPx7oFbFGcRFeRT9h7mv45nNtRRLiT61AIPO25/i1r6QiA o8HMk5WRXSK7tOXXpcr0VWunooE3SvsB7/DJzLzuaJTgcqbD+vhkTFfu3XcHnBZdOWOAq L0kiE8GCOXUyLUaBFrHHUifuAJ1YX7Clv6eKliJvECBQPn3CtYD0mZziuwQJ/KVkUC/cu Cn067Au/u4mGOJ1FKXp1JtNsK1oTfBbMLdtzx07BdBLX+cN3lpAjPHKfmpKWpzotOkQ== 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=AjBuSB4y; 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 0BEC4606A334; Fri, 4 Dec 2026 11:00:06 +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=AjBuSB4y Received: by smtp.kernel.org (Postfix) with ESMTPSA id 769C61F000CE; Fri, 4 Dec 2026 11:00:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382005; bh=5ccLULdAVAkwNi0P4+AoGhQoRM3u1W5GC47vpVw+jK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AjBuSB4yluvuArpOewfK257/iiwrk9aaIcbHge3JBPkaNOBsLhMJZFP4VMetdaVpR 7/HbiPaeTQS+NykV102hz+9plx7MfPaeoF7YnQO3C91sH6oeKGdwoN+fhcYTgIqrmZ NQ1quf2kao9qEuJLd/SBnlF3BuQGyQeCqEvcJQIo= 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.18 266/703] net: sock_reuseport: Check program type on the migration path Date: Fri, 4 Dec 2026 19:02:45 +0900 Message-ID: <20261204100634.862278475@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-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 eb8d24964e2f6..7174c61e2e59c 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