Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4487993ivc; Tue, 3 Nov 2020 13:21:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxiPOB31PVNKvW1hyLgpsdb1uCfgGNL5l1g/cYOX6lx26pHRiHmsnLhERkAcf0hJokwbkI0 X-Received: by 2002:aa7:c586:: with SMTP id g6mr24325088edq.343.1604438476985; Tue, 03 Nov 2020 13:21:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438476; cv=none; d=google.com; s=arc-20160816; b=e0eD11I9MTuAcFUV2F7WBeKGgUXDkSpmVr6PpnIfemPc2+Dle28RPiscgvM12s+k4H ks2q+4uuXDxVW4N+j8XTbnoOOUDexQui65nj2fhrIFwOzpRmoqyM/thFSQNdgfah7NKg q3GVmsxeu7t4g10zsaaGZgMPJKjYugRpUopzaa3M+ZPBmXPv6MdwZsjh6n/p9lxdpJIY rkQP0o9Z0t0k/xpaAJilp1Ukl0V2cW2J06+LbAwpQ3ClsqH2Ulx1JFKPkRijS9jBz7hb 6lpdxD5frMRFwItD+0n1JqFtG132C0km7Tvt/zPIG6R1QCtRU7hpfFjZiVSFA9XlTb/m TxOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wc6GnSmo3shWKCi27MJD7y3l+RovA9Wm8KjDRZLdNN8=; b=M3x/4G+4HO5rOSexxt2dctHqbc3E2i17Q/zexwu+93uH5wH9wDHjnQ9dASUlRXr5td Ke5eDWoeaZsp2O9vPnJUVm7Xyouf7iqWdALOHpZbKm9TOb8W3aAl4UOwA0vKW8f/JPWq qYDQnylP1GFrkN1lDTSjyzZko+cKwefDJ7t6kJMwDXbOFo8BD1pge3jpk8732uoIYXgZ Bg5zFIzkwEClLR6HOaDNiUFU4Qh7XcX8V1uVxvw6/ICy4jteifY9Pf3P/mts0kC1dy3x 04omxbY8IpSdOLNPb2xPBFq6HqkYF7SUOv0qEJ1X9tpVZn+yh/NEkbzO3VFPh3iAYYlb F1xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=to3BmABv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z10si14934615edp.346.2020.11.03.13.20.54; Tue, 03 Nov 2020 13:21:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=to3BmABv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389172AbgKCVQX (ORCPT + 99 others); Tue, 3 Nov 2020 16:16:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:52946 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388846AbgKCVLU (ORCPT ); Tue, 3 Nov 2020 16:11:20 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 2D8B5206B5; Tue, 3 Nov 2020 21:11:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437879; bh=etcV+UXLV/zln4LlNdKqT0jAuZ2p6sIfPoGh2eAn/UY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=to3BmABvD98nQaoBo/7Rb7psBMftwT7FeWNTgvHoRoW7egxycRCCcAF5J5pJv1itv +KztOf9EQ4SVEOaMJIarKDWu/rVVV4Miu5XcuQHirurrg2iDhPz8HT1nEvTCVH2KOe QR9fKm5n/UqLEii2pZ63kNWbr0flC5JPHASTYLgo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Helge Deller , "Martin K. Petersen" Subject: [PATCH 4.14 072/125] scsi: mptfusion: Fix null pointer dereferences in mptscsih_remove() Date: Tue, 3 Nov 2020 21:37:29 +0100 Message-Id: <20201103203207.402781535@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203156.372184213@linuxfoundation.org> References: <20201103203156.372184213@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Helge Deller commit 2f4843b172c2c0360ee7792ad98025fae7baefde upstream. The mptscsih_remove() function triggers a kernel oops if the Scsi_Host pointer (ioc->sh) is NULL, as can be seen in this syslog: ioc0: LSI53C1030 B2: Capabilities={Initiator,Target} Begin: Waiting for root file system ... scsi host2: error handler thread failed to spawn, error = -4 mptspi: ioc0: WARNING - Unable to register controller with SCSI subsystem Backtrace: [<000000001045b7cc>] mptspi_probe+0x248/0x3d0 [mptspi] [<0000000040946470>] pci_device_probe+0x1ac/0x2d8 [<0000000040add668>] really_probe+0x1bc/0x988 [<0000000040ade704>] driver_probe_device+0x160/0x218 [<0000000040adee24>] device_driver_attach+0x160/0x188 [<0000000040adef90>] __driver_attach+0x144/0x320 [<0000000040ad7c78>] bus_for_each_dev+0xd4/0x158 [<0000000040adc138>] driver_attach+0x4c/0x80 [<0000000040adb3ec>] bus_add_driver+0x3e0/0x498 [<0000000040ae0130>] driver_register+0xf4/0x298 [<00000000409450c4>] __pci_register_driver+0x78/0xa8 [<000000000007d248>] mptspi_init+0x18c/0x1c4 [mptspi] This patch adds the necessary NULL-pointer checks. Successfully tested on a HP C8000 parisc workstation with buggy SCSI drives. Link: https://lore.kernel.org/r/20201022090005.GA9000@ls3530.fritz.box Cc: Signed-off-by: Helge Deller Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/message/fusion/mptscsih.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/drivers/message/fusion/mptscsih.c +++ b/drivers/message/fusion/mptscsih.c @@ -1174,8 +1174,10 @@ mptscsih_remove(struct pci_dev *pdev) MPT_SCSI_HOST *hd; int sz1; - if((hd = shost_priv(host)) == NULL) - return; + if (host == NULL) + hd = NULL; + else + hd = shost_priv(host); mptscsih_shutdown(pdev); @@ -1191,14 +1193,15 @@ mptscsih_remove(struct pci_dev *pdev) "Free'd ScsiLookup (%d) memory\n", ioc->name, sz1)); - kfree(hd->info_kbuf); + if (hd) + kfree(hd->info_kbuf); /* NULL the Scsi_Host pointer */ ioc->sh = NULL; - scsi_host_put(host); - + if (host) + scsi_host_put(host); mpt_detach(pdev); }