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=1796383612; b=LrxYekvwU8bSp5hepZG/X8Jd2PpvnxGToLTmQ44m6zvbEL5eGDIaCBiuFvmLFdTCk3BU Jpa4+Y5wW7mdlVIuGFgi2SEYnOqod0n5cB8qvrZWWU/3DSZ+oLCE2C95XpG+VfGib5pqS CSAH5UXpDX7RLTlqB/YrJjr93QKRANPQibKf3ZCMsGAej5FFKLpBjVXKqygw2PaqdcmJb ueggdXbUW1EKn4sAGkypNDMnL6LSxuSjwTwxwOTvPseh1LSSCaHxNM17BR6FS/pIun0ae EEA+m3U7s+vRRfipEUlZkaKZ5lSsci1Up49M76BOUOn5O0h5akaiXt0oBNwljz/Hw/g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383612; 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=DQLIGIAyFo2GsgtsU8ffkX6WK6AeccAzpUTob03iktA=; b=OcQpgZA7GmGu0RUtB8e+LdaRPvzhFhK+9HDAUwlm4iqTFomocSvW/StWWAWfy1ty2DcS 6xrKagFz1u8l2PyP98+g3Iw2t3FP8W2uu+F+fvXvpPNqcHW2ZXW8+S8qkkEGDCeipdnZ/ 4AT6PSzSSpVZeYgHaBAPwRIORYF6F50ZQ7HjgTwMpG7GDTL4JNUp4KR43GizNQCMVGu25 gX442B8pYT4pYXmWKhYh15bkPvPJIsuvPyelMcYmxy7Id/Mie6BMyFXQq97Nhcuyp4QW1 vBtuDOfh/u8WGlXwqwkoS9p2dXyY9SOBnYbrHFRxqt+GIaYL3ewpWcEnzxM2OX2SzZA== 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=QFZNSX9Q; 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 823FA606A32D; Fri, 4 Dec 2026 11:26:52 +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=QFZNSX9Q Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF8F71F000CE; Fri, 4 Dec 2026 11:26:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383612; bh=DQLIGIAyFo2GsgtsU8ffkX6WK6AeccAzpUTob03iktA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QFZNSX9Q4BmCBCpJ5r0OllhJHNlXkxiLYSFoBuEJx8WGTAluulkT/zWvOAkXyLpYN M00FUPBX8tkcs6gDBn1ArWEDiAOu/ENqBEuv6q98bR5ExbEg1MXlqoE+pigKe591ve uapapf6J+I7OmYZYjj1m+EmGiFdSOnAnFeJ4JloM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.12 297/555] bpf: Fix NULL dereference in XDP redirect from async callbacks Date: Fri, 4 Dec 2026 19:05:40 +0900 Message-ID: <20261204100620.499844613@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: 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.12-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 b88a213bcbbe1..8aeb073792c39 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -1740,13 +1740,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 22ea8540f3114..3d75bd7137477 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4742,11 +4742,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