Received: by 10.223.185.116 with SMTP id b49csp2202352wrg; Thu, 15 Feb 2018 08:02:54 -0800 (PST) X-Google-Smtp-Source: AH8x224QTSets61Xk6WnondP9693PyE86LBjPZr7EXFRNJH+22+u6WgPTrzG+SubkkCUzvntuFHm X-Received: by 2002:a17:902:243:: with SMTP id 61-v6mr2959587plc.202.1518710573997; Thu, 15 Feb 2018 08:02:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518710573; cv=none; d=google.com; s=arc-20160816; b=lm/5XzFO2HZrzUjJSWcbm0GmtQCHClAWu7nQOvhKjUvf5X+fnguoXNfiFeyguFuQBq V47AgGPJXMs5pXsQwOTprh0MXNVXNyuDOnw0RXMmPi4U2fNRiPppn00TYuLxgYFc9GDu AUpe1o7KjejL8THRxRocClI41qMyLQzkst2cnjdG61Mchbb43lgZkdGimEsOTEOmy0MF HdLRfwZbqwts9mbU2vQsWZTOCQ5r49aTDJoKtzDpjaTblpFlATxBOrkOVnFM/hkZSwuK PSxkEYGcgmL2zPLNg0nseG41w84yAEsB0TX+EzTIP8u+ratRPCrqdZnCrG+EREG5+Yxq XnqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=1YP4+y/Wb4vE3XCX1BI/FDmMxmIpjaWNr0jpEYBmufk=; b=CLX49Vyk5RlUh5tQ3aI/fLcu/jkwGxKo/TsOoxVRbt/oGd4+G5o77ZtYIW3QVh1Rzg sLBpmR7ZI45taJowQdlQ0XerssZ3u4vWGF0RhghHEldW9phJg5SftzkZL4yCSS5Cc3lQ YvYesKi+w+0UXg7IrIJ2O1maVidHAXR83FnZXr+b6Bj/ctvhz+cgaDH7C7/ZiAl+axuQ 71TdLR43FzWNQDd9+e1wmEWXtbxmlToGXh2lJkUFJ53UjB951X+A0sJZzkZE+KO0d9Nf C+m3q3x023J9L8zHzGnqvXsSlIeJGl95qIwz/XAgdeQ7qmszVv6AT/6z3UPxJXOKMVr3 eB3w== ARC-Authentication-Results: i=1; mx.google.com; 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 r14si148941pgt.731.2018.02.15.08.02.28; Thu, 15 Feb 2018 08:02:53 -0800 (PST) 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; 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 S1424795AbeBOPq6 (ORCPT + 99 others); Thu, 15 Feb 2018 10:46:58 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:35980 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424749AbeBOPq4 (ORCPT ); Thu, 15 Feb 2018 10:46:56 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BC24FFF2; Thu, 15 Feb 2018 15:46:55 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Maciej S. Szmigiero" , Bart Van Assche , Jens Axboe Subject: [PATCH 4.15 182/202] pktcdvd: Fix a recently introduced NULL pointer dereference Date: Thu, 15 Feb 2018 16:18:02 +0100 Message-Id: <20180215151722.375063493@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bart Van Assche commit 882d4171a8950646413b1a3cbe0e4a6a612fe82e upstream. Call bdev_get_queue(bdev) after bdev->bd_disk has been initialized instead of just before that pointer has been initialized. This patch avoids that the following command pktsetup 1 /dev/sr0 triggers the following kernel crash: BUG: unable to handle kernel NULL pointer dereference at 0000000000000548 IP: pkt_setup_dev+0x2db/0x670 [pktcdvd] CPU: 2 PID: 724 Comm: pktsetup Not tainted 4.15.0-rc4-dbg+ #1 Call Trace: pkt_ctl_ioctl+0xce/0x1c0 [pktcdvd] do_vfs_ioctl+0x8e/0x670 SyS_ioctl+0x3c/0x70 entry_SYSCALL_64_fastpath+0x23/0x9a Reported-by: Maciej S. Szmigiero Fixes: commit ca18d6f769d2 ("block: Make most scsi_req_init() calls implicit") Signed-off-by: Bart Van Assche Tested-by: Maciej S. Szmigiero Cc: Maciej S. Szmigiero Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/pktcdvd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2579,14 +2579,14 @@ static int pkt_new_dev(struct pktcdvd_de bdev = bdget(dev); if (!bdev) return -ENOMEM; + ret = blkdev_get(bdev, FMODE_READ | FMODE_NDELAY, NULL); + if (ret) + return ret; if (!blk_queue_scsi_passthrough(bdev_get_queue(bdev))) { WARN_ONCE(true, "Attempt to register a non-SCSI queue\n"); - bdput(bdev); + blkdev_put(bdev, FMODE_READ | FMODE_NDELAY); return -EINVAL; } - ret = blkdev_get(bdev, FMODE_READ | FMODE_NDELAY, NULL); - if (ret) - return ret; /* This is safe, since we have a reference from open(). */ __module_get(THIS_MODULE);