Re: [PATCH 04/32] mm/shmem: fix commit limit bypass with very large shmem sizes
From: Gregory Price (Meta)
Date: Mon Nov 30 2026 - 17:39:29 EST
On 2026-11-29 11:06 +0100, 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>
reproduced with overcommit_memory=2 and some crafted shmget()'s
Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
--
~Gregory