summaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorFelix Riemann <felix.riemann@sma.de>2023-02-10 13:36:44 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-02-22 12:59:50 +0100
commit3d16f4d7a1bcad5c04180ae90de7836bba478ce4 (patch)
tree931997cc3751e0cb8c696ce5b1171b23eaf550c6 /net/core
parent2578123d5bdb7ecbb87679d82f13613173cba428 (diff)
downloadlinux-stable-3d16f4d7a1bcad5c04180ae90de7836bba478ce4.tar.gz
linux-stable-3d16f4d7a1bcad5c04180ae90de7836bba478ce4.tar.bz2
linux-stable-3d16f4d7a1bcad5c04180ae90de7836bba478ce4.zip
net: Fix unwanted sign extension in netdev_stats_to_stats64()
commit 9b55d3f0a69af649c62cbc2633e6d695bb3cc583 upstream. 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> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/dev.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index 70e06853ba25..7a2a4650a898 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10385,7 +10385,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));