Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2573826imu; Thu, 29 Nov 2018 07:06:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/UDN65XHCYUnzQvA6KnT+bFJjA2JTo+HcTzVYCFzVjycbUMaBG5XwL/dXdRFzD7O/ciuymM X-Received: by 2002:a17:902:1103:: with SMTP id d3-v6mr1713160pla.249.1543503970657; Thu, 29 Nov 2018 07:06:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543503970; cv=none; d=google.com; s=arc-20160816; b=Hv7HlsU1p0Ur1LntEj/bi79AH0ZdYuasXgcJKMWqgJjOxMb55P2k3tTrSSfnINDI5C VAc5km13iT78KxfjnjFaarRg4riRl0mx7aFdYzaCkPGdeDTFsuiKi5QVhYK9UdNt81vP K3Rhzjv4/ROXxekGEpOZAswMxwaeC0ayn0zJHvr4DDEwkBB65B/JxCdXUzLAxoeVfZvx sbyMIkjH4EDN+8uOCYAn9ASBIg8wnCNj0DRvDZaWBFGU5OdBWGFui3Ba+NSLkPfbC0Ef WI65mkxit2rMv36zwhgjHv+fh93sGQ7S2Pgv6Bg9pbagyC/5Av/C5XVyhRjzcihP51j+ I7FQ== 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=l/fvPcyz2WkRH3hxQ/xHlw6t0gWleO9b72pK0LVb5uI=; b=B6W+/gK23Z8vm4Ysm/3CJFxoCVWvZW99j7Ifw6Ukoy+Jtq9lfOOibRI/xA1nAyT8zN H6xBUUKT+xvsR10PZ0TChGTBR4b/0IqOsL1j1Gk2lBf3UKt2uozN7XNAYwCnn//HrJv9 MQEPcEigcMNbgrv+w8shQMheqPfXoXc2lqxxDPOsrAJa7o1N9fuxsOoLVHmSxVRWbvMT FqhkEsaHceVEH/qPOIjwufPnRkYURQe3hTufK9I6ued3b0vkeB6XoAW3xP8XSUCv0v8+ Y37rHFoZXpv1aYPcFnGn4C1VkiX+Ok0SjC846l/VhsmQ8eLT7QU5LAu6RBI6ZGmrginf L9mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MdpbrKpw; 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 1si2430433pls.16.2018.11.29.07.05.55; Thu, 29 Nov 2018 07:06:10 -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=MdpbrKpw; 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 S1730136AbeK3BWQ (ORCPT + 99 others); Thu, 29 Nov 2018 20:22:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:43900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729224AbeK3BWP (ORCPT ); Thu, 29 Nov 2018 20:22:15 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 0156C2133F; Thu, 29 Nov 2018 14:16:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501005; bh=4PzYO707HyDkFFZM6/hTM1cAQcWRo50kF3DgHGJJzgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MdpbrKpwD4uWnHIAItEvAZ/l0ygbTU2QKbjPwcFbjyiZpVLpf8gjDceUm4YfwTHdj CjWMCralklw8IKszZrZfiYNcVs4m5LoF1l+bjxoWnnRXp8QPsCsbiXb6DiVHPJd30J tHVLy41zblaBOIXQ1zTBbeXcN1Maggmmhlj9XvGE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yaniv Gardi , Subhash Jadavani , "Martin K. Petersen" , Amit Pundir Subject: [PATCH 3.18 76/83] scsi: ufs: fix bugs related to null pointer access and array size Date: Thu, 29 Nov 2018 15:12:34 +0100 Message-Id: <20181129140142.335334269@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140138.002176596@linuxfoundation.org> References: <20181129140138.002176596@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yaniv Gardi commit e3ce73d69aff44421d7899b235fec5ac2c306ff4 upstream. In this change there are a few fixes of possible NULL pointer access and possible access to index that exceeds array boundaries. Signed-off-by: Yaniv Gardi Signed-off-by: Subhash Jadavani Signed-off-by: Martin K. Petersen Signed-off-by: Amit Pundir Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/ufs/ufs.h | 3 ++- drivers/scsi/ufs/ufshcd.c | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -45,6 +45,7 @@ #define QUERY_DESC_MIN_SIZE 2 #define QUERY_OSF_SIZE (GENERAL_UPIU_REQUEST_SIZE - \ (sizeof(struct utp_upiu_header))) +#define RESPONSE_UPIU_SENSE_DATA_LENGTH 18 #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\ cpu_to_be32((byte3 << 24) | (byte2 << 16) |\ @@ -383,7 +384,7 @@ struct utp_cmd_rsp { __be32 residual_transfer_count; __be32 reserved[4]; __be16 sense_data_len; - u8 sense_data[18]; + u8 sense_data[RESPONSE_UPIU_SENSE_DATA_LENGTH]; }; /** --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -796,10 +796,14 @@ static inline void ufshcd_copy_sense_dat int len; if (lrbp->sense_buffer && ufshcd_get_rsp_upiu_data_seg_len(lrbp->ucd_rsp_ptr)) { + int len_to_copy; + len = be16_to_cpu(lrbp->ucd_rsp_ptr->sr.sense_data_len); + len_to_copy = min_t(int, RESPONSE_UPIU_SENSE_DATA_LENGTH, len); + memcpy(lrbp->sense_buffer, lrbp->ucd_rsp_ptr->sr.sense_data, - min_t(int, len, SCSI_SENSE_BUFFERSIZE)); + min_t(int, len_to_copy, SCSI_SENSE_BUFFERSIZE)); } } @@ -5161,7 +5165,10 @@ EXPORT_SYMBOL(ufshcd_system_suspend); int ufshcd_system_resume(struct ufs_hba *hba) { - if (!hba || !hba->is_powered || pm_runtime_suspended(hba->dev)) + if (!hba) + return -EINVAL; + + if (!hba->is_powered || pm_runtime_suspended(hba->dev)) /* * Let the runtime resume take care of resuming * if runtime suspended. @@ -5182,7 +5189,10 @@ EXPORT_SYMBOL(ufshcd_system_resume); */ int ufshcd_runtime_suspend(struct ufs_hba *hba) { - if (!hba || !hba->is_powered) + if (!hba) + return -EINVAL; + + if (!hba->is_powered) return 0; return ufshcd_suspend(hba, UFS_RUNTIME_PM); @@ -5212,10 +5222,13 @@ EXPORT_SYMBOL(ufshcd_runtime_suspend); */ int ufshcd_runtime_resume(struct ufs_hba *hba) { - if (!hba || !hba->is_powered) + if (!hba) + return -EINVAL; + + if (!hba->is_powered) return 0; - else - return ufshcd_resume(hba, UFS_RUNTIME_PM); + + return ufshcd_resume(hba, UFS_RUNTIME_PM); } EXPORT_SYMBOL(ufshcd_runtime_resume);