Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2524353imm; Mon, 28 May 2018 09:43:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo10zZxjc7+mW6qMyLzf9fNDBf/haFx834gzzHHgbwohyi/vvtfe6qu6UI04hbJ7esrSZG1 X-Received: by 2002:a62:d751:: with SMTP id v17-v6mr14136313pfl.39.1527525804255; Mon, 28 May 2018 09:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527525804; cv=none; d=google.com; s=arc-20160816; b=vYF9n8ga+rZ7nYHlj8+yL52gcywSPsZDJBBEe9SxqNYHd9ViU0Tetnq8WGYETCraBh H4dmI6Cn8gySeS6bsIM2S4bDMY00lNFqv1kfpbtogWrFpwj076l6aXbuU9d0r2BqWDj6 6ejnwGkKd5gvbvRs8mXAaYmPG1f3pHoCU74hdBJjIHVnTvLXhk0G0dPraHBtTig9fLLi djrm43yn2MJkUv9Se08YyqxD1cHykwbEm8IuykJRTv4M0ruV4JWTGyddotuF1MXXUS4l yDn0THCkAf/3+PvozhzdvL+WS9dMfFr16VCbnWm4BDWG4Ry6oU3jWfb/tctKdYqHrwTs xTVg== 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:dkim-signature :arc-authentication-results; bh=jXv0FNTy+MKwLnk6BWIRfNuFh5T29lzGZX9y8lFECiY=; b=yWUf/yGBZumfxe1nio2fxYmF/+ek3TDKkgeOA3MFOB0E8wyhY8DR+SQHGuwypQx/wD TY7nk177DpzgJNb5qfhEkG8QWrVIJNbo/L00T/wHN/+Vwjn1o5elq9OXTs6MLzXmZP1m ASaGNsKitXvS7gOs1SfQUn5u/h+sr0lg6I6VMgsPHkoKb0DMoybaGDFfYLvUybgbUZyn joWlE8VoRcKNfhlaGiJq5+5pmSlodY6PyaNBNrt6b7zZEQYHp5mmBm1Pbh5eqRVLQf4E XTWpg1m4z97Jrn1S56L/ZdpVk4kw90rqY/w/J89ce3uyop07F5kBLSoJ4yfgNqgD9oVG Atmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NkKhwp/4; 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 z5-v6si29161987pln.562.2018.05.28.09.43.09; Mon, 28 May 2018 09:43:24 -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=NkKhwp/4; 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 S940399AbeE1Qld (ORCPT + 99 others); Mon, 28 May 2018 12:41:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:56040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933456AbeE1KH6 (ORCPT ); Mon, 28 May 2018 06:07:58 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 C297720876; Mon, 28 May 2018 10:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502078; bh=1xsUq6z4eFfCOdJ6HDrpaGVsJP8//9ikmWfwwddHPZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NkKhwp/4TT+nE4813bjRjuwGONMjxWGPSHvmO4IZu1CaE0P2Y5/FQDPRy9NkhlwuR hNq7xHSI8GosBx42tA292vkZ+46HgK4AxB9OOWFNtRr0GYFdbFGE5Xx6ec/vV6v7YV JJeXpp6GYAvdFzk0An3eKjBZ/fyfb00nWu1WazGY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Meelis Roos , Dave Carroll , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 3.18 054/185] scsi: aacraid: fix shutdown crash when init fails Date: Mon, 28 May 2018 12:01:35 +0200 Message-Id: <20180528100055.473820437@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Meelis Roos [ Upstream commit 00c20cdc79259c6c5bf978b21af96c2d3edb646d ] When aacraid init fails with "AAC0: adapter self-test failed.", shutdown leads to UBSAN warning and then oops: [154316.118423] ================================================================================ [154316.118508] UBSAN: Undefined behaviour in drivers/scsi/scsi_lib.c:2328:27 [154316.118566] member access within null pointer of type 'struct Scsi_Host' [154316.118631] CPU: 2 PID: 14530 Comm: reboot Tainted: G W 4.15.0-dirty #89 [154316.118701] Hardware name: Hewlett Packard HP NetServer/HP System Board, BIOS 4.06.46 PW 06/25/2003 [154316.118774] Call Trace: [154316.118848] dump_stack+0x48/0x65 [154316.118916] ubsan_epilogue+0xe/0x40 [154316.118976] __ubsan_handle_type_mismatch+0xfb/0x180 [154316.119043] scsi_block_requests+0x20/0x30 [154316.119135] aac_shutdown+0x18/0x40 [aacraid] [154316.119196] pci_device_shutdown+0x33/0x50 [154316.119269] device_shutdown+0x18a/0x390 [...] [154316.123435] BUG: unable to handle kernel NULL pointer dereference at 000000f4 [154316.123515] IP: scsi_block_requests+0xa/0x30 This is because aac_shutdown() does struct Scsi_Host *shost = pci_get_drvdata(dev); scsi_block_requests(shost); and that assumes shost has been assigned with pci_set_drvdata(). However, pci_set_drvdata(pdev, shost) is done in aac_probe_one() far after bailing out with error from calling the init function ((*aac_drivers[index].init)(aac)), and when the init function fails, no error is returned from aac_probe_one() so PCI layer assumes there is driver attached, and tries to shut it down later. Fix it by returning error from aac_probe_one() when card-specific init function fails. This fixes reboot on my HP NetRAID-4M with dead battery. Signed-off-by: Meelis Roos Reviewed-by: Dave Carroll Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/aacraid/linit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/scsi/aacraid/linit.c +++ b/drivers/scsi/aacraid/linit.c @@ -1172,8 +1172,10 @@ static int aac_probe_one(struct pci_dev * Map in the registers from the adapter. */ aac->base_size = AAC_MIN_FOOTPRINT_SIZE; - if ((*aac_drivers[index].init)(aac)) + if ((*aac_drivers[index].init)(aac)) { + error = -ENODEV; goto out_unmap; + } if (aac->sync_mode) { if (aac_sync_mode)