* [PATCH] net: Fix unwanted sign extension in netdev_stats_to_stats64()
@ 2023-02-10 12:36 Felix Riemann
2023-02-10 15:13 ` Eric Dumazet
2023-02-13 10:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Felix Riemann @ 2023-02-10 12:36 UTC (permalink / raw)
To: netdev
Cc: linux-kernel, Eric Dumazet, Jakub Kicinski, David S. Miller,
Felix Riemann
From: Felix Riemann <felix.riemann@sma.de>
When converting net_device_stats to rtnl_link_stats64 sign extension
is triggered on ILP32 machines as 6c1c509778 changed the previous
"ulong -> u64" conversion to "long -> u64" by accessing the
net_device_stats fields through a (signed) atomic_long_t.
This causes for example the received bytes counter to jump to 16EiB after
having received 2^31 bytes. Casting the atomic value to "unsigned long"
beforehand converting it into u64 avoids this.
Fixes: 6c1c5097781f ("net: add atomic_long_t to net_device_stats fields")
Signed-off-by: Felix Riemann <felix.riemann@sma.de>
---
net/core/dev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index b76fb37b381e..ea0a7bac1e5c 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10375,7 +10375,7 @@ void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
BUILD_BUG_ON(n > sizeof(*stats64) / sizeof(u64));
for (i = 0; i < n; i++)
- dst[i] = atomic_long_read(&src[i]);
+ dst[i] = (unsigned long)atomic_long_read(&src[i]);
/* zero out counters that only exist in rtnl_link_stats64 */
memset((char *)stats64 + n * sizeof(u64), 0,
sizeof(*stats64) - n * sizeof(u64));
--
2.35.3
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] net: Fix unwanted sign extension in netdev_stats_to_stats64()
2023-02-10 12:36 [PATCH] net: Fix unwanted sign extension in netdev_stats_to_stats64() Felix Riemann
@ 2023-02-10 15:13 ` Eric Dumazet
2023-02-13 10:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2023-02-10 15:13 UTC (permalink / raw)
To: Felix Riemann; +Cc: netdev, linux-kernel, Jakub Kicinski, David S. Miller
On Fri, Feb 10, 2023 at 1:37 PM Felix Riemann <svc.sw.rte.linux@sma.de> wrote:
>
> From: Felix Riemann <felix.riemann@sma.de>
>
> When converting net_device_stats to rtnl_link_stats64 sign extension
> is triggered on ILP32 machines as 6c1c509778 changed the previous
> "ulong -> u64" conversion to "long -> u64" by accessing the
> net_device_stats fields through a (signed) atomic_long_t.
>
> This causes for example the received bytes counter to jump to 16EiB after
> having received 2^31 bytes. Casting the atomic value to "unsigned long"
> beforehand converting it into u64 avoids this.
>
> Fixes: 6c1c5097781f ("net: add atomic_long_t to net_device_stats fields")
> Signed-off-by: Felix Riemann <felix.riemann@sma.de>
> ---
Thanks for the fix.
Reviewed-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] net: Fix unwanted sign extension in netdev_stats_to_stats64()
2023-02-10 12:36 [PATCH] net: Fix unwanted sign extension in netdev_stats_to_stats64() Felix Riemann
2023-02-10 15:13 ` Eric Dumazet
@ 2023-02-13 10:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-02-13 10:00 UTC (permalink / raw)
To: Felix Riemann; +Cc: netdev, linux-kernel, edumazet, kuba, davem, felix.riemann
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:
On Fri, 10 Feb 2023 13:36:44 +0100 you wrote:
> From: Felix Riemann <felix.riemann@sma.de>
>
> When converting net_device_stats to rtnl_link_stats64 sign extension
> is triggered on ILP32 machines as 6c1c509778 changed the previous
> "ulong -> u64" conversion to "long -> u64" by accessing the
> net_device_stats fields through a (signed) atomic_long_t.
>
> [...]
Here is the summary with links:
- net: Fix unwanted sign extension in netdev_stats_to_stats64()
https://git.kernel.org/netdev/net/c/9b55d3f0a69a
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:[~2023-02-13 10:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-10 12:36 [PATCH] net: Fix unwanted sign extension in netdev_stats_to_stats64() Felix Riemann
2023-02-10 15:13 ` Eric Dumazet
2023-02-13 10:00 ` 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
all inboxes | Powered by JetHome®