Commit 9d46e104 authored by Eric Dumazet's avatar Eric Dumazet Committed by Zhengchao Shao
Browse files

net: add atomic_long_t to net_device_stats fields

stable inclusion
from stable-v5.10.163
commit 037db10e3f93f0d51ab3f52fbdaa7e67a7edd0b8
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=037db10e3f93f0d51ab3f52fbdaa7e67a7edd0b8



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

[ Upstream commit 6c1c5097 ]

Long standing KCSAN issues are caused by data-race around
some dev->stats changes.

Most performance critical paths already use per-cpu
variables, or per-queue ones.

It is reasonable (and more correct) to use atomic operations
for the slow paths.

This patch adds an union for each field of net_device_stats,
so that we can convert paths that are not yet protected
by a spinlock or a mutex.

netdev_stats_to_stats64() no longer has an #if BITS_PER_LONG==64

Note that the memcpy() we were using on 64bit arches
had no provision to avoid load-tearing,
while atomic_long_read() is providing the needed protection
at no cost.

Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
parent 70c98c7d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment