[Devel] [PATCH hci-8.1 0/7] mm, exec: fix the MADV_DOEXEC code we carry from Oracle
Konstantin Khorenko
khorenko at virtuozzo.com
Wed Oct 14 20:12:19 MSK 2026
Fixes in the existing Oracle MADV_DOEXEC code, found while working on
VSTOR-149847, and a refusal of preserved memory across setuid exec.
Applies on top of "mm: keep DMA-pinned MADV_DOEXEC memory working across
exec".
- 1: vma_dup() takes no file reference for a file-backed VMA, so a
private /dev/zero mapping marked MADV_DOEXEC is put twice
(use-after-free of struct file, reachable unprivileged).
- 2: a private VM_PFNMAP VMA with NULL vm_ops passed as anonymous and
its PAT memtype was freed twice; refuse VM_SPECIAL.
- 3: MADV_DOEXEC never cleared VM_MAYEXEC and MADV_DONTEXEC granted it
unconditionally, also on noexec mounts; the copies made by exec and
fork get back what do_mmap() granted.
- 4: load_elf_binary() looked for the opt-in note only in the last
PT_NOTE segment; a binary whose linker puts it elsewhere silently got
no preserved memory.
- 5: a setuid/secureexec exec with preserved memory is refused with
EPERM before the point of no return: long-term pins driven from
another process would keep writing into the privileged image.
- 6, 7: selftests for 5 and for 1 and 3.
Tested with the whole stack on release and debug kernels (MADV_DOEXEC
selftests, gup_test, a Container start/exec/stop).
https://virtuozzo.atlassian.net/browse/VSTOR-150232
---
Konstantin Khorenko (7):
oracle/mm: take a file reference when preserving a file-backed VMA
oracle/mm: refuse MADV_DOEXEC on special mappings
oracle/mm: keep a MADV_DOEXEC range from becoming executable
oracle/exec, elf: look for the opt-in note in every PT_NOTE segment
exec: refuse to preserve memory across a privilege-changing exec
selftests/mm: check that a setuid exec refuses preserved memory
selftests/mm: check MADV_DOEXEC on /dev/zero and exec permission
fs/binfmt_elf.c | 87 +++++++++------
fs/exec.c | 4 +
include/linux/mm.h | 1 +
kernel/fork.c | 4 +-
mm/madvise.c | 12 +-
mm/mmap.c | 17 ++-
tools/testing/selftests/mm/doexec.c | 211 +++++++++++++++++++++++++++++++++++-
7 files changed, 290 insertions(+), 46 deletions(-)
---
base-commit: 0f7fa776e32c8e6832e7604dc157d05d3af14513
change-id: 20261014-b4-prep-khorenko-vstor-149847-3-doexec-oracle-fixes-33341d1abc4d
Best regards,
--
Konstantin Khorenko <khorenko at virtuozzo.com>
More information about the Devel
mailing list