Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1183851yba; Thu, 9 May 2019 12:08:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqx46Ev91iJSF5Y6lPMcEdMcBLgEVPvBs3zyYyS1kRELnkPhTtBT2NA7WN96gJF4Cflg7ySU X-Received: by 2002:a17:902:a988:: with SMTP id bh8mr7406912plb.243.1557428914850; Thu, 09 May 2019 12:08:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557428914; cv=none; d=google.com; s=arc-20160816; b=BIZzoSDdWsEHPXcRW0SxH8HaJNaIiUKz0rSXyNDYhw1nCUm5uJ5ZiiM2GBkYQrqSMz WmEImcpAulRIMAAsrczsspY6WyqFf0+dHqDdjfukTpxvKaTidfRnwg61puCIQJyzucMu E3FsGPaJugAIlKg9UHv5/2CkfH5q518nry1GUxk7wUOnzH5HSZrDW1ad+xLwhrAoEUTE q4Gai9nnGPJsKUyOVIQAlhjJ5fJCaTFN8saVTne3PQkA8tDCimTLyG+/RwkgUh7T5SLJ ELwTVdF8yrZqbEPAyU730wkVXp5w0rva7pQYxuEeBtrt4Ip1TjuMtR+z3Tjf6ZvfF0Qk Qmjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8IS6AOxfthVGlonohByCh+2pbQ8J/VJYxN9CoAEBugI=; b=iTs1xvBtGVGAcnDajKUj4NuplpYHpCNz0mvmfw2twwUfyJPJdtbOexvWlTy7w+ODx/ u7UOsJDGQq9YoUra8yWEMYB9SlQ6SHr+Fjut+ToBMKwFOD+pkbNNE2Xf6+h2zl9iIQWZ cbJKewpFQa8lq3MhAji/GboVfFsgmqxvIaWVdfRQJvwthyQiK7XbEJdxdL5jVJzZ9B15 K4xzGCOitveD8XhWdbRVTcDGPLBbx/kGGfCOcL/peZPrEi8HheawvB5j1eyTCnWeuJyj sJfqjcEx7pLfT75jzwsZx0nyAVV32GyuGGiOaUuLQsg9zCN4BfIDpDdoFsx9BgD04VTF WcBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CArYw++l; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si4102221pgv.315.2019.05.09.12.08.18; Thu, 09 May 2019 12:08:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CArYw++l; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727429AbfEISpu (ORCPT + 99 others); Thu, 9 May 2019 14:45:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:37772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727411AbfEISpr (ORCPT ); Thu, 9 May 2019 14:45:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CAEF921848; Thu, 9 May 2019 18:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557427546; bh=3AaFu5/9xyech9Rm2gGCieosPJRXBsveYZw1we/emSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CArYw++lIBmodtr4/xqlOaZGGciNVS2z9Iubjgpj52qGHP1/MRiT3uGDW4x7osoip pF5KHi7mNPMjA1yh9377eDUpsdRxaCFUChv5rjgf74qxrOylyz6Fh82iKDIxDxBV9X udGwHoOp69vgOBzHONmgWIHGz0HNw2c1FXKwV0+8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gonglei , Longpeng , "Michael S. Tsirkin" , Sasha Levin Subject: [PATCH 4.14 22/42] virtio_pci: fix a NULL pointer reference in vp_del_vqs Date: Thu, 9 May 2019 20:42:11 +0200 Message-Id: <20190509181257.144468524@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190509181252.616018683@linuxfoundation.org> References: <20190509181252.616018683@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 6a8aae68c87349dbbcd46eac380bc43cdb98a13b ] 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: 0000 [#1] SMP [...] [ 29.425175] RIP: 0010:[] [] vp_free_vectors+0x6a/0x150 [virtio_pci] [ 29.441405] RSP: 0018:ffff9a55c2dcfa10 EFLAGS: 00010206 [ 29.453491] RAX: 0000000000000000 RBX: ffff9a55c322c400 RCX: 0000000000000000 [ 29.467488] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff9a55c322c400 [ 29.481461] RBP: ffff9a55c2dcfa20 R08: 0000000000000000 R09: ffffc1b6806ff020 [ 29.495427] R10: 0000000000000e95 R11: 0000000000aaaaaa R12: 0000000000000000 [ 29.509414] R13: 0000000000010000 R14: ffff9a55bd2d9e98 R15: ffff9a55c322c400 [ 29.523407] FS: 00007fdcba69f8c0(0000) GS:ffff9a55c2840000(0000) knlGS:0000000000000000 [ 29.538472] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 29.551621] CR2: 0000000000000000 CR3: 000000003ce52000 CR4: 00000000003607a0 [ 29.565886] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 29.580055] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 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 Signed-off-by: Michael S. Tsirkin Reviewed-by: Gonglei Signed-off-by: Sasha Levin --- drivers/virtio/virtio_pci_common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c index 1c4797e53f686..80a3704939cdc 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -254,9 +254,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 */ -- 2.20.1