public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sysinfo: Saturate 16-bit procs rather than wrapping
@ 2023-04-02  3:57 Josh Triplett
  2023-04-05 22:27 ` Eric W. Biederman
  0 siblings, 1 reply; 3+ messages in thread
From: Josh Triplett @ 2023-04-02  3:57 UTC (permalink / raw)
  To: linux-kernel, Andrew Morton
  Cc: Catalin Marinas, Eric W. Biederman, Joey Gouly,
	Greg Kroah-Hartman, Alexey Gladkov, Jason A. Donenfeld,
	Mark Brown

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@joshtriplett.org>
---

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-04-06  1:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-02  3:57 [PATCH] sysinfo: Saturate 16-bit procs rather than wrapping Josh Triplett
2023-04-05 22:27 ` Eric W. Biederman
2023-04-06  1:03   ` Josh Triplett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox