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=1796383553; b=2gf5K1AzFYaLdEZ4DV2WesG2NXSI2oAGqcCsqaLX2Jrq36NcZnSd7ELvCNE964m31hR+ jKYpH4dDfUWUXyzygga3S9DJ7Dv3qNrpkdopzkmzLpjh8cfJvSrjrNNTUuatPmFG2/q8e 4scZ1iCS6I+Z79BKFD9pohPDNOfG4/uKx1IJGV5rjmf6tLS+NOi0c8DU/3fe6IRsXYjGV QU1FgCGa4ZSx/ncf6AWSp+N+9Tqag5GplEEVj9TA/3u5jx0ZBM/rJ2Tv7tdjXrvs+08Wc 5vioT3W997BBohWnzKbQddr8bUePIjItLtPUPgUysxmdNKvCgwCZRyjib3PO2sjZ27g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383553; 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=6r7FRedplx7Z1SH+165uRVJmPMJvfearqYlNanWIJiY=; b=LLxRvrP0JAhewDf6oZbcWdIM+JtiP+wFq1TxMK/9tLAd1KuKNJAmX6PSITYmclMUfASG KmsoWq2Z7/JWTWFncz139lipK6aNfsAnHow4PTqfPhKijoI8BTe/PRY95YMQ/9XQ4TLaa +2klT4l/BHM9g54eOZsj6oa5AXffdT1ocUDkKB5qsO+jr83fIobIJ/Awp5kPCXQOro21J PVyaSz2fPXZuc8pVFhGpt5AprH2iNakH9JWQ2LDYETA6K3G03fU9u6PJrChnp32zi4sZh XjKNUyAplMj2OeCiTy+siAbUbCezCyXvy8y6hlky9BBbB+bup+VAKjx3VgVeByat17w== 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=icDLgYzw; 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 4718D606A322; Fri, 4 Dec 2026 11:25:53 +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=icDLgYzw Received: by smtp.kernel.org (Postfix) with ESMTPSA id B13AC1F000C2; Fri, 4 Dec 2026 11:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383553; bh=6r7FRedplx7Z1SH+165uRVJmPMJvfearqYlNanWIJiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=icDLgYzw3O6hoEZBXzAhDTJlo7+ZBSI0rijycS/cA/1XL0Vbq0Nc2IvVsoUGWPQI7 sNaWuJiIw7wyevgz7wNcXyExWjhAnNZ6vgn5I8WQSxxysfVD1FTUa6T/xI2woAl7Pr R8ZmRSbH97oXv5gCGMvY3DZL9MzAlbD0/VKKOCvI= 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.12 268/555] net: sock_reuseport: Check program type on the migration path Date: Fri, 4 Dec 2026 19:05:11 +0900 Message-ID: <20261204100619.297286976@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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