From patchwork Mon Jan 9 19:44:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9505811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ECE1660757 for ; Mon, 9 Jan 2017 19:44:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F16C12833A for ; Mon, 9 Jan 2017 19:44:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E44F628452; Mon, 9 Jan 2017 19:44:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72B642839A for ; Mon, 9 Jan 2017 19:44:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763684AbdAIToo (ORCPT ); Mon, 9 Jan 2017 14:44:44 -0500 Received: from mail-pg0-f50.google.com ([74.125.83.50]:35453 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761793AbdAIToj (ORCPT ); Mon, 9 Jan 2017 14:44:39 -0500 Received: by mail-pg0-f50.google.com with SMTP id 194so16680980pgd.2 for ; Mon, 09 Jan 2017 11:44:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=uBVPYZ8Ueakqr23x9X4CKQlHy/cID+oVtKJimaw5JhM=; b=113kQVNiltAco1kRqJvwwSKSR7Ucu7KzdwHxUSmv+J7T+UjE5CF8GM8itNo+7muwvo x1U9ypunFBcr9u+rTo0/g2VV5TE31n14TSAvcqxDIvMe0WaihZDkBoH3EOIRCh/1cOXj X2YSv6BDx23Evff7tJQv0wPTEwiKdfk5Wy487oUScuhaZDQYRWqzYdgqZ2ZGgQS/wTKK dkbVASMu04ZgxKi01TMN90bZOxa7ywVFDeS2dPL+Kt6s9iL1vjmehBs1srGATu2DpCh6 +9FZJ56GghWk68LxfqEHhT5N+Keji766nNeY6Tn+fA96zgRoOYabyJWQAqE81SK5m45E ZZkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=uBVPYZ8Ueakqr23x9X4CKQlHy/cID+oVtKJimaw5JhM=; b=G2UJfTs1bXPtKhPy6mMzHILQnEOfqLF47O6ehwteIP80qKsilV0JrsxdRgXbY9b4M9 FfWvLV6IyN+D5qfIyyTNsFunGU/oRzY41m31rXF3LXN7I4x4AA10tR+w+sbGugJaO+xy x3uM0XOiE31F/bb2ugeVYomCbnETvdUQDRmBvp1u2havuyDoV0AwC+535pABXGMfBQ/u pVbuLEh9dSxa8p0bxVWekXxYsFZB2Tge3MmpU732cyJ0bymaUsRR9BDQmmSSiDW9+Eln 8pF9EjMT4VudfiCb1grqoNg5K0DB4WrfzPH5ZtZdYFHdge0jSPPM1b7PeLoeVmil7kT8 FtWQ== X-Gm-Message-State: AIkVDXJW7mlZL9uBTWGZdV2pdJixbsZJlLD1UJYJXFZxh8ermlQ528B+Ev6slvT0wC50U6Ek X-Received: by 10.99.173.68 with SMTP id y4mr162970120pgo.54.1483991078857; Mon, 09 Jan 2017 11:44:38 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::2:df2a]) by smtp.gmail.com with ESMTPSA id u64sm175294545pgc.39.2017.01.09.11.44.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jan 2017 11:44:38 -0800 (PST) From: Omar Sandoval To: "Michael S. Tsirkin" , Jason Wang , virtualization@lists.linux-foundation.org, linux-block@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH] virtio_blk: fix panic in initialization error path Date: Mon, 9 Jan 2017 11:44:12 -0800 Message-Id: <4bc0f759ce198dc36e9b678a3c8f69bfef5cb728.1483990999.git.osandov@fb.com> X-Mailer: git-send-email 2.11.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval If blk_mq_init_queue() returns an error, it gets assigned to vblk->disk->queue. Then, when we call put_disk(), we end up calling blk_put_queue() with the ERR_PTR, causing a bad dereference. Fix it by only assigning to vblk->disk->queue on success. Signed-off-by: Omar Sandoval Reviewed-by: Jeff Moyer Acked-by: Jason Wang Acked-by: Michael S. Tsirkin --- drivers/block/virtio_blk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 5545a679abd8..8587361e5356 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -628,11 +628,12 @@ static int virtblk_probe(struct virtio_device *vdev) if (err) goto out_put_disk; - q = vblk->disk->queue = blk_mq_init_queue(&vblk->tag_set); + q = blk_mq_init_queue(&vblk->tag_set); if (IS_ERR(q)) { err = -ENOMEM; goto out_free_tags; } + vblk->disk->queue = q; q->queuedata = vblk;