[PATCH] sysinfo: Saturate 16-bit procs rather than wrapping

From: Josh Triplett
Date: Sat Apr 01 2023 - 23:57:49 EST


struct sysinfo has a 16-bit field for the number of processes. Current
systems can easily exceed this. Rather than wrapping around, saturate
the value at U16_MAX. This is still incorrect, but more likely to
help the user know what's going on; a caller can then (for instance)
parse the full value out of /proc/loadavg.

Signed-off-by: Josh Triplett <josh@xxxxxxxxxxxxxxxx>
---

Not sure what tree changes to kernel/sys.c should flow through. Andrew,
could you take this through your tree (assuming you agree with it), or
suggest what tree it should go through instead?

diff --git a/kernel/sys.c b/kernel/sys.c
index 495cd87d9bf4..ba05fca26927 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2699,7 +2699,7 @@ static int do_sysinfo(struct sysinfo *info)

get_avenrun(info->loads, 0, SI_LOAD_SHIFT - FSHIFT);

- info->procs = nr_threads;
+ info->procs = min_t(typeof(nr_threads), nr_threads, U16_MAX);

si_meminfo(info);
si_swapinfo(info);
--
2.40.0