mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Lan Tianyu <tianyu.lan@intel.com>
Cc: rkrcmar@redhat.com, kvm@vger.kernel.org, dvyukov@google.com,
	linux-kernel@vger.kernel.org, david@redhat.com
Subject: Re: [PATCH V2] KVM/Eventfd: Avoid crash when assign and deassign specific eventfd in parallel.
Date: Sun, 15 Jul 2018 18:10:40 +0200	[thread overview]
Message-ID: <6b0960ed-8bc3-51a4-6053-882630e3bb4b@redhat.com> (raw)
In-Reply-To: <20171222021036.13107-1-tianyu.lan@intel.com>

On 22/12/2017 03:10, Lan Tianyu wrote:
> Syzroot reports crash in kvm_irqfd_assign() is caused by use-after-free.
> Because kvm_irqfd_assign() and kvm_irqfd_deassign() can't run in parallel
> for one specific eventfd. When assign path hasn't been finished after irqfd
> has been added to kvm->irqfds.items list, another thead may deassign the
> eventfd and free struct kvm_kernel_irqfd(). This causes assign path still
> uses struct kvm_kernel_irqfd freed by deassign path. To avoid such issue,
> make irqfd's reference under kvm->irq_srcu protection after irqfd added to
> kvm->irqfds.iterms list and call synchronize_srcu() in irq_shutdown() to
> make sure that irqfd has been fully initialized in the assign path.
> 
> Reported-by: Dmitry Vyukov <dvyukov@google.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Signed-off-by: Tianyu Lan <tianyu.lan@intel.com>
> ---
>  virt/kvm/eventfd.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
> index a334399fafec..0abc2e9ddafb 100644
> --- a/virt/kvm/eventfd.c
> +++ b/virt/kvm/eventfd.c
> @@ -119,8 +119,12 @@ irqfd_shutdown(struct work_struct *work)
>  {
>  	struct kvm_kernel_irqfd *irqfd =
>  		container_of(work, struct kvm_kernel_irqfd, shutdown);
> +	struct kvm *kvm = irqfd->kvm;
>  	u64 cnt;
>  
> +	/* Make sure irqfd has been initalized in assign path. */
> +	synchronize_srcu(&kvm->irq_srcu);
> +
>  	/*
>  	 * Synchronize with the wait-queue and unhook ourselves to prevent
>  	 * further events.
> @@ -387,7 +391,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
>  
>  	idx = srcu_read_lock(&kvm->irq_srcu);
>  	irqfd_update(kvm, irqfd);
> -	srcu_read_unlock(&kvm->irq_srcu, idx);
>  
>  	list_add_tail(&irqfd->list, &kvm->irqfds.items);
>  
> @@ -421,6 +424,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
>  	}
>  #endif
>  
> +	srcu_read_unlock(&kvm->irq_srcu, idx);
>  	return 0;
>  
>  fail:
> 

Queued, at last.  Thanks,

Paolo

      reply	other threads:[~2018-07-15 16:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-22  2:10 Lan Tianyu
2018-07-15 16:10 ` Paolo Bonzini [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=6b0960ed-8bc3-51a4-6053-882630e3bb4b@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=david@redhat.com \
    --cc=dvyukov@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rkrcmar@redhat.com \
    --cc=tianyu.lan@intel.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

all inboxes | Powered by JetHome®