From: William Tu Date: Wed, 2 Aug 2017 15:43:52 +0000 (-0700) Subject: bpf: fix the printing of ifindex X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=eb48d682814c8b0e44111c45d7c554e1989fd10d;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git bpf: fix the printing of ifindex Save the ifindex before it gets zeroed so the invalid ifindex can be printed out. Signed-off-by: William Tu Acked-by: Daniel Borkmann Acked-by: John Fastabend Signed-off-by: David S. Miller --- diff --git a/net/core/filter.c b/net/core/filter.c index 7e9708653c6f..78d00933dbe7 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2509,15 +2509,16 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp, { struct redirect_info *ri = this_cpu_ptr(&redirect_info); struct net_device *fwd; + u32 index = ri->ifindex; if (ri->map) return xdp_do_redirect_map(dev, xdp, xdp_prog); - fwd = dev_get_by_index_rcu(dev_net(dev), ri->ifindex); + fwd = dev_get_by_index_rcu(dev_net(dev), index); ri->ifindex = 0; ri->map = NULL; if (unlikely(!fwd)) { - bpf_warn_invalid_xdp_redirect(ri->ifindex); + bpf_warn_invalid_xdp_redirect(index); return -EINVAL; } @@ -2531,11 +2532,12 @@ int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb) { struct redirect_info *ri = this_cpu_ptr(&redirect_info); unsigned int len; + u32 index = ri->ifindex; - dev = dev_get_by_index_rcu(dev_net(dev), ri->ifindex); + dev = dev_get_by_index_rcu(dev_net(dev), index); ri->ifindex = 0; if (unlikely(!dev)) { - bpf_warn_invalid_xdp_redirect(ri->ifindex); + bpf_warn_invalid_xdp_redirect(index); goto err; }