net: Fix unwanted sign extension in netdev_stats_to_stats64()
authorFelix Riemann <felix.riemann@sma.de>
Fri, 10 Feb 2023 12:36:44 +0000 (13:36 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Feb 2023 11:57:07 +0000 (12:57 +0100)
commit50267cf35ba0289333f525ca35fbf22399724d9e
tree04c59a96b29d93943138cf6f37d6e29b83d808d2
parent3775c95ffbc6471fbbdf176deb49c12eaba1e27f
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>
net/core/dev.c