Linux userland API discussions
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Yingjie Wang <x-professor@outlook.com>
Cc: "Manfred Spraul" <manfred@colorfullife.com>,
	"Alexey Gladkov" <legion@kernel.org>,
	"Eric W . Biederman" <ebiederm@xmission.com>,
	"Vasily Averin" <vasily.averin@linux.dev>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Shakeel Butt" <shakeel.butt@linux.dev>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Michal Hocko" <mhocko@suse.com>,
	"Alejandro Colomar" <alx@kernel.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>,
	"linux-api@vger.kernel.org" <linux-api@vger.kernel.org>,
	"linux-man@vger.kernel.org" <linux-man@vger.kernel.org>,
	"linux-hardening@vger.kernel.org"
	<linux-hardening@vger.kernel.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>
Subject: Re: [PATCH v5 0/3] ipc/sem: account dynamic sops arrays and validate SEMOPM
Date: Sun, 15 Nov 2026 14:12:06 -0800	[thread overview]
Message-ID: <20261115141206.920bdc8c5a84073712bb5c3b@linux-foundation.org> (raw)
In-Reply-To: <cover.1793250194.git.x-professor@outlook.com>

On Thu, 29 Oct 2026 05:03:24 +0000 Yingjie Wang <x-professor@outlook.com> wrote:

> Shakeel, thanks for the suggestion.

Thanks.  Shakeel, please review [1/3]?

