linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vegard Nossum <vegard.nossum@oracle.com>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: linux-mm@kvack.org, Vlastimil Babka <vbabka@suse.cz>,
	Leon Yu <chianglungyu@gmail.com>,
	Konstantin Khlebnikov <koct9i@gmail.com>,
	Rik van Riel <riel@redhat.com>,
	Daniel Forrest <dan.forrest@ssec.wisc.edu>
Subject: Re: [PATCH] mm: correctly handle errors during VMA merging
Date: Wed, 27 Jul 2016 07:40:02 +0200	[thread overview]
Message-ID: <57984932.4010803@oracle.com> (raw)
In-Reply-To: <20160726203053.GD11776@node.shutemov.name>

On 07/26/2016 10:30 PM, Kirill A. Shutemov wrote:
> On Tue, Jul 26, 2016 at 10:19:48PM +0200, Vegard Nossum wrote:
>> On 07/26/2016 01:48 PM, Kirill A. Shutemov wrote:
>>> On Tue, Jul 26, 2016 at 08:34:03AM +0200, Vegard Nossum wrote:
>>>> Using trinity + fault injection I've been running into this bug a lot:
>>>>
>>>>      ==================================================================
>>>>      BUG: KASAN: out-of-bounds in mprotect_fixup+0x523/0x5a0 at addr ffff8800b9e7d740
>>
>> [...]
>>
>>>> What's happening is that we're doing an mprotect() on a range that spans
>>>> three existing adjacent mappings. The first two are merged fine, but if
>>>> we merge the last one and anon_vma_clone() runs out of memory, we return
>>>> an error and mprotect_fixup() tries to use the (now stale) pointer. It
>>>> goes like this:
>>>>
>>>>      SyS_mprotect()
>>>>        - mprotect_fixup()
>>>>           - vma_merge()
>>>>              - vma_adjust()
>>>>                 // first merge
>>>>                 - kmem_cache_free(vma)
>>>>                 - goto again;
>>>>                 // second merge
>>>>                 - anon_vma_clone()
>>>>                    - kmem_cache_alloc()
>>>>                       - return NULL
>>>>                    - kmem_cache_alloc()
>>>>                       - return NULL
>>>>                    - return -ENOMEM
>>>>                 - return -ENOMEM
>>>>              - return NULL
>>>>           - vma->vm_start // use-after-free
>>>>
>>>> In other words, it is possible to run into a memory allocation error
>>>> *after* part of the merging work has already been done. In this case,
>>>> we probably shouldn't return an error back to userspace anyway (since
>>>> it would not reflect the partial work that was done).
>>>>
>>>> I *think* the solution might be to simply ignore the errors from
>>>> vma_adjust() and carry on with distinct VMAs for adjacent regions that
>>>> might otherwise have been represented with a single VMA.
>>>>
>>>> I have a reproducer that runs into the bug within a few seconds when
>>>> fault injection is enabled -- with the patch I no longer see any
>>>> problems.
>>>>
>>>> The patch and resulting code admittedly look odd and I'm *far* from
>>>> an expert on mm internals, so feel free to propose counter-patches and
>>>> I can give the reproducer a spin.
>>>
>>> Could you give this a try (barely tested):
>>
>> No apparent problems using either the quick reproducer or trinity (used
>> to take 1-5 hours) after ~8 hours of testing :-)
>
> Good. I'll prepare proper patch tomorrow.
>
> I assume I can use your Tested-by, right?

Tested-by: Vegard Nossum <vegard.nossum@oracle.com>

Feel free to reuse any or all parts of the commit message I wrote for my
patch.

Thanks!


Vegard

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

      reply	other threads:[~2016-07-27  5:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-26  6:34 [PATCH] mm: correctly handle errors during VMA merging Vegard Nossum
2016-07-26  7:03 ` Vlastimil Babka
2016-07-26  8:53 ` Kirill A. Shutemov
2016-07-26  9:00   ` Vlastimil Babka
2016-07-26  9:24   ` Vegard Nossum
2016-07-26 10:54     ` Kirill A. Shutemov
2016-07-26 11:48 ` Kirill A. Shutemov
2016-07-26 20:19   ` Vegard Nossum
2016-07-26 20:30     ` Kirill A. Shutemov
2016-07-27  5:40       ` Vegard Nossum [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57984932.4010803@oracle.com \
    --to=vegard.nossum@oracle.com \
    --cc=chianglungyu@gmail.com \
    --cc=dan.forrest@ssec.wisc.edu \
    --cc=kirill@shutemov.name \
    --cc=koct9i@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=riel@redhat.com \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).