> -Original Message-
> From: longpeng
> Sent: Saturday, March 09, 2019 3:18 PM
> To: m...@redhat.com; jasow...@redhat.com
> Cc: virtualizat...@lists.linux-foundation.org; linux-kernel@vger.kernel.org;
> longpeng ; Gonglei (Arei)
>
> Subject: [PATCH] virtio_pci: fix a NULL pointer reference in vp_del_vqs
>
> From: Longpeng
>
> If the msix_affinity_masks is alloced failed, then we'll
> try to free some resources in vp_free_vectors() that may
> access it directly.
>
> We met the following stack in our production:
> [ 29.296767] BUG: unable to handle kernel NULL pointer dereference at
> (null)
> [ 29.311151] IP: [] vp_free_vectors+0x6a/0x150
> [virtio_pci]
> [ 29.324787] PGD 0
> [ 29.333224] Oops: [#1] SMP
> [...]
> [ 29.425175] RIP: 0010:[] []
> vp_free_vectors+0x6a/0x150 [virtio_pci]
> [ 29.441405] RSP: 0018:9a55c2dcfa10 EFLAGS: 00010206
> [ 29.453491] RAX: RBX: 9a55c322c400 RCX:
>
> [ 29.467488] RDX: RSI: RDI:
> 9a55c322c400
> [ 29.481461] RBP: 9a55c2dcfa20 R08: R09:
> c1b6806ff020
> [ 29.495427] R10: 0e95 R11: 00aa R12:
>
> [ 29.509414] R13: 0001 R14: 9a55bd2d9e98 R15:
> 9a55c322c400
> [ 29.523407] FS: 7fdcba69f8c0() GS:9a55c284()
> knlGS:
> [ 29.538472] CS: 0010 DS: ES: CR0: 80050033
> [ 29.551621] CR2: CR3: 3ce52000 CR4:
> 003607a0
> [ 29.565886] DR0: DR1: DR2:
>
> [ 29.580055] DR3: DR6: fffe0ff0 DR7:
> 0400
> [ 29.594122] Call Trace:
> [ 29.603446] [] vp_request_msix_vectors+0xe2/0x260
> [virtio_pci]
> [ 29.618017] [] vp_try_to_find_vqs+0x95/0x3b0
> [virtio_pci]
> [ 29.632152] [] vp_find_vqs+0x37/0xb0 [virtio_pci]
> [ 29.645582] [] init_vq+0x153/0x260 [virtio_blk]
> [ 29.658831] [] virtblk_probe+0xe8/0x87f [virtio_blk]
> [...]
>
> Cc: Gonglei
> Signed-off-by: Longpeng
> ---
> drivers/virtio/virtio_pci_common.c | 8 +---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
Reviewed-by: Gonglei
Thanks,
-Gonglei
> diff --git a/drivers/virtio/virtio_pci_common.c
> b/drivers/virtio/virtio_pci_common.c
> index d0584c0..7a0398b 100644
> --- a/drivers/virtio/virtio_pci_common.c
> +++ b/drivers/virtio/virtio_pci_common.c
> @@ -255,9 +255,11 @@ void vp_del_vqs(struct virtio_device *vdev)
> for (i = 0; i < vp_dev->msix_used_vectors; ++i)
> free_irq(pci_irq_vector(vp_dev->pci_dev, i), vp_dev);
>
> - for (i = 0; i < vp_dev->msix_vectors; i++)
> - if (vp_dev->msix_affinity_masks[i])
> - free_cpumask_var(vp_dev->msix_affinity_masks[i]);
> + if (vp_dev->msix_affinity_masks) {
> + for (i = 0; i < vp_dev->msix_vectors; i++)
> + if (vp_dev->msix_affinity_masks[i])
> +
> free_cpumask_var(vp_dev->msix_affinity_masks[i]);
> + }
>
> if (vp_dev->msix_enabled) {
> /* Disable the vector used for configuration */
> --
> 1.8.3.1
>