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=1796382097; b=3NNI17BNpBeG/0NtaLhFpqy3bZ3GiG3RqRWeh/3qlYlt/mVJUqNlfH+CD+t2DyiTG6qS wCgafs7nDqwGW1fTwj7SzutpfHVfKpH/DQss1b4nhL39IISqBuXXept5i1EHit5+dzJca tGNReWqAJDW6Vh/Lhikl1Jdg71+eFEqPGbtakgN626lihnNpYeKEttw/fxXCdHNx/3W12 RebuFprZgOTXCb++mnS/k9rkDNo7WO3IHP5j7/RHnhQVDhkkUbNg5rpnJiuuKq5GUrWd5 PB9ls+BToxfZCyRKA/zJFAYqctdh8gqPZWGPAOdP66ia/LXAGN0XtgTwXZLAdDHf0xQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382097; 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=iQyhT+v13f0ZLFHcqwQwN0hIfiYdT9jJBoVpdFBAYR0=; b=aOSKgzY2cpTwpTT08rNniqWNXVVA7iiv6+6LCtOHycgjqMbxpylf252h3WfMwajrE0E4 gYMXk6nQgS0SHCYrrujuQyKiTPLednivV8C6Zacaf3zt+W9STYgcI6UWYA4IHlgRlnjr6 N3R3nXkGYvYUQ4ilYPtcZWAXnAaoKbseSaZzU7lqsO4qm7fx3YLdoDZVYMZ8FD0ujpuex saQOdgkwaR26ggvtYAQ+9FkuyBJPqu2GrP8MFCKaljCNZIIb3D7ExkKRqzM2ye6NYu2tI tRz4XWSniGaymBAJSRyUMeZsAKrmSxhmJA3g4LT3zXmQ1LWnB6Mku8Wn6+7WoSK2dfg== 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=qZ5UM62t; 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 B1B22606A322; Fri, 4 Dec 2026 11:01:37 +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=qZ5UM62t Received: by smtp.kernel.org (Postfix) with ESMTPSA id 246421F000C2; Fri, 4 Dec 2026 11:01:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382097; bh=iQyhT+v13f0ZLFHcqwQwN0hIfiYdT9jJBoVpdFBAYR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qZ5UM62tppfmii45zGsxmH2odrTkT7t0L3kYZBRzynqWvajkkmRL1cU5mf2Jl35yE mz5LqIs5WhkHbGUelRcMgYloqSVh/N87DBQUQyPXK0nj9kApc9TFVi1jufIBql2ZG1 QaS8sSq6nMqEmXxZfvgFl9AeTiJaPEpo2f+Ke6FE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.18 306/703] bpf: Fix NULL dereference in XDP redirect from async callbacks Date: Fri, 4 Dec 2026 19:03:25 +0900 Message-ID: <20261204100635.915267229@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: Alexei Starovoitov [ Upstream commit f28ed533106bc01aedba6ba47c0e1a1098c92092 ] bpf_redirect() and bpf_redirect_map() do not take the context, so the timer callback of an XDP program can call them. There is no current->bpf_net_context then: KASAN: null-ptr-deref in range [0x0000000000000038-0x000000000000003f] RIP: 0010:bpf_xdp_redirect+0x5b/0x170 Return XDP_ABORTED, like the tc helpers return TC_ACT_SHOT. It is one more test and branch on a value that is loaded anyway. Fixes: 401cb7dae813 ("net: Reference bpf_redirect_info via task_struct on PREEMPT_RT.") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261125032938.670542-17-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- include/linux/filter.h | 5 +++-- net/core/filter.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/linux/filter.h b/include/linux/filter.h index a11c92e104965..59a029db56059 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -1784,13 +1784,14 @@ static __always_inline long __bpf_xdp_redirect_map(struct bpf_map *map, u64 inde u64 flags, const u64 flag_mask, void *lookup_elem(struct bpf_map *map, u32 key)) { - struct bpf_redirect_info *ri = bpf_net_ctx_get_ri(); const u64 action_mask = XDP_ABORTED | XDP_DROP | XDP_PASS | XDP_TX; + struct bpf_redirect_info *ri; /* Lower bits of the flags are used as return code on lookup failure */ - if (unlikely(flags & ~(action_mask | flag_mask))) + if (unlikely(!bpf_net_ctx_get() || flags & ~(action_mask | flag_mask))) return XDP_ABORTED; + ri = bpf_net_ctx_get_ri(); ri->tgt_value = lookup_elem(map, index); if (unlikely(!ri->tgt_value) && !(flags & BPF_F_BROADCAST)) { /* If the lookup fails we want to clear out the state in the diff --git a/net/core/filter.c b/net/core/filter.c index ec8ce9faca0c5..b06d7c2515651 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4741,11 +4741,12 @@ int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb, BPF_CALL_2(bpf_xdp_redirect, u32, ifindex, u64, flags) { - struct bpf_redirect_info *ri = bpf_net_ctx_get_ri(); + struct bpf_redirect_info *ri; - if (unlikely(flags)) + if (unlikely(!bpf_net_ctx_get() || flags)) return XDP_ABORTED; + ri = bpf_net_ctx_get_ri(); /* NB! Map type UNSPEC and map_id == INT_MAX (never generated * by map_idr) is used for ifindex based XDP redirect. */ -- 2.53.0