From: sashiko-bot@kernel.org
To: "Jamal Hadi Salim" <jhs@mojatatu.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net 1/3] net: Extend bpf_net_context lifetime to cover qdisc enqueue
Date: Sat, 27 Jun 2026 16:52:18 +0000 [thread overview]
Message-ID: <20260627165218.959371F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260626165156.169012-2-jhs@mojatatu.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch moves `bpf_net_context` initialization to `__dev_queue_xmit()`, but fails to handle asynchronous qdisc enqueue operations (e.g., via `netem`'s `dequeue` function), leaving a NULL pointer dereference unaddressed when qevents execute during `net_tx_action()`.
--
commit 804facd8bc23cc276a2c5ce958a8503b7b036912
Author: Jamal Hadi Salim <jhs@mojatatu.com>
net: Extend bpf_net_context lifetime to cover qdisc enqueue
This commit moves the bpf_net_context lifecycle management from
sch_handle_egress() to __dev_queue_xmit(). The intent is to cover the
qdisc enqueue phase so that a qevent filter returning TC_ACT_REDIRECT can
safely call skb_do_redirect() without triggering a NULL pointer dereference.
Closes: https://sashiko.dev/#/patchset/20260620130749.226642-1-jhs%40mojatatu.com
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 4b3d5cfdf6e00..8c214bfff8aa9 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
[ ... ]
> @@ -4795,6 +4791,9 @@ int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
> skb_update_prio(skb);
>
> tcx_set_ingress(skb, false);
> +#ifdef CONFIG_NET_XGRESS
> + bpf_net_ctx = bpf_net_ctx_set(&__bpf_net_ctx);
> +#endif
[Severity: High]
This is a pre-existing issue, but does this patch fully cover asynchronous
qdisc enqueue operations?
While this patch successfully covers synchronous enqueue via
__dev_queue_xmit(), the bpf_net_context might still be uninitialized during
asynchronous qdisc operations driven by the net_tx_action() softirq.
For example, if netem delays a packet, its dequeue function is called
asynchronously from net_tx_action() in net/core/dev.c, which runs
qdisc_run() without setting up a bpf_net_context. The netem_dequeue()
function then enqueues the packet to its child qdisc.
If that child qdisc evaluates a qevent and the attached BPF filter calls the
bpf_redirect() helper, the helper invokes bpf_net_ctx_get_ri() in
include/linux/filter.h:
struct bpf_net_context *bpf_net_ctx = bpf_net_ctx_get();
if (!(bpf_net_ctx->ri.kern_flags & BPF_RI_F_RI_INIT)) {
Since net_tx_action() did not initialize the context, current->bpf_net_context
is NULL, resulting in a kernel panic when accessing bpf_net_ctx->ri.
Although a later patch ("net/sched: Handle TC_ACT_REDIRECT from qdisc filter
chains") addresses the crash in skb_do_redirect(), does it prevent the crash
inside the bpf_redirect() helper itself during these asynchronous paths?
> #ifdef CONFIG_NET_EGRESS
> if (static_branch_unlikely(&egress_needed_key)) {
> if (nf_hook_egress_active()) {
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260626165156.169012-1-jhs@mojatatu.com?part=1
next prev parent reply other threads:[~2026-06-27 16:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 16:51 [PATCH net 0/3] Fix broken TC_ACT_REDIRECT Jamal Hadi Salim
2026-06-26 16:51 ` [PATCH net 1/3] net: Extend bpf_net_context lifetime to cover qdisc enqueue Jamal Hadi Salim
2026-06-27 16:52 ` sashiko-bot [this message]
2026-06-28 12:16 ` Jamal Hadi Salim
2026-06-29 10:29 ` Sebastian Andrzej Siewior
2026-06-29 10:47 ` Jamal Hadi Salim
2026-06-26 16:51 ` [PATCH net 2/3] net/sched: Handle TC_ACT_REDIRECT from qdisc filter chains Jamal Hadi Salim
2026-06-27 16:52 ` sashiko-bot
2026-06-28 12:28 ` Jamal Hadi Salim
2026-06-26 16:51 ` [PATCH net 3/3] selftests/tc-testing: Verify bpf redirect on RED block with preceding clsact (egress) classifier Jamal Hadi Salim
2026-06-27 16:52 ` sashiko-bot
2026-06-28 12:36 ` Jamal Hadi Salim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260627165218.959371F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jhs@mojatatu.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox