Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: don't touch dev->stats in BPF redirect paths

Gal reports that BPF redirect increments dev->stats.tx_errors
on failure. This is not correct, most modern drivers completely
ignore dev->stats so these drops will be invisible to the user.
Core code should use the dedicated core stats which are folded
into device stats in dev_get_stats().

Note that we're switching from tx_errors to tx_dropped.
Core only has tx_dropped, hence presumably users already expect
that counter to increment for "stack" Tx issues.

Reported-by: Gal Pressman <gal@nvidia.com>
Link: https://lore.kernel.org/c5df3b60-246a-4030-9c9a-0a35cd1ca924@nvidia.com
Fixes: b4ab31414970 ("bpf: Add redirect_neigh helper as redirect drop-in")
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260130033827.698841-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+4 -4
+4 -4
net/core/filter.c
··· 2289 2289 2290 2290 err = bpf_out_neigh_v6(net, skb, dev, nh); 2291 2291 if (unlikely(net_xmit_eval(err))) 2292 - DEV_STATS_INC(dev, tx_errors); 2292 + dev_core_stats_tx_dropped_inc(dev); 2293 2293 else 2294 2294 ret = NET_XMIT_SUCCESS; 2295 2295 goto out_xmit; 2296 2296 out_drop: 2297 - DEV_STATS_INC(dev, tx_errors); 2297 + dev_core_stats_tx_dropped_inc(dev); 2298 2298 kfree_skb(skb); 2299 2299 out_xmit: 2300 2300 return ret; ··· 2396 2396 2397 2397 err = bpf_out_neigh_v4(net, skb, dev, nh); 2398 2398 if (unlikely(net_xmit_eval(err))) 2399 - DEV_STATS_INC(dev, tx_errors); 2399 + dev_core_stats_tx_dropped_inc(dev); 2400 2400 else 2401 2401 ret = NET_XMIT_SUCCESS; 2402 2402 goto out_xmit; 2403 2403 out_drop: 2404 - DEV_STATS_INC(dev, tx_errors); 2404 + dev_core_stats_tx_dropped_inc(dev); 2405 2405 kfree_skb(skb); 2406 2406 out_xmit: 2407 2407 return ret;