[PATCH 1/2] softirq: fix integer overflow in function show_stat()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Zhen Lei <thunder.leizhen@xxxxxxxxxx>

The statistics function of softirq is supported by commit aa0ce5bbc2db
("softirq: introduce statistics for softirq") in 2009. At that time,
64-bit processors should not have many cores and would not face
significant count overflow problems. Now it's common for a processor to
have hundreds of cores. Assume that there are 100 cores and 10
TIMER_SOFTIRQ are generated per second, then the 32-bit sum will be
overflowed after 50 days.

For example:
seq_put_decimal_ull(p, "softirq ", (unsigned long long)sum_softirq);
for (i = 0; i < NR_SOFTIRQS; i++)
	seq_put_decimal_ull(p, " ", per_softirq_sums[i]);

$ cat /proc/stat | tail -n 1
softirq 22929066124 9 2963267579 4128150 2618598635 546358555 0 \
629391610 1326100278 74637 1956244783

Here, the sum of per_softirq_sums[] is 10044164236 and is not equal to
22929066124. Because integers overflowed.

Therefore, change the type of local variable per_softirq_sums[] to u64.

Fixes: d3d64df21d3d ("proc: export statistics for softirq to /proc")
Signed-off-by: Zhen Lei <thunder.leizhen@xxxxxxxxxx>
---
 fs/proc/stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index da60956b2915645..84aac577a50cabb 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -86,7 +86,7 @@ static int show_stat(struct seq_file *p, void *v)
 	u64 guest, guest_nice;
 	u64 sum = 0;
 	u64 sum_softirq = 0;
-	unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
+	u64 per_softirq_sums[NR_SOFTIRQS] = {0};
 	struct timespec64 boottime;
 
 	user = nice = system = idle = iowait =
-- 
2.25.1




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux