stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: dvyukov@google.com, stable@vger.kernel.org
Subject: Re: [PATCH] KVM: irqfd: fix race between EPOLLHUP and irq_bypass_register_consumer
Date: Mon, 28 May 2018 20:21:44 +0200	[thread overview]
Message-ID: <0014b068-897d-bcb4-beb2-e5b2a5d2219b@redhat.com> (raw)
In-Reply-To: <20180528113113.30941-1-pbonzini@redhat.com>

On 28.05.2018 13:31, Paolo Bonzini wrote:
> A comment warning against this bug is there, but the code is not doing what
> the comment says.  Therefore it is possible that an EPOLLHUP races against
> irq_bypass_register_consumer.  The EPOLLHUP handler schedules irqfd_shutdown,
> and if that runs soon enough, you get a use-after-free.
> 
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  virt/kvm/eventfd.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
> index 6e865e8b5b10..44dda5dad0ee 100644
> --- a/virt/kvm/eventfd.c
> +++ b/virt/kvm/eventfd.c
> @@ -402,11 +402,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
>  	if (events & EPOLLIN)
>  		schedule_work(&irqfd->inject);
>  
> -	/*
> -	 * do not drop the file until the irqfd is fully initialized, otherwise
> -	 * we might race against the EPOLLHUP
> -	 */
> -	fdput(f);
>  #ifdef CONFIG_HAVE_KVM_IRQ_BYPASS
>  	if (kvm_arch_has_irq_bypass()) {
>  		irqfd->consumer.token = (void *)irqfd->eventfd;
> @@ -421,6 +416,11 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
>  	}
>  #endif
>  
> +	/*
> +	 * do not drop the file until the irqfd is fully initialized, otherwise
> +	 * we might race against the EPOLLHUP
> +	 */
> +	fdput(f);
>  	return 0;
>  
>  fail:
> 

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 

Thanks,

David / dhildenb

      reply	other threads:[~2018-05-28 18:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-28 11:31 [PATCH] KVM: irqfd: fix race between EPOLLHUP and irq_bypass_register_consumer Paolo Bonzini
2018-05-28 18:21 ` David Hildenbrand [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=0014b068-897d-bcb4-beb2-e5b2a5d2219b@redhat.com \
    --to=david@redhat.com \
    --cc=dvyukov@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=stable@vger.kernel.org \
    /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).