Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2555256yba; Mon, 6 May 2019 07:58:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1w8+0gLEGSwwt0eA5RGbouTzgFihe2KlwE/EIWDBQQW3oOEtZP7a5uCfYlvUZ4WeGgOUJ X-Received: by 2002:a65:5c4a:: with SMTP id v10mr25258616pgr.359.1557154689521; Mon, 06 May 2019 07:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557154689; cv=none; d=google.com; s=arc-20160816; b=m60t4/TUE6XfuwZRO7dJhISrTO2OAwqiqUsmMdvi1gn4ot9h3VOQewmTEhZC1h8w4d KdmhDFhJP8U9oKzb6dxjidzi1TEjX7509Jl3GykiAHtc+bN13sebgbY0VJVhDL5pi/ZZ fJcN9Plva5CJhDsqKC7/TcILg4iUeBFNOBZGEqt6/49SX4hD2FP48RmD5K4cE1Z2C0dE 6tKD1aE+ltXca9O3EEP1duhdPkAAN7kkUF/SdK/w7z/eAtr/BKacGIEbbEMDbDYgKO/B wS9cyIgqxM2reW2PMcWCl8TaQ8bqX+loLe6swLXGAkaLvVlxG4Q92w9+t2EsvGbFqrMX db5A== 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=1Bc0nlqKRrGxSuDiEi7CASD5HFtzvtyGxBfh1jQTHCE=; b=h/aa+YZmwBX3nEu1N0a8XuoXYUa5Bl7AIVkJlqh1uJOyN72b6TIMPAq40jsy+gtLb2 EJVLit/znhLNXcjwEOVW91VMpmT5yjBoEYPMvam6bp+LZvHMy2IUTygshsUIGH3CqMZ6 y9QD9xHfSgm8LLlLce2SpXmh4sxoNHKj94l+m+YeVRyhcQx2h8YirWqZGH/kjwamwixv Hii2PGwVKy93ri9ikZua4ywPmMRWSbk9ReuiynmF2WkPiFj18ehCqVgmCVdYrdwhLiZ5 4bVIwga6GbOxi1U9T627KyFN5BlshoGDWc6iBDsdbMQUjkXWKXjQw1kXjKqWibSu9p2r Vd4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=azn9VwwC; 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 s12si14783091plp.420.2019.05.06.07.57.53; Mon, 06 May 2019 07:58:09 -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=azn9VwwC; 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 S1728757AbfEFOzs (ORCPT + 99 others); Mon, 6 May 2019 10:55:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:42714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727080AbfEFOpn (ORCPT ); Mon, 6 May 2019 10:45:43 -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 2C2DF20C01; Mon, 6 May 2019 14:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153942; bh=k1qLfZtkdHPa8fQMawYRh8CPXtKR+g3RMPQy+5toWIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=azn9VwwCA64S3oLTnTpfyHG3dAhaLW9cR0yRKhaYhCffUcD/mGmPoU9JVLio+wE18 7ZlnsxORt1otiKeLMYMhVdSsyMNT0viuJ497xtms2MfViPlD8YYIsVe0KLD/VeolNN Lsbepgpa9o3cW2QzOGaTQlVTNFDPIpSkuINsv9qs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michal Simek , Guenter Roeck , Jens Axboe , Sasha Levin Subject: [PATCH 4.14 55/75] xsysace: Fix error handling in ace_setup Date: Mon, 6 May 2019 16:33:03 +0200 Message-Id: <20190506143058.249615723@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143053.287515952@linuxfoundation.org> References: <20190506143053.287515952@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 47b16820c490149c2923e8474048f2c6e7557cab ] If xace hardware reports a bad version number, the error handling code in ace_setup() calls put_disk(), followed by queue cleanup. However, since the disk data structure has the queue pointer set, put_disk() also cleans and releases the queue. This results in blk_cleanup_queue() accessing an already released data structure, which in turn may result in a crash such as the following. [ 10.681671] BUG: Kernel NULL pointer dereference at 0x00000040 [ 10.681826] Faulting instruction address: 0xc0431480 [ 10.682072] Oops: Kernel access of bad area, sig: 11 [#1] [ 10.682251] BE PAGE_SIZE=4K PREEMPT Xilinx Virtex440 [ 10.682387] Modules linked in: [ 10.682528] CPU: 0 PID: 1 Comm: swapper Tainted: G W 5.0.0-rc6-next-20190218+ #2 [ 10.682733] NIP: c0431480 LR: c043147c CTR: c0422ad8 [ 10.682863] REGS: cf82fbe0 TRAP: 0300 Tainted: G W (5.0.0-rc6-next-20190218+) [ 10.683065] MSR: 00029000 CR: 22000222 XER: 00000000 [ 10.683236] DEAR: 00000040 ESR: 00000000 [ 10.683236] GPR00: c043147c cf82fc90 cf82ccc0 00000000 00000000 00000000 00000002 00000000 [ 10.683236] GPR08: 00000000 00000000 c04310bc 00000000 22000222 00000000 c0002c54 00000000 [ 10.683236] GPR16: 00000000 00000001 c09aa39c c09021b0 c09021dc 00000007 c0a68c08 00000000 [ 10.683236] GPR24: 00000001 ced6d400 ced6dcf0 c0815d9c 00000000 00000000 00000000 cedf0800 [ 10.684331] NIP [c0431480] blk_mq_run_hw_queue+0x28/0x114 [ 10.684473] LR [c043147c] blk_mq_run_hw_queue+0x24/0x114 [ 10.684602] Call Trace: [ 10.684671] [cf82fc90] [c043147c] blk_mq_run_hw_queue+0x24/0x114 (unreliable) [ 10.684854] [cf82fcc0] [c04315bc] blk_mq_run_hw_queues+0x50/0x7c [ 10.685002] [cf82fce0] [c0422b24] blk_set_queue_dying+0x30/0x68 [ 10.685154] [cf82fcf0] [c0423ec0] blk_cleanup_queue+0x34/0x14c [ 10.685306] [cf82fd10] [c054d73c] ace_probe+0x3dc/0x508 [ 10.685445] [cf82fd50] [c052d740] platform_drv_probe+0x4c/0xb8 [ 10.685592] [cf82fd70] [c052abb0] really_probe+0x20c/0x32c [ 10.685728] [cf82fda0] [c052ae58] driver_probe_device+0x68/0x464 [ 10.685877] [cf82fdc0] [c052b500] device_driver_attach+0xb4/0xe4 [ 10.686024] [cf82fde0] [c052b5dc] __driver_attach+0xac/0xfc [ 10.686161] [cf82fe00] [c0528428] bus_for_each_dev+0x80/0xc0 [ 10.686314] [cf82fe30] [c0529b3c] bus_add_driver+0x144/0x234 [ 10.686457] [cf82fe50] [c052c46c] driver_register+0x88/0x15c [ 10.686610] [cf82fe60] [c09de288] ace_init+0x4c/0xac [ 10.686742] [cf82fe80] [c0002730] do_one_initcall+0xac/0x330 [ 10.686888] [cf82fee0] [c09aafd0] kernel_init_freeable+0x34c/0x478 [ 10.687043] [cf82ff30] [c0002c6c] kernel_init+0x18/0x114 [ 10.687188] [cf82ff40] [c000f2f0] ret_from_kernel_thread+0x14/0x1c [ 10.687349] Instruction dump: [ 10.687435] 3863ffd4 4bfffd70 9421ffd0 7c0802a6 93c10028 7c9e2378 93e1002c 38810008 [ 10.687637] 7c7f1b78 90010034 4bfffc25 813f008c <81290040> 75290100 4182002c 80810008 [ 10.688056] ---[ end trace 13c9ff51d41b9d40 ]--- Fix the problem by setting the disk queue pointer to NULL before calling put_disk(). A more comprehensive fix might be to rearrange the code to check the hardware version before initializing data structures, but I don't know if this would have undesirable side effects, and it would increase the complexity of backporting the fix to older kernels. Fixes: 74489a91dd43a ("Add support for Xilinx SystemACE CompactFlash interface") Acked-by: Michal Simek Signed-off-by: Guenter Roeck Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/xsysace.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c index 14459d66ef0c..51ff7ee1b2b1 100644 --- a/drivers/block/xsysace.c +++ b/drivers/block/xsysace.c @@ -1063,6 +1063,8 @@ static int ace_setup(struct ace_device *ace) return 0; err_read: + /* prevent double queue cleanup */ + ace->gd->queue = NULL; put_disk(ace->gd); err_alloc_disk: blk_cleanup_queue(ace->queue); -- 2.20.1