Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4439358ioa; Wed, 27 Apr 2022 04:02:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6N6CsMqnQ4U+wQpql9amC8RU2+2OJPF8RY3qbxOj8cnzCEMUMygyq+JyxgR9aFQHv65wX X-Received: by 2002:a05:6638:358b:b0:326:4717:90d4 with SMTP id v11-20020a056638358b00b00326471790d4mr12456136jal.136.1651057367827; Wed, 27 Apr 2022 04:02:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651057367; cv=none; d=google.com; s=arc-20160816; b=IpCap+45bGL6cD6FmVPTouU3TcfCQZeLX4UdoHHKzr3otDFsRuESOc3tyXC1T+GHGQ PTs44hIkWb/bwG9Rog+3H9BHQnmwAgTJ78vsCRvttxz+h7EWVmnaLj3IDLEyDKad699i nLfub5n4qGgRBCJspOVduIoCzwTooF7vtAx9vBDoYOoErPpqfU7E5q62odpHGw34OgUL +BoRlJudel/mlNcvsysQjiYe7pOB/hqsd7eHicroLHewYz6gN41Cggi7IVfJRaIG3Nou RTk/dOYyolNtJPVdosrbUotVQqDXQxfBg648JvXGGwnmWqy5LzstZy7qlbOK0hju5nZy cYZg== 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=G0JB5uMbYqKit/ym7/dxSNDH6j2y34AGZNM/s5nhKt8=; b=U6/LJlHyhhZzQKTEP/SC+xBYMRPnY9FijhwtGfqmWM/CS3psdiB9h04ptgJWE2PGFb EjeTtJwYTZmvtYEu4rzQVk3juWU7q8jT9anIoAOVjrVWMR7O/2HABnTsTRi6cLu8odll 1xieruV2LeM8EV2IkV7QVyTDRighzpjIUdBBUfZgOLlKHUeW5HR5sqVIhmPgprkiHL++ h7fF4CjFhY2eWjl4BPH5G9EiGHwiq8xPUG3BbtdjREPsva54R00o5Tx7cEgMXHjVum6b 6TTaJR7dFm48CHyvDb/l6xtqFg0h2oBTcqPm4eppxu/BWsnhlYFWLtEyDcFjhatZgkU7 hcEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="BhNjI/xb"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a6-20020a056602208600b0065291cbbc83si578458ioa.22.2022.04.27.04.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:02:47 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="BhNjI/xb"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4FA4A2C38DF; Wed, 27 Apr 2022 03:11:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237674AbiDZJBp (ORCPT + 99 others); Tue, 26 Apr 2022 05:01:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346897AbiDZIp3 (ORCPT ); Tue, 26 Apr 2022 04:45:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36FAEB1E6; Tue, 26 Apr 2022 01:36:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EA9C8B81CFE; Tue, 26 Apr 2022 08:36:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 470AFC385AC; Tue, 26 Apr 2022 08:36:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962180; bh=Kb0biBkFZABp5DjxR6pFH9eVYKEyISk7HCQ3zv4bjvw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BhNjI/xbF8vRomstX0HlAs8L2BHtp4bgC/JE7+O79SFzIqRLnKWtLuY1j7418UUOs 0gYgK41Z+CgLSoqG0EQuolY9cog1GucOcPvQ1WRPC/NZcZ0vDempR7Jpm/HymPXAC8 oOdvhOfD/BhBRblnkSHbS4erCL7GHEzcR92wSaWg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Peter Wang , "Martin K. Petersen" Subject: [PATCH 5.15 013/124] scsi: ufs: core: scsi_get_lba() error fix Date: Tue, 26 Apr 2022 10:20:14 +0200 Message-Id: <20220426081747.676581071@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081747.286685339@linuxfoundation.org> References: <20220426081747.286685339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Wang commit 2bd3b6b75946db2ace06e145d53988e10ed7e99a upstream. When ufs initializes without scmd->device->sector_size set, scsi_get_lba() will get a wrong shift number and trigger an ubsan error. The shift exponent 4294967286 is too large for the 64-bit type 'sector_t' (aka 'unsigned long long'). Call scsi_get_lba() only when opcode is READ_10/WRITE_10/UNMAP. Link: https://lore.kernel.org/r/20220307111752.10465-1-peter.wang@mediatek.com Reviewed-by: Bart Van Assche Signed-off-by: Peter Wang Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/ufs/ufshcd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -358,7 +358,7 @@ static void ufshcd_add_uic_command_trace static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag, enum ufs_trace_str_t str_t) { - u64 lba; + u64 lba = 0; u8 opcode = 0, group_id = 0; u32 intr, doorbell; struct ufshcd_lrb *lrbp = &hba->lrb[tag]; @@ -375,7 +375,6 @@ static void ufshcd_add_command_trace(str return; opcode = cmd->cmnd[0]; - lba = scsi_get_lba(cmd); if (opcode == READ_10 || opcode == WRITE_10) { /* @@ -383,6 +382,7 @@ static void ufshcd_add_command_trace(str */ transfer_len = be32_to_cpu(lrbp->ucd_req_ptr->sc.exp_data_transfer_len); + lba = scsi_get_lba(cmd); if (opcode == WRITE_10) group_id = lrbp->cmd->cmnd[6]; } else if (opcode == UNMAP) { @@ -390,6 +390,7 @@ static void ufshcd_add_command_trace(str * The number of Bytes to be unmapped beginning with the lba. */ transfer_len = blk_rq_bytes(rq); + lba = scsi_get_lba(cmd); } intr = ufshcd_readl(hba, REG_INTERRUPT_STATUS);