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=1796380452; b=g77m+zSJMn3DDYXbVEfchClCCyv8PyjfHyGz5TKw8NG6VxYriReun+Q2/qvstGnGodFD RjPa2YXDxnsaNhW/ajEtx+XjZu0pDY/Wxa1nMCgKZc1CueOpL6UPPX1Ir3i4SXyOgbOMw 4PE9D+20elN/7pBizunsJ6mauXI3LfJwX6bK2W2Xf+QeOeQXGUEy+Uo9BxmtPe0JhVJ0I ORtdy+F462ZVVE+Wd/nlvhogvJ02VQqXNF1CaDBI3ZqoDpnmHHeDo+I1Y4/cXSed3va3v H5OODrweOonK0CcuSu5AAQgeOFdHPWY65shSgDS1q2Wltz+eL8C93AE+OfYoPszgz9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380452; 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=zoRInPLdOgYoOJ7f6xGmujqToLj/gxCkn0DN0GKpgGM=; b=4xvng6osJFQmjzLY47OoxWQSengF2ECd4Gh2kkk3xaaOAGASYLDXQz/P5pXmaCUV55rQ 3Z1w6ZfSjF3D7T8fCWtf3SO2UYH+h5PqU/GWiivYC8vMT0pmfvPncm+z5jG8h+go/cWyp EhlWlGIqcccrT3swhB7/ErcGJOVBaNdeWPVZIsrff7QXn6Ac6JeV2uEJ2D8u9n/sK7bfd 8k96mHmIEh7BKHKTyojj43jIoenldmsFeMwkn3m2Cy8aYT5AHh4yV1v/FjxAzPswznBz8 zmwZ970+epS5CZWZAXIvlNEL+wFZdSVp1BYdZg8PsehMbekIrr0SSt02WTDZR+8WHUg== 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=jtNn6EnH; 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 32E1A606A69A; Fri, 4 Dec 2026 10:34:12 +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=jtNn6EnH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 713561F00931; Fri, 4 Dec 2026 10:34:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380451; bh=zoRInPLdOgYoOJ7f6xGmujqToLj/gxCkn0DN0GKpgGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jtNn6EnHNDEW6IM3KuJ+IIfgRcUr+9SN4tBGoiGVZ1Nl3gjcp/A2WPiPv/O8jotP3 viqKKTBGzvUB8Q8x9JSIy6IMtbL/4l3thALKDI6TDMYyu/SbJonQR0qGnYgLiOHGYZ vd3WsvLSaOFjpzLcaRG29eJuCYrA+ZgBAj9gZbCc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 280/742] bpf: Fix NULL dereference in XDP redirect from async callbacks Date: Fri, 4 Dec 2026 19:02:24 +0900 Message-ID: <20261204100642.487078019@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: 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 7.3-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 39decde7fc730..94bbdb948ab02 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -1863,13 +1863,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 30bbd0c20a044..53ca1457fd331 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4895,11 +4895,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