netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] rtnetlink: Fix handling of disabled L3 stats in RTM_GETSTATS replies
@ 2022-04-12 20:25 Petr Machata
  2022-04-13  6:10 ` Ido Schimmel
  2022-04-14  7:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Petr Machata @ 2022-04-12 20:25 UTC (permalink / raw)
  To: netdev; +Cc: David S. Miller, Jakub Kicinski, Ido Schimmel, Petr Machata

When L3 stats are disabled, rtnl_offload_xstats_get_size_stats() returns
size of 0, which is supposed to be an indication that the corresponding
attribute should not be emitted. However, instead, the current code
reserves a 0-byte attribute.

The reason this does not show up as a citation on a kasan kernel is that
netdev_offload_xstats_get(), which is supposed to fill in the data, never
ends up getting called, because rtnl_offload_xstats_get_stats() notices
that the stats are not actually used and skips the call.

Thus a zero-length IFLA_OFFLOAD_XSTATS_L3_STATS attribute ends up in a
response, confusing the userspace.

Fix by skipping the L3-stats related block in rtnl_offload_xstats_fill().

Fixes: 0e7788fd7622 ("net: rtnetlink: Add UAPI for obtaining L3 offload xstats")
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
 net/core/rtnetlink.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 159c9c61e6af..d1381ea6d52e 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -5242,6 +5242,8 @@ static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev,
 		*prividx = attr_id_l3_stats;
 
 		size_l3 = rtnl_offload_xstats_get_size_stats(dev, t_l3);
+		if (!size_l3)
+			goto skip_l3_stats;
 		attr = nla_reserve_64bit(skb, attr_id_l3_stats, size_l3,
 					 IFLA_OFFLOAD_XSTATS_UNSPEC);
 		if (!attr)
@@ -5253,6 +5255,7 @@ static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev,
 			return err;
 
 		have_data = true;
+skip_l3_stats:
 		*prividx = 0;
 	}
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] rtnetlink: Fix handling of disabled L3 stats in RTM_GETSTATS replies
  2022-04-12 20:25 [PATCH net] rtnetlink: Fix handling of disabled L3 stats in RTM_GETSTATS replies Petr Machata
@ 2022-04-13  6:10 ` Ido Schimmel
  2022-04-14  7:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Ido Schimmel @ 2022-04-13  6:10 UTC (permalink / raw)
  To: Petr Machata; +Cc: netdev, David S. Miller, Jakub Kicinski, Ido Schimmel

On Tue, Apr 12, 2022 at 10:25:06PM +0200, Petr Machata wrote:
> When L3 stats are disabled, rtnl_offload_xstats_get_size_stats() returns
> size of 0, which is supposed to be an indication that the corresponding
> attribute should not be emitted. However, instead, the current code
> reserves a 0-byte attribute.
> 
> The reason this does not show up as a citation on a kasan kernel is that
> netdev_offload_xstats_get(), which is supposed to fill in the data, never
> ends up getting called, because rtnl_offload_xstats_get_stats() notices
> that the stats are not actually used and skips the call.
> 
> Thus a zero-length IFLA_OFFLOAD_XSTATS_L3_STATS attribute ends up in a
> response, confusing the userspace.
> 
> Fix by skipping the L3-stats related block in rtnl_offload_xstats_fill().
> 
> Fixes: 0e7788fd7622 ("net: rtnetlink: Add UAPI for obtaining L3 offload xstats")
> Signed-off-by: Petr Machata <petrm@nvidia.com>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] rtnetlink: Fix handling of disabled L3 stats in RTM_GETSTATS replies
  2022-04-12 20:25 [PATCH net] rtnetlink: Fix handling of disabled L3 stats in RTM_GETSTATS replies Petr Machata
  2022-04-13  6:10 ` Ido Schimmel
@ 2022-04-14  7:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-14  7:20 UTC (permalink / raw)
  To: Petr Machata; +Cc: netdev, davem, kuba, idosch

Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <pabeni@redhat.com>:

On Tue, 12 Apr 2022 22:25:06 +0200 you wrote:
> When L3 stats are disabled, rtnl_offload_xstats_get_size_stats() returns
> size of 0, which is supposed to be an indication that the corresponding
> attribute should not be emitted. However, instead, the current code
> reserves a 0-byte attribute.
> 
> The reason this does not show up as a citation on a kasan kernel is that
> netdev_offload_xstats_get(), which is supposed to fill in the data, never
> ends up getting called, because rtnl_offload_xstats_get_stats() notices
> that the stats are not actually used and skips the call.
> 
> [...]

Here is the summary with links:
  - [net] rtnetlink: Fix handling of disabled L3 stats in RTM_GETSTATS replies
    https://git.kernel.org/netdev/net/c/23cfe941b52e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-14  7:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-12 20:25 [PATCH net] rtnetlink: Fix handling of disabled L3 stats in RTM_GETSTATS replies Petr Machata
2022-04-13  6:10 ` Ido Schimmel
2022-04-14  7:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).