From 171355878e09938c06396498f584662e3eddcdbc Mon Sep 17 00:00:00 2001 From: Kalesh Singh Date: Mon, 23 Sep 2024 22:26:26 +0000 Subject: [PATCH] ANDROID: 16K: Fixup padding vm_flags bits on VMA splits In some cases VMAs are split without the mmap write lock held; later the lock is taken to fixup vm_flags of the original VMA. Since some uppper bits of vm_flags are used to encode the ELF padding ranges, they need to be modified on splits. This is usually handled correctly by __split_vma(). However in the above case, the flags get over witten later under the write lock. Preserve vm_flag bits on reset to correctly represent padding. Bug: 357901498 Change-Id: I1cb75419e614791a47cbdb0341373f619daf0bf2 Signed-off-by: Kalesh Singh --- fs/userfaultfd.c | 5 +++-- mm/madvise.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 830f620f9ad2..ce0e23398482 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -27,6 +27,7 @@ #include #include #include +#include int sysctl_unprivileged_userfaultfd __read_mostly = 1; @@ -1480,7 +1481,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, * the next vma was merged into the current one and * the current one has not been updated yet. */ - vma->vm_flags = new_flags; + vma->vm_flags = vma_pad_fixup_flags(vma, new_flags); vma->vm_userfaultfd_ctx.ctx = ctx; skip: @@ -1643,7 +1644,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, * the next vma was merged into the current one and * the current one has not been updated yet. */ - vma->vm_flags = new_flags; + vma->vm_flags = vma_pad_fixup_flags(vma, new_flags); vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX; skip: diff --git a/mm/madvise.c b/mm/madvise.c index ed1fffbe6f03..890630a670e4 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -167,7 +167,7 @@ success: /* * vm_flags is protected by the mmap_sem held in write mode. */ - vma->vm_flags = new_flags; + vma->vm_flags = vma_pad_fixup_flags(vma, new_flags); out_convert_errno: /*