diff options
author | Lorenzo Stoakes <lorenzo.stoakes@oracle.com> | 2024-12-06 21:52:29 +0000 |
---|---|---|
committer | Andrew Morton <akpm@linux-foundation.org> | 2024-12-18 19:04:42 -0800 |
commit | 42c4e4b20d9c4651903c4afc53a4ff18b7451b3e (patch) | |
tree | f082a9bd61542e14059ab30d12a59adbbcc20979 /mm | |
parent | f5d09de9f1bf9674c6418ff10d0a40cfe29268e1 (diff) | |
download | linux-stable-42c4e4b20d9c4651903c4afc53a4ff18b7451b3e.tar.gz linux-stable-42c4e4b20d9c4651903c4afc53a4ff18b7451b3e.tar.bz2 linux-stable-42c4e4b20d9c4651903c4afc53a4ff18b7451b3e.zip |
mm: correctly reference merged VMA
On second merge attempt on mmap() we incorrectly discard the possibly
merged VMA, resulting in a possible use-after-free (and most certainly a
reference to the wrong VMA) in this instance in the subsequent
__mmap_complete() invocation.
Correct this mistake by reassigning vma correctly if a merge succeeds in
this case.
Link: https://lkml.kernel.org/r/20241206215229.244413-1-lorenzo.stoakes@oracle.com
Fixes: 5ac87a885aec ("mm: defer second attempt at merge on mmap()")
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Suggested-by: Jann Horn <jannh@google.com>
Reported-by: syzbot+91cf8da9401355f946c3@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/67536a25.050a0220.a30f1.0149.GAE@google.com/
Reviewed-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/vma.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -2460,10 +2460,13 @@ unsigned long __mmap_region(struct file *file, unsigned long addr, /* If flags changed, we might be able to merge, so try again. */ if (map.retry_merge) { + struct vm_area_struct *merged; VMG_MMAP_STATE(vmg, &map, vma); vma_iter_config(map.vmi, map.addr, map.end); - vma_merge_existing_range(&vmg); + merged = vma_merge_existing_range(&vmg); + if (merged) + vma = merged; } __mmap_complete(&map, vma); |