Re: [PATCH 04/32] mm/shmem: fix commit limit bypass with very large shmem sizes
From: Baolin Wang
Date: Wed Dec 02 2026 - 03:32:15 EST
On 11/29/26 6:06 PM, David Hildenbrand (Arm) wrote:
VM_ACCT() uses PAGE_ALIGN() on a loff_t, a signed type, which overflows
for sizes in the last page up to LLONG_MAX (MAX_LFS_FILESIZE on 64-bit).
With the default shmmax and shmall, userspace can trigger this through
shmget(IPC_PRIVATE, LLONG_MAX, IPC_CREAT).
Consequently, the resulting negative count makes __vm_enough_memory()
succeed and lowers vm_committed_as such that it will go negative. This
effectively disables the commit limit with vm.overcommit_memory = 2 for
as long as the shmem file exists.
Let's fix it by avoiding PAGE_ALIGN() and just using DIV_ROUND_UP_POW2(),
which cannot overflow. We now reject such problematic sizes with ENOMEM,
like any other size above the limit.
On 32-bit, VM_ACCT() can still return numbers that don't fit into
the long that __vm_enough_memory() consumes. However, only ftruncate()
to 8 TiB or more, through an fd obtained via /proc/$PID/map_files for a
shared anonymous mapping, can trigger that, which requires CAP_SYS_ADMIN
or CAP_CHECKPOINT_RESTORE. So we'll leave that alone for now.
This has low urgency, as it only affects systems with
vm.overcommit_memory = 2.
Fixes: 09cbfeaf1a5a ("mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros")
Cc: stable@xxxxxxxxxxxxxxx
Reported-by: Chris Mason <mason@xxxxxxxxxx>
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
LGTM.
Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>