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=1796380335; b=ZZD4lD+2rjZyRET7WezfdQa6vxGTPIjoS2E5eV4PLs/sAlaLFWYMiHfvWpzUlpW3DFyy +TIk3jnabkzz+VInols+e3L3kYWMncrEkM+zJBWp0iwEB6KW0p8knXjLA3bBhEiQg8uQP GJAF9nj/izXn/pf82xgX1HBVHfd1pB+YCVbjjlcogf/uR+ni37CaQtl4SvAa+dh23oHCS gcYhePL0jppmiAS/eM6sfUOY4och7CVgxqS4SeM6PZDRrQMYYQPCK1B28K/aK0EtfDOn5 3mVG45MYOxj9+k2RX9d0kASFWoOX9TgUjhd2E3nzaCtt+cM8Go3aC68SLBaCVj7TREw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380335; 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=kfJ5a5kQASXvHZXcH1Q8JXx7z+J/P5znt/0RUYh8yFY=; b=g57itVZebWvs57dNrM3WLd5v3sbhu6tb7F/fP6iJfqS9mX2jqpA/+jc27pK7xPHc3id4 p1kvTlOcdNaXKA/LHEdq8u40ee6P5cOG2Zd/TEIXC41tFlGnO4tLsg5vdUgpeunIg+DRj Ak5OMr/kA3k3rlcoigkDsVBZj/DqrbF+gCpdtq/Zx3br+mVO1xJOkkP2zSxr3yyK25SoF A72kOmDghabNE9Y7IpZIjaKMMKJWakgJtUUvQIJTbzTcMw7h3+3fzqPQ0Fy/ZBRURzK7X 3vwQprnQivbFfYeONau/shV+2P1f2tpE3VqMNTTsaYDHFNw1I/gGxVuoNc02Ey+u88g== 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=CUIkvT9u; 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 7AB25606A332; Fri, 4 Dec 2026 10:32:15 +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=CUIkvT9u Received: by smtp.kernel.org (Postfix) with ESMTPSA id B93951F000CE; Fri, 4 Dec 2026 10:32:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380335; bh=kfJ5a5kQASXvHZXcH1Q8JXx7z+J/P5znt/0RUYh8yFY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CUIkvT9u51VXsjJea3sAQrp9c/DDPdUJ1ijokDBkpAZkSSw5OMDmHGjwXSXn3IVnr 4eMZSKVdS5A7P0a2Qbzuar+TbAx1saQqvr3rJptMxzEHR/gdqYG5ymGho3uKohiEB7 TDBcfZA8eKyAh/gedeeEktIE728cSY6GzpEEDRik= 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 7.3 230/742] net: sock_reuseport: Check program type on the migration path Date: Fri, 4 Dec 2026 19:01:34 +0900 Message-ID: <20261204100641.182930744@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 b9e5648fa4c51..e039e35f39a90 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