Re: [PATCH 06/32] mm/shmem: seal the size of SysV and shared anon files

From: Gregory Price (Meta)

Date: Mon Nov 30 2026 - 17:42:04 EST


On 2026-11-29 11:06 +0100, David Hildenbrand (Arm) wrote:
> A process can resize the underlying shmem file of a SysV shm segment or of
> a shared anonymous mapping through /proc/<pid>/map_files.
>
> We account these files by their size when creating them and unaccount
> them by their size when destroying them, so resizing them can underflow
> vm_committed_as and the RLIMIT_MEMLOCK count of SHM_LOCK, and add pages
> that are charged to neither.
>
> Consequently, an underflowed vm_committed_as lets the whole system commit
> memory beyond the limit of vm.overcommit_memory=2, and the RLIMIT_MEMLOCK
> underflow triggers a WARN_ON_ONCE().
>
> Since commit 77142517990f ("shmem: update memory reservation on truncate")
> we adjust the commit charge on truncation, but not when writing or
> fallocating beyond EOF, and we never adjust the RLIMIT_MEMLOCK count.
>
> Let's fix it by sealing these files against growing and shrinking when
> creating them instead, similar to what is being done for SysV segments on
> hugetlbfs [1].
>
> Truncating such files and writing or fallocating to them beyond EOF will
> now fail with EPERM, and F_GET_SEALS will now report these two seals.
> As udmabuf requires F_SEAL_SHRINK, it will now accept these files, which
> shouldn't matter, as obtaining an fd for them requires
> CAP_CHECKPOINT_RESTORE.
>
> It's highly unlikely that any user would rely on this: e.g., CRIU only
> maps and reads these files through /proc/<pid>/map_files, and only
> resizes memfds. A search didn't reveal any other relevant cases.
>
> This has low urgency, as it requires CAP_CHECKPOINT_RESTORE.
>
> [1] https://lore.kernel.org/all/20261125-hugetlb_fixes_2-v1-17-db27fd2f71a8@xxxxxxxxxx/
>
> Fixes: 640708a2cff7 ("procfs: introduce the /proc/<pid>/map_files/ directory")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Chris Mason <mason@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

reproduced the wrong seal reporting and that previously successful
operations now fail with EPERM

Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>

--
~Gregory