]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/virtio_pci-fix-a-null-pointer-reference-in-vp_del_vq.patch
dd06b872a72108946c6a16853205f15d8afe14ef
[thirdparty/kernel/stable-queue.git] / queue-4.19 / virtio_pci-fix-a-null-pointer-reference-in-vp_del_vq.patch
1 From 9c97b03462499e871671ac5b06cd96086928a0d3 Mon Sep 17 00:00:00 2001
2 From: Longpeng <longpeng2@huawei.com>
3 Date: Sat, 9 Mar 2019 15:17:40 +0800
4 Subject: virtio_pci: fix a NULL pointer reference in vp_del_vqs
5
6 [ Upstream commit 6a8aae68c87349dbbcd46eac380bc43cdb98a13b ]
7
8 If the msix_affinity_masks is alloced failed, then we'll
9 try to free some resources in vp_free_vectors() that may
10 access it directly.
11
12 We met the following stack in our production:
13 [ 29.296767] BUG: unable to handle kernel NULL pointer dereference at (null)
14 [ 29.311151] IP: [<ffffffffc04fe35a>] vp_free_vectors+0x6a/0x150 [virtio_pci]
15 [ 29.324787] PGD 0
16 [ 29.333224] Oops: 0000 [#1] SMP
17 [...]
18 [ 29.425175] RIP: 0010:[<ffffffffc04fe35a>] [<ffffffffc04fe35a>] vp_free_vectors+0x6a/0x150 [virtio_pci]
19 [ 29.441405] RSP: 0018:ffff9a55c2dcfa10 EFLAGS: 00010206
20 [ 29.453491] RAX: 0000000000000000 RBX: ffff9a55c322c400 RCX: 0000000000000000
21 [ 29.467488] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff9a55c322c400
22 [ 29.481461] RBP: ffff9a55c2dcfa20 R08: 0000000000000000 R09: ffffc1b6806ff020
23 [ 29.495427] R10: 0000000000000e95 R11: 0000000000aaaaaa R12: 0000000000000000
24 [ 29.509414] R13: 0000000000010000 R14: ffff9a55bd2d9e98 R15: ffff9a55c322c400
25 [ 29.523407] FS: 00007fdcba69f8c0(0000) GS:ffff9a55c2840000(0000) knlGS:0000000000000000
26 [ 29.538472] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
27 [ 29.551621] CR2: 0000000000000000 CR3: 000000003ce52000 CR4: 00000000003607a0
28 [ 29.565886] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
29 [ 29.580055] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
30 [ 29.594122] Call Trace:
31 [ 29.603446] [<ffffffffc04fe8a2>] vp_request_msix_vectors+0xe2/0x260 [virtio_pci]
32 [ 29.618017] [<ffffffffc04fedc5>] vp_try_to_find_vqs+0x95/0x3b0 [virtio_pci]
33 [ 29.632152] [<ffffffffc04ff117>] vp_find_vqs+0x37/0xb0 [virtio_pci]
34 [ 29.645582] [<ffffffffc057bf63>] init_vq+0x153/0x260 [virtio_blk]
35 [ 29.658831] [<ffffffffc057c1e8>] virtblk_probe+0xe8/0x87f [virtio_blk]
36 [...]
37
38 Cc: Gonglei <arei.gonglei@huawei.com>
39 Signed-off-by: Longpeng <longpeng2@huawei.com>
40 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
41 Reviewed-by: Gonglei <arei.gonglei@huawei.com>
42 Signed-off-by: Sasha Levin <sashal@kernel.org>
43 ---
44 drivers/virtio/virtio_pci_common.c | 8 +++++---
45 1 file changed, 5 insertions(+), 3 deletions(-)
46
47 diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
48 index 465a6f5142cc5..45b04bc91f248 100644
49 --- a/drivers/virtio/virtio_pci_common.c
50 +++ b/drivers/virtio/virtio_pci_common.c
51 @@ -255,9 +255,11 @@ void vp_del_vqs(struct virtio_device *vdev)
52 for (i = 0; i < vp_dev->msix_used_vectors; ++i)
53 free_irq(pci_irq_vector(vp_dev->pci_dev, i), vp_dev);
54
55 - for (i = 0; i < vp_dev->msix_vectors; i++)
56 - if (vp_dev->msix_affinity_masks[i])
57 - free_cpumask_var(vp_dev->msix_affinity_masks[i]);
58 + if (vp_dev->msix_affinity_masks) {
59 + for (i = 0; i < vp_dev->msix_vectors; i++)
60 + if (vp_dev->msix_affinity_masks[i])
61 + free_cpumask_var(vp_dev->msix_affinity_masks[i]);
62 + }
63
64 if (vp_dev->msix_enabled) {
65 /* Disable the vector used for configuration */
66 --
67 2.20.1
68