From: Tonghao Zhang <redacted>
We may use bpf_redirect to redirect the packets to other
netdevice (e.g. ifb) in ingress and egress path.
The target netdevice may check the *skb_iif, *redirected
and *from_ingress, for example, if skb_iif or redirected
is 0, ifb will drop the packets.
Fixes: a70b506efe89 ("bpf: enforce recursion limit on redirects")
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Tonghao Zhang <redacted>
---
net/core/filter.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
@@ -2107,9 +2107,19 @@ static inline int __bpf_tx_skb(struct net_device *dev, struct sk_buff *skb)return-ENETDOWN;}-skb->dev=dev;+/* The target netdevice (e.g. ifb) may use the:+*-skb_iif+*-redirected+*-from_ingress+*/+skb->skb_iif=skb->dev->ifindex;
This doesn't look right to me to set it unconditionally in tx path, isn't ifb_ri_tasklet()
setting skb->skb_iif in this case (or __netif_receive_skb_core() in main rx path)?
Also, I would suggest to add a proper BPF selftest which outlines the issue you're solving
in here.
@@ -2107,9 +2107,19 @@ static inline int __bpf_tx_skb(struct net_device *dev, struct sk_buff *skb)return-ENETDOWN;}-skb->dev=dev;+/* The target netdevice (e.g. ifb) may use the:+*-skb_iif+*-redirected+*-from_ingress+*/+skb->skb_iif=skb->dev->ifindex;
This doesn't look right to me to set it unconditionally in tx path, isn't ifb_ri_tasklet()
setting skb->skb_iif in this case (or __netif_receive_skb_core() in main rx path)?
Hi
the act_mirred set the skb->skb_iif, redirected and from_ingress. and
__netif_receive_skb_core also set skb->skb_iif.
so we can use the act_mirred to ifb in ingress or egress path.
For ingress, when we use the bpf_redirct to ifb, we should set
redirected, and from_ingress.
For egress, when we use the bpf_redirct to ifb, we should skb_iif ,
set redirected, and from_ingress.
Also, I would suggest to add a proper BPF selftest which outlines the issue you're solving
in here.
@@ -2107,9 +2107,19 @@ static inline int __bpf_tx_skb(struct net_device *dev, struct sk_buff *skb)return-ENETDOWN;}-skb->dev=dev;+/* The target netdevice (e.g. ifb) may use the:+*-skb_iif+*-redirected+*-from_ingress+*/+skb->skb_iif=skb->dev->ifindex;
This doesn't look right to me to set it unconditionally in tx path, isn't ifb_ri_tasklet()
setting skb->skb_iif in this case (or __netif_receive_skb_core() in main rx path)?
Hi
the act_mirred set the skb->skb_iif, redirected and from_ingress. and
__netif_receive_skb_core also set skb->skb_iif.
so we can use the act_mirred to ifb in ingress or egress path.
For ingress, when we use the bpf_redirct to ifb, we should set
redirected, and from_ingress.
For egress, when we use the bpf_redirct to ifb, we should skb_iif ,
set redirected, and from_ingress.
Hi Daniel,
because we don't know bpf_redirct invoked in tx path, or rx path.
can we set the skb->skb_iif unconditionally in bpf_redirct? any thoughts?
quoted
Also, I would suggest to add a proper BPF selftest which outlines the issue you're solving
in here.