All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rjones@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: Laura Abbott <labbott@redhat.com>, Christoph Hellwig <hch@lst.de>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	virtualization@lists.linux-foundation.org,
	Thorsten Leemhuis <linux@leemhuis.info>
Subject: Re: [REGRESSION] 07ec51480b5e ("virtio_pci: use shared interrupts for virtqueues") causes crashes in guest
Date: Thu, 23 Mar 2017 15:19:07 +0000	[thread overview]
Message-ID: <20170323151906.GA19376@redhat.com> (raw)
In-Reply-To: <e042635f-e30e-45e8-f4a5-b03b9228eec2@redhat.com>

On Thu, Mar 23, 2017 at 01:13:50PM +0800, Jason Wang wrote:
> >From 312859b596e83a2164a8430343d31fce2a5ad808 Mon Sep 17 00:00:00 2001
> From: Jason Wang <jasowang@redhat.com>
> Date: Thu, 23 Mar 2017 13:07:16 +0800
> Subject: [PATCH] virtio_pci: fix out of bound access for msix_names
> 
> Signed-off-by: Jason Wang <jasowang@redhat.com>

I tested this, and it does appear to fix the crashes in
vp_modern_find_vqs.  Therefore:

Tested-by: Richard W.M. Jones <rjones@redhat.com>

Thanks,

Rich.

