]> www.infradead.org Git - users/jedix/linux-maple.git/commit
mm: fix use-after-free if memory allocation failed in vma_adjust()
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Thu, 28 Jul 2016 22:49:01 +0000 (15:49 -0700)
committerShan Hai <shan.hai@oracle.com>
Fri, 14 Jul 2017 07:42:36 +0000 (15:42 +0800)
commit8b5ec4c9c4eec5dcece9830dc6b7f0efe6f487a3
tree12a648da0f0476c7dba66b50d55e8aa19f282a30
parentbc32adfba1b71faa9a018757f0d537d7081f1850
mm: fix use-after-free if memory allocation failed in vma_adjust()

There's one case when vma_adjust() expands the vma, overlapping with
*two* next vma.  See case 6 of mprotect, described in the comment to
vma_merge().

To handle this (and only this) situation we iterate twice over main part
of the function.  See "goto again".

Vegard reported[1] that he sees out-of-bounds access complain from
KASAN, if anon_vma_clone() on the *second* iteration fails.

This happens because we free 'next' vma by the end of first iteration
and don't have a way to undo this if anon_vma_clone() fails on the
second iteration.

The solution is to do all required allocations upfront, before we touch
vmas.

The allocation on the second iteration is only required if first two
vmas don't have anon_vma, but third does.  So we need, in total, one
anon_vma_clone() call.

It's easy to adjust 'exporter' to the third vma for such case.

[1] http://lkml.kernel.org/r/1469514843-23778-1-git-send-email-vegard.nossum@oracle.com

Link: http://lkml.kernel.org/r/1469625255-126641-1-git-send-email-kirill.shutemov@linux.intel.com
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Orabug: 26441514

(cherry picked from commit 734537c9cb725fc8005ee7a25c48f1ad10fce5df)
Signed-off-by: Shan Hai <shan.hai@oracle.com>
Reviewed-by: Somasundaram Krishnasamy <somasundaram.krishnasamy@oracle.com>
mm/mmap.c