]> git.baikalelectronics.ru Git - kernel.git/commit
mmap: fix do_brk_flags() modifying obviously incorrect VMAs
authorLiam Howlett <liam.howlett@oracle.com>
Mon, 5 Dec 2022 19:23:17 +0000 (19:23 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 10 Dec 2022 02:41:16 +0000 (18:41 -0800)
commitc9d73a6a1bf574f63ed5b82a6eb7945729e9f4c4
tree4567c31ca848afd48fa30d897c6f7ed68a76dec7
parente8d997be31b84c0dab4ff50a877065eb383da9be
mmap: fix do_brk_flags() modifying obviously incorrect VMAs

Add more sanity checks to the VMA that do_brk_flags() will expand.  Ensure
the VMA matches basic merge requirements within the function before
calling can_vma_merge_after().

Drop the duplicate checks from vm_brk_flags() since they will be enforced
later.

The old code would expand file VMAs on brk(), which is functionally
wrong and also dangerous in terms of locking because the brk() path
isn't designed for file VMAs and therefore doesn't lock the file
mapping.  Checking can_vma_merge_after() ensures that new anonymous
VMAs can't be merged into file VMAs.

See https://lore.kernel.org/linux-mm/CAG48ez1tJZTOjS_FjRZhvtDA-STFmdw8PEizPDwMGFd_ui0Nrw@mail.gmail.com/

Link: https://lkml.kernel.org/r/20221205192304.1957418-1-Liam.Howlett@oracle.com
Fixes: 592c227c3647 ("mm/mmap: change do_brk_flags() to expand existing VMA and add do_brk_munmap()")
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Suggested-by: Jann Horn <jannh@google.com>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: SeongJae Park <sj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mmap.c