Commit fdf3f680 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

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: default avatarGal Pressman <gal@nvidia.com>
Link: https://lore.kernel.org/c5df3b60-246a-4030-9c9a-0a35cd1ca924@nvidia.com


Fixes: b4ab3141 ("bpf: Add redirect_neigh helper as redirect drop-in")
Acked-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260130033827.698841-1-kuba@kernel.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 6d06bc83
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -2289,12 +2289,12 @@ static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev,

	err = bpf_out_neigh_v6(net, skb, dev, nh);
	if (unlikely(net_xmit_eval(err)))
		DEV_STATS_INC(dev, tx_errors);
		dev_core_stats_tx_dropped_inc(dev);
	else
		ret = NET_XMIT_SUCCESS;
	goto out_xmit;
out_drop:
	DEV_STATS_INC(dev, tx_errors);
	dev_core_stats_tx_dropped_inc(dev);
	kfree_skb(skb);
out_xmit:
	return ret;
@@ -2396,12 +2396,12 @@ static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev,

	err = bpf_out_neigh_v4(net, skb, dev, nh);
	if (unlikely(net_xmit_eval(err)))
		DEV_STATS_INC(dev, tx_errors);
		dev_core_stats_tx_dropped_inc(dev);
	else
		ret = NET_XMIT_SUCCESS;
	goto out_xmit;
out_drop:
	DEV_STATS_INC(dev, tx_errors);
	dev_core_stats_tx_dropped_inc(dev);
	kfree_skb(skb);
out_xmit:
	return ret;