linux/tools/testing/selftests/bpf/progs/test_tc_qevent.c
Daniel Borkmann f789afed94 selftests/bpf: Add test for redirect from qdisc qevent block
Add a regression test for the NULL current->bpf_net_context deref hit
when a BPF classifier attached to a qdisc qevent block asks for a
redirect. The classifier runs from tcf_qevent_handle() on the qdisc
enqueue path, outside any bpf_net_context.

  # LDLIBS=-static PKG_CONFIG='pkg-config --static' ./vmtest.sh -- ./test_progs -t qevent
  [...]
  + /etc/rcS.d/S50-startup
  ./test_progs -t qevent
  #496/1   tc_qevent/redirect_verdict:OK
  #496/2   tc_qevent/redirect_helper:OK
  #496     tc_qevent:OK
  Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://patch.msgid.link/20260706185609.330006-4-daniel@iogearbox.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-07-20 18:16:43 -07:00

24 lines
482 B
C

// SPDX-License-Identifier: GPL-2.0
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
int redirect_ifindex = 1;
__u64 verdict_calls = 0;
__u64 helper_calls = 0;
SEC("tc")
int qevent_redirect_verdict(struct __sk_buff *skb)
{
__sync_fetch_and_add(&verdict_calls, 1);
return TCX_REDIRECT;
}
SEC("tc")
int qevent_redirect_helper(struct __sk_buff *skb)
{
__sync_fetch_and_add(&helper_calls, 1);
return bpf_redirect(redirect_ifindex, 0);
}
char _license[] SEC("license") = "GPL";