Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3002810rwl; Sat, 1 Apr 2023 21:00:35 -0700 (PDT) X-Google-Smtp-Source: AKy350ZA/oHSvVY9IMJIH7SQ5lwYA6Z5nSvIat3gNrFhavUTrd+bTyaRpS6iAy5V7e5ZDs34HbOB X-Received: by 2002:a17:907:846:b0:944:6b03:7840 with SMTP id ww6-20020a170907084600b009446b037840mr27074037ejb.70.1680408034725; Sat, 01 Apr 2023 21:00:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680408034; cv=none; d=google.com; s=arc-20160816; b=BvaPRgkG2BQBFGDon5wlno0dQMiq99ULp/p5YtJ7/Sfa8sSxHlHW1nCHSqDadmvo0A tvVQRUEL39cper4Jfr/GloJrqpMKcwJMSvMYUqE9kBlCsQAxi/DpMG9M0f1rKKimuPvr Smmb0hJJhBSRPsXaVq62vwbXNBLTZZwO/qqoKONRghxGTy++PBXF2PnrRucyhDpLtTx2 xvNX4A2i9K9+yo32qQpAFVgbt2CBoR2AzIpMGEGY+BOVFuYyFeAs7S5YUVPGp9Vjv8ob JtA1NkFzq6FvOQfSXLSIF7zdgDHW20ebTWUtkfIQkgaSD72qsGo6q98BHj4mnlU6urb1 qnDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:feedback-id:dkim-signature:dkim-signature; bh=5amwOPaxC92wzRYxQ1JVx2WftbFO9nBcwXCPE0iFBO8=; b=n6rhDpZ7Jqquq5oQXN12Jmtx8JrQL2t0cwNCDru6ITpzuiviLjqzxUljUAdj7aoff8 VoQzJcRJt7cCCPKCxJoi2Oy964c+/42MnR2A7HnYtu5kh/15PuooB9Q9jmJcXNW+OsEQ A2lLfbx4qeE0JakcRKMxJskUPlpaEB9Zk8XN5HnJ6P8luvamfAxIkXlqawNyzV776E6D IKUkFj7ksf0tuygF7BtOSfDE6YOAgSRlaYxbqOVYY7pI2iNBQnqxL8oJi2Xe1XQi07cP qFXGm3lZH3yxANLDhsf0eAOPylpfiPa/gcIzMSHUuEamgS5Qv75RsY8YTJ+NxwEeqQtu kn5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joshtriplett.org header.s=fm1 header.b=VF9aqMCe; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=IzGUC9ne; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw21-20020a1709066a1500b009486ead4e67si161899ejc.992.2023.04.01.21.00.06; Sat, 01 Apr 2023 21:00:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@joshtriplett.org header.s=fm1 header.b=VF9aqMCe; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=IzGUC9ne; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230053AbjDBD5m (ORCPT + 99 others); Sat, 1 Apr 2023 23:57:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbjDBD5j (ORCPT ); Sat, 1 Apr 2023 23:57:39 -0400 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B90B121AAD for ; Sat, 1 Apr 2023 20:57:38 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id CFBCB3200A1D; Sat, 1 Apr 2023 23:57:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sat, 01 Apr 2023 23:57:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= joshtriplett.org; h=cc:cc:content-type:content-type:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to; s=fm1; t=1680407855; x=1680494255; bh=5a mwOPaxC92wzRYxQ1JVx2WftbFO9nBcwXCPE0iFBO8=; b=VF9aqMCeFRQygL/ne8 MipRK84Xwz6nJAYRO9LGXXfr5Av6eDwBh9frwI1HTfoxkPWE5hmVblgSQpQ0LiH/ vWKnPWGtyHn3wUPvQa+n6gS9y36BwMBvZ2/5LaT4hcwmtm3XphOCSIsy0HYH8RSS RWtmlVGvsbKtrlCKeKDloXmlvlo0v9Pez0L9VV3ERaK0OUInO4Dj91jBA28o7yfx Lj99nr9NCeRe3Iu6Ut4SvAk3QAOh6sZKWx4DvaW9uSjiAiKZVhoDJ5BVp4dTntyV leLWcYR7GFYh3OMcv71nryXIYuBTh6LA2jgX9AAaka1DjCUpZ4/+Y1KIzBdOgf3M 4Skg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1680407855; x=1680494255; bh=5amwOPaxC92wzRYxQ1JVx2WftbFO9nBcwXC PE0iFBO8=; b=IzGUC9nefIiqZGndgS+++xFjU/94qy7T2Cy87f4p4VSOV0l+NyD 0JtwgwdFJwoP1nHMGs49ITbvioNL+nQTzk8Z43BWlWTszDb6qQHJs8NO5JUoOoHC 0WsXkHP2e66JszO1HojiI/lW01AfnOXMUzotqbQDY2YheVrUxS8CecitZiFvBycQ AfQPa9XWtxq1BqiPc28LRbd+z8gAbXJ77WR70cFnrxPQg1mAPVJa+7C9s2jNirO0 b3TFHodRXG9s9oI+EvPrkBjmY7+2GZsnDaaiq47RGA1FfLCoKBzZEKPAOdPPHAWx 8TseTYVP7sLr831475S93EeR1Kv1ecOGlXg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeigedgjeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugesthdtredttddtvdenucfhrhhomheplfhoshhhucfv rhhiphhlvghtthcuoehjohhshhesjhhoshhhthhrihhplhgvthhtrdhorhhgqeenucggtf frrghtthgvrhhnpeduvdelheettdfgvddvleegueefudegudevffekjeegffefvdeikeeh vdehleekhfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehjohhshhesjhhoshhhthhrihhplhgvthhtrdhorhhg X-ME-Proxy: Feedback-ID: i83e94755:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 1 Apr 2023 23:57:31 -0400 (EDT) Date: Sun, 2 Apr 2023 12:57:29 +0900 From: Josh Triplett To: linux-kernel@vger.kernel.org, Andrew Morton Cc: Catalin Marinas , "Eric W. Biederman" , Joey Gouly , Greg Kroah-Hartman , Alexey Gladkov , "Jason A. Donenfeld" , Mark Brown Subject: [PATCH] sysinfo: Saturate 16-bit procs rather than wrapping Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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