Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,stable@vger.kernel.org,
	manfred@colorfullife.com,dave@stgolabs.net,david.laight.linux@gmail.com,
	akpm@linux-foundation.org
Subject: + ipc-msg-fix-saturation-of-percpu-counts-in-msgctl_info.patch added to mm-nonmm-unstable branch
Date: Wed, 28 Oct 2026 18:15:08 -0700	[thread overview]
Message-ID: <20261029011509.6005D1F01825@smtp.kernel.org> (raw)


The patch titled
     Subject: ipc/msg: fix saturation of percpu counts in msgctl_info()
has been added to the -mm mm-nonmm-unstable branch.  Its filename is
     ipc-msg-fix-saturation-of-percpu-counts-in-msgctl_info.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/ipc-msg-fix-saturation-of-percpu-counts-in-msgctl_info.patch

This patch will later appear in the mm-nonmm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: David Laight <david.laight.linux@gmail.com>
Subject: ipc/msg: fix saturation of percpu counts in msgctl_info()
Date: Wed, 19 Nov 2025 22:41:01 +0000

While the percpu_counter_sum() values are unlikely to be large the code
tries to saturate them using min_t(int, percpu_counter_sum(), INT_MAX)
This just doesn't work since the high bits are all masked and then the
(possibly negative) value assigned.

When aggregate System V message queue usage exceeds INT_MAX, MSG_INFO
returns wrapped statistics instead of saturating them.  At 2 GiB of queued
data the byte count becomes negative, and at 4 GiB it becomes zero. 
Consequently, ipcs -q -u can display an enormous used-space value or
report no queued data despite substantial usage.  Monitoring programs
using this interface can therefore substantially underreport or overreport
resource consumption.  The bug affects statistics; it does not corrupt
queued messages or alter queue-limit enforcement.

Replace the min_t() with a plain min().

Link: https://lore.kernel.org/20251119224140.8616-6-david.laight.linux@gmail.com
Fixes: 72d1e611082e ("ipc/msg: mitigate the lock contention with percpu counter")
Signed-off-by: David Laight <david.laight.linux@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Manfred Spraul <manfred@colorfullife.com>
Cc: <stable@vger.kernel.org>
---

 ipc/msg.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

--- a/ipc/msg.c~ipc-msg-fix-saturation-of-percpu-counts-in-msgctl_info
+++ a/ipc/msg.c
@@ -501,11 +501,9 @@ static int msgctl_info(struct ipc_namesp
 	max_idx = ipc_get_maxidx(&msg_ids(ns));
 	up_read(&msg_ids(ns).rwsem);
 	if (cmd == MSG_INFO) {
-		msginfo->msgmap = min_t(int,
-				     percpu_counter_sum(&ns->percpu_msg_hdrs),
+		msginfo->msgmap = min(percpu_counter_sum(&ns->percpu_msg_hdrs),
 				     INT_MAX);
-		msginfo->msgtql = min_t(int,
-		                     percpu_counter_sum(&ns->percpu_msg_bytes),
+		msginfo->msgtql = min(percpu_counter_sum(&ns->percpu_msg_bytes),
 				     INT_MAX);
 	} else {
 		msginfo->msgmap = MSGMAP;
_

Patches currently in -mm which might be from david.laight.linux@gmail.com are

ipc-msg-fix-saturation-of-percpu-counts-in-msgctl_info.patch


                 reply	other threads:[~2026-10-29  1:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261029011509.6005D1F01825@smtp.kernel.org \
    --to=akpm@linux-foundation.org \
    --cc=dave@stgolabs.net \
    --cc=david.laight.linux@gmail.com \
    --cc=manfred@colorfullife.com \
    --cc=mm-commits@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox