BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Borkmann" <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net v2 2/3] net/sched: Handle TC_ACT_REDIRECT from qdisc filter chains
Date: Tue, 07 Jul 2026 18:56:21 +0000	[thread overview]
Message-ID: <20260707185621.EE25C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260706185609.330006-3-daniel@iogearbox.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Uninitialized kernel stack memory in `struct bpf_net_context` can be leaked via eBPF program redirect.
--

commit 2f1907a4bebd712981a70b8c62353113ce365c7b
Author: Jamal Hadi Salim <jhs@mojatatu.com>

net/sched: Handle TC_ACT_REDIRECT from qdisc filter chains

When a TC filter attached to a qdisc filter chain returns TC_ACT_REDIRECT,
the redirect was silently lost. This patch adds a tcf_classify_qdisc()
wrapper to convert TC_ACT_REDIRECT to TC_ACT_SHOT, ensuring the packet is
dropped rather than silently passed through.

> diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h
> index 3bd08d7f39c18..5f5cb36439fe2 100644
> --- a/include/net/pkt_cls.h
> +++ b/include/net/pkt_cls.h

[ ... ]

> @@ -156,8 +156,20 @@ static inline int tcf_classify(struct sk_buff *skb,
>  {
>  	return TC_ACT_UNSPEC;
>  }
> -
> -#endif
> +static inline int tcf_classify_qdisc(struct sk_buff *skb,
> +				     const struct tcf_proto *tp,
> +				     struct tcf_result *res, bool compat_mode)
> +{
> +	int ret = tcf_classify(skb, NULL, tp, res, compat_mode);
> +
> +	/* TC_ACT_REDIRECT from qdisc filter chains is not supported.
> +	 * Use BPF via tcx or mirred redirect instead.
> +	 */
> +	if (unlikely(ret == TC_ACT_REDIRECT))

[Severity: High]
This is a pre-existing issue, but since this patch explicitly discusses
handling TC_ACT_REDIRECT verdicts, does the current clsact fast path leak
uninitialized kernel stack memory?

If a user attaches a TC BPF program that simply returns TC_ACT_REDIRECT
without calling the bpf_redirect() helper, it appears we use uninitialized
stack data.

In net/core/dev.c:sch_handle_ingress(), the bpf_net_context is allocated on
the stack without initialization:

    struct bpf_net_context __bpf_net_ctx, *bpf_net_ctx;
    ...
    bpf_net_ctx = bpf_net_ctx_set(&__bpf_net_ctx);

When include/linux/filter.h:bpf_net_ctx_set() is called, it only zeroes
kern_flags:

    bpf_net_ctx->ri.kern_flags = 0;

This leaves the rest of the redirect info (ri.tgt_index, ri.flags, and
ri.nh) uninitialized. 

Later, when net/core/filter.c:skb_do_redirect() is called to process the
TC_ACT_REDIRECT verdict:

    struct bpf_redirect_info *ri = bpf_net_ctx_get_ri();
    ...
    u32 flags = ri->flags;
    dev = dev_get_by_index_rcu(net, ri->tgt_index);

It reads this uninitialized stack memory. If the flags happen to have
BPF_F_NEIGH set, the uninitialized ri->nh structure is used to generate an
ARP/NDP request, potentially leaking kernel stack memory on the network.

Should bpf_net_ctx_set() or sch_handle_ingress() zero out the entire
__bpf_net_ctx structure to prevent this leak?

> +		ret = TC_ACT_SHOT;
> +	return ret;
> +}
>  
>  static inline unsigned long
>  __cls_set_class(unsigned long *clp, unsigned long cl)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260706185609.330006-1-daniel@iogearbox.net?part=2

  reply	other threads:[~2026-07-07 18:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 18:56 [PATCH net v2 0/3] Fix broken TC_ACT_REDIRECT from qdiscs Daniel Borkmann
2026-07-06 18:56 ` [PATCH net v2 1/3] bpf: Reject redirect helpers without a bpf_net_context Daniel Borkmann
2026-07-06 18:56 ` [PATCH net v2 2/3] net/sched: Handle TC_ACT_REDIRECT from qdisc filter chains Daniel Borkmann
2026-07-07 18:56   ` sashiko-bot [this message]
2026-07-06 18:56 ` [PATCH net v2 3/3] selftests/bpf: Add test for redirect from qdisc qevent block Daniel Borkmann

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=20260707185621.EE25C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --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