linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Radim Krčmář" <rkrcmar@redhat.com>,
	"Eric Biggers" <ebiggers3@gmail.com>
Cc: kvm@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com,
	Eric Biggers <ebiggers@google.com>
Subject: Re: [PATCH] KVM/x86: remove WARN_ON() for when vm_munmap() fails
Date: Thu, 1 Feb 2018 12:12:00 -0500	[thread overview]
Message-ID: <584ef475-21cc-9ef5-8ac9-d6b00e93134e@redhat.com> (raw)
In-Reply-To: <20180201153310.GD31080@flask>

On 01/02/2018 10:33, Radim Krčmář wrote:
> 2018-01-31 17:30-0800, Eric Biggers:
>> From: Eric Biggers <ebiggers@google.com>
>>
>> On x86, special KVM memslots such as the TSS region have anonymous
>> memory mappings created on behalf of userspace, and these mappings are
>> removed when the VM is destroyed.
>>
>> It is however possible for removing these mappings via vm_munmap() to
>> fail.  This can most easily happen if the thread receives SIGKILL while
>> it's waiting to acquire ->mmap_sem.   This triggers the 'WARN_ON(r < 0)'
>> in __x86_set_memory_region().  syzkaller was able to hit this, using
>> 'exit()' to send the SIGKILL.  Note that while the vm_munmap() failure
>> results in the mapping not being removed immediately, it is not leaked
>> forever but rather will be freed when the process exits.
>>
>> It's not really possible to handle this failure properly, so almost
> 
> We could check "r < 0 && r != -EINTR" to get rid of the easily
> triggerable warning.

Considering that vm_munmap uses down_write_killable, that would be
preferrable I think.

Paolo

>> every other caller of vm_munmap() doesn't check the return value.  It's
>> a limitation of having the kernel manage these mappings rather than
>> userspace.
>>
>> So just remove the WARN_ON() so that users can't spam the kernel log
>> with this warning.
>>
>> Fixes: f0d648bdf0a5 ("KVM: x86: map/unmap private slots in __x86_set_memory_region")
>> Reported-by: syzbot <syzkaller@googlegroups.com>
>> Signed-off-by: Eric Biggers <ebiggers@google.com>
>> ---
> 
> Removing it altogether doesn't sound that bad, though ...
> Queued, thanks.
> 
>>  arch/x86/kvm/x86.c | 6 ++----
>>  1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index c53298dfbf50..53b57f18baec 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -8272,10 +8272,8 @@ int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
>>  			return r;
>>  	}
>>  
>> -	if (!size) {
>> -		r = vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE);
>> -		WARN_ON(r < 0);
>> -	}
>> +	if (!size)
>> +		vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE);
>>  
>>  	return 0;
>>  }
>> -- 
>> 2.16.0.rc1.238.g530d649a79-goog
>>

  reply	other threads:[~2018-02-01 17:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-31 13:14 WARNING in __x86_set_memory_region syzbot
2017-11-03 21:55 ` syzbot
2018-02-01  1:30   ` [PATCH] KVM/x86: remove WARN_ON() for when vm_munmap() fails Eric Biggers
2018-02-01 15:33     ` Radim Krčmář
2018-02-01 17:12       ` Paolo Bonzini [this message]
2018-02-01 20:07         ` Eric Biggers

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=584ef475-21cc-9ef5-8ac9-d6b00e93134e@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=ebiggers3@gmail.com \
    --cc=ebiggers@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rkrcmar@redhat.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /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).