Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11792399pjo; Thu, 2 Jan 2020 14:21:50 -0800 (PST) X-Google-Smtp-Source: APXvYqwK4BQ1ZVblUROqNH4tRH5joxGKaMATAXi34cBRHElwacDplYE0nGd/7L71FXI2fsScx+Or X-Received: by 2002:a9d:7c90:: with SMTP id q16mr78370046otn.191.1578003710260; Thu, 02 Jan 2020 14:21:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578003710; cv=none; d=google.com; s=arc-20160816; b=LxgA1Mjbdh0xUBN3PF8G7IvGaNGW0CoGAV6B5PkQ/Ih3+JvYWi3+alc5aE4QSuQ1ER culL1REXp6GS2GiMN0MRtGMdmMCK5QEiybHvl2teztL/fgAF0c6x4rD2MV00BeSRDK0v V6m+/vX1AwhKqB0apT0Oj8puY70w/dmTpQ8VTDFdQu1Qt4JDzyXszegVfx3jcrV8CA1H lE6w7S1WvlK3g3XnMb0X3DvqMh6iu5Rwjbw2Fz9RfIjWx+rBgIu8xuS7xczzJybLfUpM f0VmgCS46SCimJZ242YWmeCCLAHIWR78U/7g3/5jlCym9tfMosCBO+2CG8+8gpgjZ/8L U/WQ== 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=dDuEp7RRElERa5HM9pvWpUxzKsw/0Hr8dco+xLCwJtI=; b=WmPZ1YzX4oao0eAZGsl9fTs3O8vwBM0y8G0qsdrKP/PF4t2ihf84TGuyeAseiE2DvB Pn7IVwbAJeCq0KvePm1DDLd7gOXOzqE7rlzzeldIcxTEhSvULkl6QmIibhBZOzkJhYEa C5//1zKIq0rls5zcA9uzSZt26eUnukfM04ZYEAbL/d5PnTLpLoDhjTw/GXlzDSzym8zH LCe0RfcAtjrtAE90fFwlIUURTnjzDp6BZEA8J1gXz5YCYgwZ9/DYR9IJvR571mirSY+0 5Ixctpt3KmhjeREDzbdjNMThDlWpEIaUTocQcI2s1sfjDZBo5YMLOAOUoQpHI3WKv/i8 kakA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ad1184IX; 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 f4si20881285oij.133.2020.01.02.14.21.38; Thu, 02 Jan 2020 14:21:50 -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; dkim=pass header.i=@kernel.org header.s=default header.b=ad1184IX; 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 S1728514AbgABWUB (ORCPT + 99 others); Thu, 2 Jan 2020 17:20:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:36778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728507AbgABWT7 (ORCPT ); Thu, 2 Jan 2020 17:19:59 -0500 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 371CC22314; Thu, 2 Jan 2020 22:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003598; bh=gkNryoQdQeCUL1UzSkod7HxNfAsDk2MseLcigk/kfgc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ad1184IXXl7pSBA1zAkq8280Ajf/Lz5ifR/sgvsYD1k0Z/wT0ULvJrOrGvV22+FUI +oGCGmNtrE5PW7qWYetSz8sHmb/u4e8dA9IsSRzlsMIljFzaA+rJ3RoiJVZQQM01Y6 VE7dRySokusgOG+xurTlJ6Dbt8NEy8s7h4OWuTdI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alim Akhtar , Bart Van Assche , Bean Huo , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.19 036/114] scsi: ufs: fix potential bug which ends in system hang Date: Thu, 2 Jan 2020 23:06:48 +0100 Message-Id: <20200102220032.725515295@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220029.183913184@linuxfoundation.org> References: <20200102220029.183913184@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 From: Bean Huo [ Upstream commit cfcbae3895b86c390ede57b2a8f601dd5972b47b ] In function __ufshcd_query_descriptor(), in the event of an error happening, we directly goto out_unlock and forget to invaliate hba->dev_cmd.query.descriptor pointer. This results in this pointer still valid in ufshcd_copy_query_response() for other query requests which go through ufshcd_exec_raw_upiu_cmd(). This will cause __memcpy() crash and system hangs. Log as shown below: Unable to handle kernel paging request at virtual address ffff000012233c40 Mem abort info: ESR = 0x96000047 Exception class = DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000047 CM = 0, WnR = 1 swapper pgtable: 4k pages, 48-bit VAs, pgdp = 0000000028cc735c [ffff000012233c40] pgd=00000000bffff003, pud=00000000bfffe003, pmd=00000000ba8b8003, pte=0000000000000000 Internal error: Oops: 96000047 [#2] PREEMPT SMP ... Call trace: __memcpy+0x74/0x180 ufshcd_issue_devman_upiu_cmd+0x250/0x3c0 ufshcd_exec_raw_upiu_cmd+0xfc/0x1a8 ufs_bsg_request+0x178/0x3b0 bsg_queue_rq+0xc0/0x118 blk_mq_dispatch_rq_list+0xb0/0x538 blk_mq_sched_dispatch_requests+0x18c/0x1d8 __blk_mq_run_hw_queue+0xb4/0x118 blk_mq_run_work_fn+0x28/0x38 process_one_work+0x1ec/0x470 worker_thread+0x48/0x458 kthread+0x130/0x138 ret_from_fork+0x10/0x1c Code: 540000ab a8c12027 a88120c7 a8c12027 (a88120c7) ---[ end trace 793e1eb5dff69f2d ]--- note: kworker/0:2H[2054] exited with preempt_count 1 This patch is to move "descriptor = NULL" down to below the label "out_unlock". Fixes: d44a5f98bb49b2(ufs: query descriptor API) Link: https://lore.kernel.org/r/20191112223436.27449-3-huobean@gmail.com Reviewed-by: Alim Akhtar Reviewed-by: Bart Van Assche Signed-off-by: Bean Huo Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/ufshcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 8bce755e0f5b..7510d8328d4d 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3011,10 +3011,10 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba, goto out_unlock; } - hba->dev_cmd.query.descriptor = NULL; *buf_len = be16_to_cpu(response->upiu_res.length); out_unlock: + hba->dev_cmd.query.descriptor = NULL; mutex_unlock(&hba->dev_cmd.lock); out: ufshcd_release(hba); -- 2.20.1