Skip to content

Commit dcf7726

Browse files
Kalesh SinghTreehugger Robot
authored andcommitted
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 <[email protected]>
1 parent 7772260 commit dcf7726

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

fs/userfaultfd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/ioctl.h>
3030
#include <linux/security.h>
3131
#include <linux/hugetlb.h>
32+
#include <linux/pgsize_migration.h>
3233

3334
int sysctl_unprivileged_userfaultfd __read_mostly;
3435

@@ -1510,7 +1511,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
15101511
* the next vma was merged into the current one and
15111512
* the current one has not been updated yet.
15121513
*/
1513-
vma->vm_flags = new_flags;
1514+
vma->vm_flags = vma_pad_fixup_flags(vma, new_flags);
15141515
rcu_assign_pointer(vma->vm_userfaultfd_ctx.ctx, ctx);
15151516

15161517
if (is_vm_hugetlb_page(vma) && uffd_disable_huge_pmd_share(vma))
@@ -1690,7 +1691,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
16901691
* the next vma was merged into the current one and
16911692
* the current one has not been updated yet.
16921693
*/
1693-
vma->vm_flags = new_flags;
1694+
vma->vm_flags = vma_pad_fixup_flags(vma, new_flags);
16941695
rcu_assign_pointer(vma->vm_userfaultfd_ctx.ctx, NULL);
16951696

16961697
skip:

mm/madvise.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static int madvise_update_vma(struct vm_area_struct *vma,
182182
/*
183183
* vm_flags is protected by the mmap_lock held in write mode.
184184
*/
185-
vma->vm_flags = new_flags;
185+
vma->vm_flags = vma_pad_fixup_flags(vma, new_flags);
186186
if (!vma->vm_file) {
187187
error = replace_anon_vma_name(vma, anon_name);
188188
if (error)

0 commit comments

Comments
 (0)