Alexei Starovoitov suggested guarding the re-lookup in neigh_update_process_arp_queue() with the skb's device instead of changing every producer that steers a packet to another device. This is that guard. The issue: neigh_update_process_arp_queue() re-looks the neighbour up from the skb's dst, because shapers, eql and sch_teql can output a packet through a different neigh object and it has to be reinjected at the top of the path. A packet steered to another device by bpf_redirect_neigh(), or by an nft "fwd ... device" rule, is parked on that device's neighbour while its dst is still the route that named the device it arrived on. The lookup returns the neighbour of that route, so the drained frame leaves the parking device with the arrived-on device's source address and that route's neighbour as the destination. The Fix: Skip the lookup when skb->dev is already neigh->dev; the parking neighbour is the top-level one in that case and can reinject the packet itself. The condition never consults dst->dev: teql still takes the lookup because there skb->dev is the master, not the slave's neigh->dev. Some context: A route for one device is a normal thing to find on a frame that leaves another one; bpf_redirect() and mirred have always produced it, and the packet has to keep it for the xfrm, tunnel and lwtstate consumers further down. lwtstate, NBMA tunnels, the route realm and ICMP errors are unaffected, and the fast path does not change. Conditions to recreate the bug: Two network namespaces joined by two veth pairs, va/vb in the first and va_peer/vb_peer in the second. vb_peer carries no address, so the neighbour for its side stays unresolved. ip netns add ns1 ip netns add ns2 ip link add va type veth peer name va_peer ip link add vb type veth peer name vb_peer ip link set va netns ns1 ip link set va_peer netns ns2 ip link set vb netns ns1 ip link set vb_peer netns ns2 ip -n ns1 link set va address 02:aa:00:00:00:01 ip -n ns1 link set vb address 02:bb:00:00:00:01 ip -n ns1 addr add 10.10.0.1/24 dev va ip -n ns1 addr add 10.1.0.1/24 dev vb ip -n ns2 addr add 10.10.0.2/24 dev va_peer ip -n ns1 link set va up ip -n ns1 link set vb up ip -n ns2 link set va_peer up ip -n ns2 link set vb_peer up ip -n ns1 neigh replace 10.10.0.2 lladdr 02:aa:00:00:00:ab dev va nud permanent ip netns exec ns1 nft add table netdev t ip netns exec ns1 nft "add chain netdev t c { type filter hook egress device va priority 0; policy accept; }" ip netns exec ns1 nft add rule netdev t c fwd ip to 10.1.0.2 device vb One packet to 10.10.0.2 egresses va and the rule steers it through vb to 10.1.0.2, whose neighbour is incomplete, so it is parked there with va's route. A cls_bpf program returning struct bpf_redir_neigh nh = { .nh_family = AF_INET, .ipv4_nh = htonl(0x0a010002) }; return bpf_redirect_neigh(vb, &nh, sizeof(nh), 0); in the same hook produces the same park. Making that neighbour valid drains the queue: ip -n ns1 neigh replace 10.1.0.2 lladdr 02:bb:00:00:00:cd dev vb nud permanent The single frame that leaves vb_peer carries 02:aa:00:00:00:01 as its source and 02:aa:00:00:00:ab as its destination instead of vb's own addresses. Setup needs CAP_NET_ADMIN in a user namespace of its own (unshare -Urn); the payload itself does not. The bpf_redirect_neigh() arm is a higher-privileged alternative; the nft route above is the minimum. Fixes: 13a43d94ab02 ("neigh: Convert over to dst_neigh_lookup_skb().") Link: https://lore.kernel.org/netdev/DMX7RM93TMGR.AXFN4YJ55REF@gmail.com/ Suggested-by: Alexei Starovoitov Acked-by: Alexei Starovoitov Signed-off-by: Jamal Hadi Salim --- v1 -> v2: - say what the guard actually tests: it is skipped when skb->dev is already neigh->dev and never consults dst->dev, so teql still takes the lookup because there skb->dev is the master, not the slave's neigh->dev. - add the Fixes: tag for the drain's dst-based re-lookup, and carry Alexei's Acked-by. --- net/core/neighbour.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 887d2e35cd04..219dc89716f8 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1334,9 +1334,11 @@ static void neigh_update_process_arp_queue(struct neighbour *neigh) * the packet in the output path. So what we need to do * here is re-lookup the top-level neigh in the path so * we can reinject the packet there. + * When skb->dev is neigh->dev 'neigh' is the top-level one. + * dst can be a route via another device after a redirect. */ n2 = NULL; - if (dst && + if (dst && skb->dev != neigh->dev && READ_ONCE(dst->obsolete) != DST_OBSOLETE_DEAD) { n2 = dst_neigh_lookup_skb(dst, skb); if (n2) -- 2.43.0