> Patch 1 now uses GFP_KERNEL_ACCOUNT for every dynamically allocated sops
> array. The first 64 operations still use the existing stack buffer. The
> fixed 1000-operation exemption and its conditional allocation flags have
> been removed.
> 
> I compared this version with v4 in a 4-vCPU KVM guest. The benchmark process
> was pinned to one vCPU. Each number is the median of 21 samples from three
> fresh boots of each kernel. In a leaf memory cgroup, the changes were:
> 
>                                       65       500      1000
>   successful semop()                   +3.2%     +3.2%     +2.3%
>   allocation-focused invalid semid     +5.6%     +9.1%    +11.9%
> 
> The invalid-sem-id case allocates and copies the operation array before
> returning EINVAL, so it emphasizes allocation overhead. The 64-operation
> stack controls changed by 0.9% and 0.5%, respectively. The already-accounted
> 1001-operation controls changed by 1.0% and -0.2%. Successful calls in the
> root cgroup changed by at most 2.3%, including the controls.
> 
> The sysctl handler parses writes into a temporary array while holding a
> per-IPC-namespace mutex. The mutex covers the snapshot, validation, and
> publication, so a failed write leaves the live settings unchanged and a
> partial write cannot restore fields from an older snapshot. The snapshot and
> publication use READ_ONCE() and WRITE_ONCE(), and reads continue through
> proc_dointvec(). The unused sem_check_semmni() helper is also removed.
> 
> The UAPI warning about physical fragmentation is obsolete now that the
> operation array uses kvmalloc(). The header describes SEMOPM as the
> compiled-in default and retains the uniform <= INT_MAX range comment.
> 
> Patches 2 and 3 are unchanged from v4 and retain Manfred's Reviewed-by tags.
> The series is based on 7be4bc52fd9e ("Merge tag 'driver-core-7.4-rc1' of
> git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core").

Thing is, the above is largely about what-changed-since-last-time. 
It's useful info, but it's short-term development-time stuff.  Most of
this is inappropriate for the long-term kernel record.

I had LLM suggest a replacement [0/N].  wdyt?

: An IPC namespace owner can raise SEMOPM and make semop() allocate a large
: operation array.  A blocked call retains the array.  These allocations are
: currently uncharged to the caller's memory cgroup, so repeated calls can
: consume host memory beyond a container's limit.  In one test, a call
: retained 60,936,448 bytes while a 32 MiB cgroup recorded less than 1 MiB. 
: Sixteen concurrent calls retained 100,860,416 bytes while the cgroup
: recorded about 1.3 MiB.
: 
: The SEMOPM sysctl also accepts negative values.  Because the operation
: count is unsigned, SEMOPM=-1 becomes an effective limit of UINT_MAX. 
: Separately, a rejected kernel.sem write can leave earlier fields changed:
: an invalid SEMMNI can return ERANGE after setting SEMOPM to zero, causing
: subsequent nonempty semop() calls in that IPC namespace to fail with
: E2BIG.
: 
: Patch 1 charges dynamically allocated operation arrays in the regular
: semop() path to the caller's memory cgroup.  Patch 2 parses and validates
: kernel.sem writes before publishing them and serializes writers within
: each IPC namespace.  Patch 3 removes the obsolete warning that SEMOPM
: above 1000 risks physical memory fragmentation; the operation array uses
: kvmalloc().
: 
: Accounting contains the large-array case when the caller's memory cgroup
: has an effective limit.  The series does not impose a maximum on positive
: SEMOPM values, so a root or unlimited cgroup can still request large
: allocations.
: 
: Validation included x86-64 and i386 builds, initial and user-owned IPC
: namespace checks, concurrent sysctl writes, operation-count boundaries,
: and allocation cleanup on success and error paths.  In a limited memory
: cgroup, accounting increased median successful-call time by 2.3% to 3.2%
: for 65, 500 and 1000 operations; the allocation-focused invalid semaphore
: ID case increased by 5.6% to 11.9%.

Also, [1/3] and [2/3] are cc:stable but include no clear description of
why we're recommending backports.  Backportable patches should clearly
state the userspace-visible runtime effects of the bug which is being
fixed.  Our downstream people (-stable maintainers and further
downstream) are swamped with bugfixes, so let's help them out!

So for [1/3] I inserted this statement:

: A caller can raise SEMOPM and keep large, uncharged operation arrays alive
: in blocked semop() calls.  Repeating this from a memory-limited cgroup can
: exhaust host memory outside that cgroup, causing reclaim, stalls, or OOM
: kills of unrelated processes.  Charging the arrays lets an effective memcg
: limit contain that memory use.

and for [2/3] I inserted

: A negative SEMOPM becomes a large unsigned limit in semop(), allowing
: operation counts that the configured limit should reject.  Separately, a
: kernel.sem write can return ERANGE for an invalid SEMMNI while leaving
: earlier fields changed; if it leaves SEMOPM at zero, subsequent nonempty
: semop() calls in that IPC namespace fail with E2BIG.  Validate the whole
: write before changing the live settings.

Please check these also.


  parent reply	other threads:[~2026-11-15 22:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29  5:03 [PATCH v5 0/3] ipc/sem: account dynamic sops arrays and validate SEMOPM Yingjie Wang
2026-10-29  5:03 ` [PATCH v5 1/3] ipc/sem: account dynamically allocated sops arrays to memcg Yingjie Wang
2026-11-16  4:19   ` Shakeel Butt
2026-10-29  5:03 ` [PATCH v5 2/3] ipc/sem: reject negative SEMOPM values Yingjie Wang
2026-10-29  5:03 ` [PATCH v5 3/3] ipc/sem: remove obsolete SEMOPM fragmentation warning Yingjie Wang
2026-11-15 22:12 ` Andrew Morton [this message]
2026-11-16  4:13   ` [PATCH v5 0/3] ipc/sem: account dynamic sops arrays and validate SEMOPM Shakeel Butt

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=20261115141206.920bdc8c5a84073712bb5c3b@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=alx@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=dave@stgolabs.net \
    --cc=ebiederm@xmission.com \
    --cc=hannes@cmpxchg.org \
    --cc=legion@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=manfred@colorfullife.com \
    --cc=mhocko@suse.com \
    --cc=mkoutny@suse.com \
    --cc=shakeel.butt@linux.dev \
    --cc=vasily.averin@linux.dev \
    --cc=x-professor@outlook.com \
    /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