mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
net/sched: Handle TC_ACT_REDIRECT from qdisc filter chains
When a TC filter attached to a qdisc filter chain returns TC_ACT_REDIRECT (ex: via an eBPF program calling bpf_redirect() or an act_bpf action), the redirect was silently lost i.e no qdisc classify function handled TC_ACT_REDIRECT, so the packet fell through the switch and was enqueued normally instead of being redirected. This has been broken since bpf_redirect() was introduced for TC in commit27b29f6305("bpf: add bpf_redirect() helper"). We got lucky for a long time because bpf_net_context was a per-CPU variable that was always available. commit401cb7dae8("net: Reference bpf_redirect_info via task_struct on PREEMPT_RT.") turned bpf_net_context into a task_struct member that is only set up by explicit callers. Without a caller setting it up, bpf_redirect() itself crashes with a NULL pointer dereference in bpf_net_ctx_get_ri(). However, even with bpf_net_context available, TC_ACT_REDIRECT from qdisc filter chains cannot be honored without adding skb_do_redirect() calls to every qdisc classify function, which would require changes across net/sched/. Isolate it to ebpf core where it belongs. Instead, add a tcf_classify_qdisc() inline helper in pkt_cls.h, as a wrapper around tcf_classify() for use by qdisc classify functions and tcf_qevent_handle(). When the classify verdict is TC_ACT_REDIRECT, the wrapper converts it to TC_ACT_SHOT, dropping the packet rather than letting it continue silently. Dropping is preferred over letting the packet through because the user immediately sees packet loss. Silently passing the packet through would hide the problem and leave the user wondering why their redirect is not working. The clsact fast path, tc_run() continues to call tcf_classify() directly and is unaffected: TC_ACT_REDIRECT is returned as-is and handled by sch_handle_egress/ingress() calling skb_do_redirect() as before. Fixes:27b29f6305("bpf: add bpf_redirect() helper") Fixes:401cb7dae8("net: Reference bpf_redirect_info via task_struct on PREEMPT_RT.") Tested-by: Victor Nogueira <victor@mojatatu.com> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Link: https://patch.msgid.link/20260706185609.330006-3-daniel@iogearbox.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
3f4920d165
commit
ec48b3be2c
|
|
@ -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))
|
||||
ret = TC_ACT_SHOT;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline unsigned long
|
||||
__cls_set_class(unsigned long *clp, unsigned long cl)
|
||||
|
|
|
|||
|
|
@ -4045,9 +4045,7 @@ struct sk_buff *tcf_qevent_handle(struct tcf_qevent *qe, struct Qdisc *sch, stru
|
|||
|
||||
fl = rcu_dereference_bh(qe->filter_chain);
|
||||
|
||||
switch (tcf_classify(skb, NULL, fl, &cl_res, false)) {
|
||||
case TC_ACT_REDIRECT:
|
||||
fallthrough;
|
||||
switch (tcf_classify_qdisc(skb, fl, &cl_res, false)) {
|
||||
case TC_ACT_SHOT:
|
||||
qdisc_qstats_drop(sch);
|
||||
__qdisc_drop(skb, to_free);
|
||||
|
|
|
|||
|
|
@ -1727,7 +1727,7 @@ static u32 cake_classify(struct Qdisc *sch, struct cake_tin_data **t,
|
|||
goto hash;
|
||||
|
||||
*qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
||||
result = tcf_classify(skb, NULL, filter, &res, false);
|
||||
result = tcf_classify_qdisc(skb, filter, &res, false);
|
||||
|
||||
if (result >= 0) {
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ static struct drr_class *drr_classify(struct sk_buff *skb, struct Qdisc *sch,
|
|||
|
||||
*qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
||||
fl = rcu_dereference_bh(q->filter_list);
|
||||
result = tcf_classify(skb, NULL, fl, &res, false);
|
||||
result = tcf_classify_qdisc(skb, fl, &res, false);
|
||||
if (result >= 0) {
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (result) {
|
||||
|
|
|
|||
|
|
@ -364,7 +364,7 @@ static int dualpi2_skb_classify(struct dualpi2_sched_data *q,
|
|||
if (!fl)
|
||||
return NET_XMIT_SUCCESS;
|
||||
|
||||
result = tcf_classify(skb, NULL, fl, &res, false);
|
||||
result = tcf_classify_qdisc(skb, fl, &res, false);
|
||||
if (result >= 0) {
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (result) {
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ static struct ets_class *ets_classify(struct sk_buff *skb, struct Qdisc *sch,
|
|||
*qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
||||
if (TC_H_MAJ(skb->priority) != sch->handle) {
|
||||
fl = rcu_dereference_bh(q->filter_list);
|
||||
err = tcf_classify(skb, NULL, fl, &res, false);
|
||||
err = tcf_classify_qdisc(skb, fl, &res, false);
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (err) {
|
||||
case TC_ACT_STOLEN:
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ static unsigned int fq_codel_classify(struct sk_buff *skb, struct Qdisc *sch,
|
|||
return fq_codel_hash(q, skb) + 1;
|
||||
|
||||
*qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
||||
result = tcf_classify(skb, NULL, filter, &res, false);
|
||||
result = tcf_classify_qdisc(skb, filter, &res, false);
|
||||
if (result >= 0) {
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (result) {
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ static unsigned int fq_pie_classify(struct sk_buff *skb, struct Qdisc *sch,
|
|||
return fq_pie_hash(q, skb) + 1;
|
||||
|
||||
*qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
||||
result = tcf_classify(skb, NULL, filter, &res, false);
|
||||
result = tcf_classify_qdisc(skb, filter, &res, false);
|
||||
if (result >= 0) {
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (result) {
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@ hfsc_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)
|
|||
*qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
||||
head = &q->root;
|
||||
tcf = rcu_dereference_bh(q->root.filter_list);
|
||||
while (tcf && (result = tcf_classify(skb, NULL, tcf, &res, false)) >= 0) {
|
||||
while (tcf && (result = tcf_classify_qdisc(skb, tcf, &res, false)) >= 0) {
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (result) {
|
||||
case TC_ACT_QUEUED:
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ static struct htb_class *htb_classify(struct sk_buff *skb, struct Qdisc *sch,
|
|||
}
|
||||
|
||||
*qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
||||
while (tcf && (result = tcf_classify(skb, NULL, tcf, &res, false)) >= 0) {
|
||||
while (tcf && (result = tcf_classify_qdisc(skb, tcf, &res, false)) >= 0) {
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (result) {
|
||||
case TC_ACT_QUEUED:
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ multiq_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)
|
|||
int err;
|
||||
|
||||
*qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
||||
err = tcf_classify(skb, NULL, fl, &res, false);
|
||||
err = tcf_classify_qdisc(skb, fl, &res, false);
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (err) {
|
||||
case TC_ACT_STOLEN:
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ prio_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)
|
|||
*qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
||||
if (TC_H_MAJ(skb->priority) != sch->handle) {
|
||||
fl = rcu_dereference_bh(q->filter_list);
|
||||
err = tcf_classify(skb, NULL, fl, &res, false);
|
||||
err = tcf_classify_qdisc(skb, fl, &res, false);
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (err) {
|
||||
case TC_ACT_STOLEN:
|
||||
|
|
|
|||
|
|
@ -709,7 +709,7 @@ static struct qfq_class *qfq_classify(struct sk_buff *skb, struct Qdisc *sch,
|
|||
|
||||
*qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
||||
fl = rcu_dereference_bh(q->filter_list);
|
||||
result = tcf_classify(skb, NULL, fl, &res, false);
|
||||
result = tcf_classify_qdisc(skb, fl, &res, false);
|
||||
if (result >= 0) {
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (result) {
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ static bool sfb_classify(struct sk_buff *skb, struct tcf_proto *fl,
|
|||
struct tcf_result res;
|
||||
int result;
|
||||
|
||||
result = tcf_classify(skb, NULL, fl, &res, false);
|
||||
result = tcf_classify_qdisc(skb, fl, &res, false);
|
||||
if (result >= 0) {
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (result) {
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ static unsigned int sfq_classify(struct sk_buff *skb, struct Qdisc *sch,
|
|||
return sfq_hash(q, skb) + 1;
|
||||
|
||||
*qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
||||
result = tcf_classify(skb, NULL, fl, &res, false);
|
||||
result = tcf_classify_qdisc(skb, fl, &res, false);
|
||||
if (result >= 0) {
|
||||
#ifdef CONFIG_NET_CLS_ACT
|
||||
switch (result) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user