Fix broken TC_ACT_REDIRECT
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest3 patches 5 repliesIn review
- v13 patches 5 repliesSuperseded
Changes in v2 from the cover letter
1)Patch 1: Address pre-existing issue to cover asynchronous qdisc enqueue
operations in particular if bpf_redirect() is invoked from an attached
ebpf program (the helper invokes bpf_net_ctx_get_ri())
https://sashiko.dev/#/patchset/20260620130749.226642-1-jhs%40mojatatu.com
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | net: Extend bpf_net_context lifetime to cover qdisc enqueuenet/ | +23 | 5 replies | |
| 2/3 | net/sched: Handle TC_ACT_REDIRECT from qdisc filter chainsinclude/ net/ net/ +12 more | +27 | 0 replies | |
| 3/3 | selftests/tc-testing: Verify bpf redirect on RED block with preceding clsact (egress) classifiertools/ tools/ tools/ | +37 | 0 replies |
Reviews trailers per patch
1 of 3 patches has a Reviewed-by or Acked-by.
| Patch | Victor Nogueira | Jamal Hadi Salim |
|---|---|---|
| 1/3 | T-b | |
| 2/3 | T-b | |
| 3/3 | A-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH net 0/3 v2] Fix broken TC_ACT_REDIRECT
When sashiko-gemini[1] reviewed commit a8a02897f2b4 ("net/sched: cls_api: Handle TC_ACT_CONSUMED in tcf_qevent_handle") it
correctly pointed out the following:
"
This is a pre-existing issue, but does executing a redirect via a qevent filter cause a NULL pointer dereference?
When tcf_qevent_handle() processes a TC_ACT_REDIRECT, it calls skb_do_redirect(). This eventually calls bpf_net_ctx_get_ri() which dereferences the task bpf_net_context:
include/linux/filter.h:bpf_net_ctx_get_ri() {
...
struct bpf_net_context *bpf_net_ctx = bpf_net_ctx_get();
if (!(bpf_net_ctx->ri.kern_flags & BPF_RI_F_RI_INIT)) {
...
}Since qevents are evaluated during enqueue, which runs within __dev_queue_xmit() after sch_handle_egress() has already executed and cleared the bpf_net_context pointer, will this dereference a NULL pointer? "
That issue is fixed in patch 1. See the commit log for details.
Upon further investigation it turns out that TC_ACT_REDIRECT being returned from the egress qdiscs never actually worked. When an action returns that code we would silently loose it and the packet will never be redirected. After all those years, if nobody complained, my gut feel is it was never used by anyone with serious need for it.
Patch 2 fixes it by 1) putting a warning out when someone does and 2) asking the core to drop the packet. At least this would help whoever is misconfiguring to diagnose the issue much faster.
I had initially attempted to "fix" this and make it work, but unfortunately it's a bit ugly so i left i didnt think it was worth fixing
Apologies for the shotgun Cc - its what get_maintainer.pl told me to use.
[1] https://sashiko.dev/#/patchset/20260620130749.226642-1-jhs%40mojatatu.com
---
Changes since v1 (address 3 sashiko comments):
1)Patch 1: Address pre-existing issue to cover asynchronous qdisc enqueue
operations in particular if bpf_redirect() is invoked from an attached
ebpf program (the helper invokes bpf_net_ctx_get_ri())
https://sashiko.dev/#/patchset/20260620130749.226642-1-jhs%40mojatatu.com
2)Patch 2: Explain in the commit message that it is actually design intent to
remove TC_ACT_REDIRECT from tcf_qevent_handle().
https://sashiko.dev/#/patchset/[email protected]?part=2
3) Patch 3: be explicit with $EBPFDIR
https://sashiko.dev/#/patchset/[email protected]?part=3
--- net/core/dev.c | 31 +++++++++++++++---- include/net/pkt_cls.h | 13 +++++++ net/sched/cls_api.c | 6 +--- net/sched/sch_cake.c | 2 +- net/sched/sch_drr.c | 2 +- net/sched/sch_dualpi2.c | 2 +- net/sched/sch_ets.c | 2 +- net/sched/sch_fq_codel.c | 2 +- net/sched/sch_fq_pie.c | 2 +- net/sched/sch_hfsc.c | 2 +- net/sched/sch_htb.c | 2 +- net/sched/sch_multiq.c | 2 +- net/sched/sch_prio.c | 2 +- net/sched/sch_qfq.c | 2 +- net/sched/sch_sfb.c | 2 +- net/sched/sch_sfq.c | 2 +- tools/testing/selftests/tc-testing/action-ebpf | Bin 856 -> 9072 bytes tools/testing/selftests/tc-testing/action.c | 5 +++ .../tc-testing/tc-tests/infra/qdiscs.json | 32 ++++++++++++++ 19 files changed, 87 insertions(+), 26 deletions(-)