>  drivers/virtio/virtio_pci_common.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> index df548a6..5905349 100644
> --- a/drivers/virtio/virtio_pci_common.c
> +++ b/drivers/virtio/virtio_pci_common.c
> @@ -147,7 +147,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
>  {
>  	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
>  	const char *name = dev_name(&vp_dev->vdev.dev);
> -	int i, err = -ENOMEM, allocated_vectors, nvectors;
> +	int i, j, err = -ENOMEM, allocated_vectors, nvectors;
>  	unsigned flags = PCI_IRQ_MSIX;
>  	bool shared = false;
>  	u16 msix_vec;
> @@ -212,7 +212,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
>  	if (!vp_dev->msix_vector_map)
>  		goto out_disable_config_irq;
>  
> -	allocated_vectors = 1; /* vector 0 is the config interrupt */
> +	allocated_vectors = j = 1; /* vector 0 is the config interrupt */
>  	for (i = 0; i < nvqs; ++i) {
>  		if (!names[i]) {
>  			vqs[i] = NULL;
> @@ -236,18 +236,19 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
>  			continue;
>  		}
>  
> -		snprintf(vp_dev->msix_names[i + 1],
> +		snprintf(vp_dev->msix_names[j],
>  			 sizeof(*vp_dev->msix_names), "%s-%s",
>  			 dev_name(&vp_dev->vdev.dev), names[i]);
>  		err = request_irq(pci_irq_vector(vp_dev->pci_dev, msix_vec),
>  				  vring_interrupt, IRQF_SHARED,
> -				  vp_dev->msix_names[i + 1], vqs[i]);
> +				  vp_dev->msix_names[j], vqs[i]);
>  		if (err) {
>  			/* don't free this irq on error */
>  			vp_dev->msix_vector_map[i] = VIRTIO_MSI_NO_VECTOR;
>  			goto out_remove_vqs;
>  		}
>  		vp_dev->msix_vector_map[i] = msix_vec;
> +		j++;
>  
>  		/*
>  		 * Use a different vector for each queue if they are available,
> -- 
> 2.7.4
> 


-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html

WARNING: multiple messages have this Message-ID (diff)
From: "Richard W.M. Jones" <rjones@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Thorsten Leemhuis <linux@leemhuis.info>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Laura Abbott <labbott@redhat.com>,
	virtualization@lists.linux-foundation.org,
	Christoph Hellwig <hch@lst.de>
Subject: Re: [REGRESSION] 07ec51480b5e ("virtio_pci: use shared interrupts for virtqueues") causes crashes in guest
Date: Thu, 23 Mar 2017 15:19:07 +0000	[thread overview]
Message-ID: <20170323151906.GA19376@redhat.com> (raw)
In-Reply-To: <e042635f-e30e-45e8-f4a5-b03b9228eec2@redhat.com>

On Thu, Mar 23, 2017 at 01:13:50PM +0800, Jason Wang wrote:
> >From 312859b596e83a2164a8430343d31fce2a5ad808 Mon Sep 17 00:00:00 2001
> From: Jason Wang <jasowang@redhat.com>
> Date: Thu, 23 Mar 2017 13:07:16 +0800
> Subject: [PATCH] virtio_pci: fix out of bound access for msix_names
> 
> Signed-off-by: Jason Wang <jasowang@redhat.com>

I tested this, and it does appear to fix the crashes in
vp_modern_find_vqs.  Therefore:

Tested-by: Richard W.M. Jones <rjones@redhat.com>

Thanks,

Rich.

>  drivers/virtio/virtio_pci_common.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> index df548a6..5905349 100644
> --- a/drivers/virtio/virtio_pci_common.c
> +++ b/drivers/virtio/virtio_pci_common.c
> @@ -147,7 +147,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
>  {
>  	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
>  	const char *name = dev_name(&vp_dev->vdev.dev);
> -	int i, err = -ENOMEM, allocated_vectors, nvectors;
> +	int i, j, err = -ENOMEM, allocated_vectors, nvectors;
>  	unsigned flags = PCI_IRQ_MSIX;
>  	bool shared = false;
>  	u16 msix_vec;
> @@ -212,7 +212,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
>  	if (!vp_dev->msix_vector_map)
>  		goto out_disable_config_irq;
>  
> -	allocated_vectors = 1; /* vector 0 is the config interrupt */
> +	allocated_vectors = j = 1; /* vector 0 is the config interrupt */
>  	for (i = 0; i < nvqs; ++i) {
>  		if (!names[i]) {
>  			vqs[i] = NULL;
> @@ -236,18 +236,19 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
>  			continue;
>  		}
>  
> -		snprintf(vp_dev->msix_names[i + 1],
> +		snprintf(vp_dev->msix_names[j],
>  			 sizeof(*vp_dev->msix_names), "%s-%s",
>  			 dev_name(&vp_dev->vdev.dev), names[i]);
>  		err = request_irq(pci_irq_vector(vp_dev->pci_dev, msix_vec),
>  				  vring_interrupt, IRQF_SHARED,
> -				  vp_dev->msix_names[i + 1], vqs[i]);
> +				  vp_dev->msix_names[j], vqs[i]);
>  		if (err) {
>  			/* don't free this irq on error */
>  			vp_dev->msix_vector_map[i] = VIRTIO_MSI_NO_VECTOR;
>  			goto out_remove_vqs;
>  		}
>  		vp_dev->msix_vector_map[i] = msix_vec;
> +		j++;
>  
>  		/*
>  		 * Use a different vector for each queue if they are available,
> -- 
> 2.7.4
> 


-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html

  parent reply	other threads:[~2017-03-23 15:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-23  0:30 [REGRESSION] 07ec51480b5e ("virtio_pci: use shared interrupts for virtqueues") causes crashes in guest Laura Abbott
2017-03-23  5:13 ` Jason Wang
2017-03-23  5:13   ` Jason Wang
2017-03-23 14:22   ` Christoph Hellwig
2017-03-23 14:22     ` Christoph Hellwig
2017-03-23 15:19   ` Richard W.M. Jones [this message]
2017-03-23 15:19     ` Richard W.M. Jones
2017-03-23 16:41     ` Michael S. Tsirkin
2017-03-23 16:41       ` Michael S. Tsirkin
2017-03-23 17:15       ` Thorsten Leemhuis
2017-03-23 17:15       ` Thorsten Leemhuis

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=20170323151906.GA19376@redhat.com \
    --to=rjones@redhat.com \
    --cc=hch@lst.de \
    --cc=jasowang@redhat.com \
    --cc=labbott@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@leemhuis.info \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.