From: Wang Yingjie <x-professor@outlook.com>
To: Alexey Gladkov <legion@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
"Eric W. Biederman" <ebiederm@xmission.com>
Cc: Manfred Spraul <manfred@colorfullife.com>,
Vasily Averin <vasily.averin@linux.dev>,
Johannes Weiner <hannes@cmpxchg.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>
Subject: [PATCH] ipc/sem: account enlarged sops arrays to memcg
Date: Fri, 16 Oct 2026 15:26:11 +0000 [thread overview]
Message-ID: <20261016152609.2528805-1-x-professor@outlook.com> (raw)
Commit 50ec499b9a43 ("sysctl: allow change system v ipc sysctls
inside ipc namespace") lets an IPC namespace owner change kernel.sem.
The SEMOPM field defaults to 500 but has no semantic range check.
do_semtimedop() allocates nsops * sizeof(struct sembuf) with
GFP_KERNEL. A blocking operation retains that buffer, so a user can
raise SEMOPM and hold large attacker-selected amounts of host kernel
memory without charging the calling task memcg.
On the current mainline base, one 10,000,000-operation call retained
60,936,448 bytes while a 32 MiB cgroup peaked at 909,312 bytes and
reported no limit event. Sixteen 1,000,000-operation calls retained
100,860,416 bytes while the cgroup peaked at 1,310,720 bytes.
Commit 6a4746ba0619 ("ipc: remove memcg accounting for sops objects in
do_semtimedop()") removed accounting on the premise that the buffer was
at most two pages. Preserve that default-sized path, but account arrays
larger than the default SEMOPM value.
With this change, both test configurations reach the 32 MiB cgroup
limit and the caller is terminated by the memcg OOM killer before it
can retain the enlarged arrays.
The sysctl also accepts negative SEMOPM values. Since nsops is unsigned,
SEMOPM=-1 bypasses the intended operation-count check. This change still
accounts any admitted array larger than the default, while leaving
SEMOPM range policy for separate review.
Fixes: 50ec499b9a43 ("sysctl: allow change system v ipc sysctls inside ipc namespace")
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
ipc/sem.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/ipc/sem.c b/ipc/sem.c
index 5ec41de7e85b2b..8c9edecc160763 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -2234,7 +2234,9 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops,
return -EINVAL;
if (nsops > SEMOPM_FAST) {
- sops = kvmalloc_objs(*sops, nsops);
+ gfp_t gfp = nsops > SEMOPM ? GFP_KERNEL_ACCOUNT : GFP_KERNEL;
+
+ sops = kvmalloc_objs(*sops, nsops, gfp);
if (sops == NULL)
return -ENOMEM;
}
base-commit: 2f2f7eeef8b0a1a9b9ca998231419873ccae8d4e
--
2.43.0
next reply other threads:[~2026-10-16 15:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 15:26 Wang Yingjie [this message]
2026-10-16 22:59 ` Andrew Morton
2026-10-18 10:46 ` Manfred Spraul
2026-10-18 14:02 ` Wang Yingjie
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=20261016152609.2528805-1-x-professor@outlook.com \
--to=x-professor@outlook.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=ebiederm@xmission.com \
--cc=hannes@cmpxchg.org \
--cc=legion@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=manfred@colorfullife.com \
--cc=vasily.averin@linux.dev \
/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
all inboxes | Powered by JetHome®