Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2521753imu; Thu, 29 Nov 2018 06:21:34 -0800 (PST) X-Google-Smtp-Source: AFSGD/VxV2l3NbhKPzdIAf8Vwj60ALHyB9ls+9l+E8RHvo7S2jOuWaGsdvUFbKjDnAw7JJtroaE3 X-Received: by 2002:a17:902:e101:: with SMTP id cc1-v6mr1675792plb.165.1543501294349; Thu, 29 Nov 2018 06:21:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501294; cv=none; d=google.com; s=arc-20160816; b=l4BjzQCwfEBuIwsGAbvU8aFEnkuC3c2w5icXBFx32DelzWBYvey6exeYzPh4QDhHkR MJ6Y7XX+9DnXZrFXNs4pF+b3oSP7iYY7nScBLNF3SrZRNeKD2qYW5KvkKpM0hGGaesLV 36RrFhgoR7O4VZarH3RKLur3W8b9o0vaO5AauFGllGDHcX93qPphh6z7FLHuOeN9vqdc Qfc3MRDGmiJVkJgeUcvFFwJQbZZ8KZooMR6paIFFmpqRW29joTPk/AipYkyW8Iv0SpRD kUvCi0FJDFd2fscpLKXtInJIsFQmy9E4ZzQjOOtMrJ8PUrm/lifuOEaf8Xo9ckiQicbM 3/XQ== 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=bWNLtfCFmRBhAgl0L0Em/FX6QR3+7KDvRYfg3yDOHaM=; b=gvWLJtgV7Pw+/EIqNdKjVwcgirpt8qcgFTtdzpec/NF3J1kP8/rUCe+msWX8nXazX8 l+u9JNfIGERz649E45B7yrvwrqtJcwSEIkB4qbUT3gBwAgRrngEUHKvVEIkPs5apnNGD p5N41SvZGRlrxL4+mRLLUaTUUaVLVvD7ZPpfqDF0rqJG4IlcNcNZhqAA7z9omrWf4Dre +tQ14Xvdg7QCp7r7KFgpkuOuAV0CvbX6gofg3c3G0WLGqOLiv8CUSr/Ou4EPz2qXvPC/ l8DY5Fva4BkYdwrGI63VRRqM8u0mUffd+QIs3SNqeVMg3AiiCK9UVIGf3RfwvYEZrvSp +51w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tW5YBsGE; 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 f124si2416763pfa.1.2018.11.29.06.21.18; Thu, 29 Nov 2018 06:21:34 -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=tW5YBsGE; 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 S1731226AbeK3BZX (ORCPT + 99 others); Thu, 29 Nov 2018 20:25:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:48766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729806AbeK3BZW (ORCPT ); Thu, 29 Nov 2018 20:25:22 -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 C4B92205C9; Thu, 29 Nov 2018 14:19:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501191; bh=EksPdrTIg0KqakVwZRjni2EVAUrnCGNVJnbmPJzZGt0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tW5YBsGEHmEzePPOsZRN/2s1d0oD7i1rFAli9AJQAOhFFb9rk4/nrEvjBZHjdE9Vd nP5p4t9Ed1QyKDtXhEqoWU5UK4LC1QMXoi/noNEdEtkGF2NE3ELhvdwxPyJY4wbGtN Io20yP/RSuivNfEJu7BdRL0Jb/Pr1HS9umRimy+k= 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 4.4 73/86] scsi: ufs: fix bugs related to null pointer access and array size Date: Thu, 29 Nov 2018 15:12:38 +0100 Message-Id: <20181129140115.841524609@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140109.832117862@linuxfoundation.org> References: <20181129140109.832117862@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 4.4-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 @@ -813,10 +813,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)); } } @@ -5251,7 +5255,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. @@ -5272,7 +5279,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); @@ -5302,10 +5312,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);