Commit 9fa7485a authored by Felix Riemann's avatar Felix Riemann Committed by Zhengchao Shao
Browse files

net: Fix unwanted sign extension in netdev_stats_to_stats64()

stable inclusion
from stable-v5.10.169
commit e2bf52ff159db37b5b60d34069464c00a1f54fd6
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I95ATV
CVE: CVE-2023-52578

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=e2bf52ff159db37b5b60d34069464c00a1f54fd6



--------------------------------

commit 9b55d3f0 upstream.

When converting net_device_stats to rtnl_link_stats64 sign extension
is triggered on ILP32 machines as 6c1c5097 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: 6c1c5097 ("net: add atomic_long_t to net_device_stats fields")
Signed-off-by: default avatarFelix Riemann <felix.riemann@sma.de>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
parent 71db1ded
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10354,7 +10354,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));