freenode
Kernel & Low-Level

Kernel fixes close local memory corruption and unkillable hangs

Lorenzo Stoakes wants two VMA bugs treated as hotfixes after Chris Mason reported flaws that can corrupt memory, hang the machine, or drop data.

Linux memory management has a batch of user-triggerable bugs in how it places and moves virtual memory areas, including one that can corrupt memory for any local user and another that can hang the whole machine.

Lorenzo Stoakes of ARM posted the fixes, describing them as a rework of AI-generated VMA and mremap changes, and asked reviewers to check them carefully for correctness. He wants the first two treated as hotfixes. The rest, he wrote, can wait for 7.5. Chris Mason reported several of the flaws and wrote four of the patches. Suren Baghdasaryan has reviewed the set.

The worst case is in the top-down search for a free address range. An exclusive upper bound of zero is treated as a range that runs to the end of the address space, and the search can return a wrapped address that does not look like an error. On x86-64 that address can be used for an uprobe trampoline whose mapping ends at zero. When the process exits, the kernel then frees page tables shared by every address space. On powerpc64 with the hash MMU, the same bad address can be written past the end of a per-process context array. A plain mmap with no placement hint can also fail even when free space remains.

The second hotfix is a lock-order bug. Registering a memory-management notifier takes a mutex shared by every process, then waits for virtual-memory locks. Since shared faults were allowed to run under those locks, a fault can sleep with no bound, including inside a FUSE write that waits on a userspace server. A local user who can stall that server can leave notifier registration hung, and the wait cannot be killed. The fix takes the virtual-memory locks first and makes that wait interruptible by a fatal signal.

Three further bugs are marked for stable. Kernel same-page merging can abandon an unmerge on any pending signal and ask the caller to restart. That is unsafe for mremap, which drops its mapping lock on restart. Moving two mergeable areas with MREMAP_DONTUNMAP can then report success while the first area's data is gone. A failed execve stack relocation can also expand a stack mapping without a matching memory charge. On exit the kernel uncharges the larger size, so the strict overcommit accounting can go negative by as much as 16 GiB on 64-bit x86, or about 128 TiB for a 32-bit process. Separately, mremap could grow a file mapping past the offset mmap itself refuses, and a DAX fault handler can then overflow that offset and skip its file-size check.

Two smaller changes are hardening only: guard gaps on in-place mremap growth, and non-executable brk mappings when memory-deny-write-execute is in force. Stoakes set one related change aside for the BPF maintainers rather than altering core memory management for it.