Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1526425pxb; Thu, 16 Sep 2021 09:14:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCRdOnU6ZLksg2EPceQElruzFdcSrer81vgUBFmavmCdrM17pINVlL2aQ1jjdsxmWjIJRa X-Received: by 2002:a05:6602:3284:: with SMTP id d4mr4931622ioz.100.1631808894970; Thu, 16 Sep 2021 09:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631808894; cv=none; d=google.com; s=arc-20160816; b=05lz95hvQyPKDggmUAvZmVBR7noOozZI1FHVJoMx+D62OIGUGEt/P5hjsBausxA+Bv q0cEmtLrjglJPoYRgGJq8mOMeljtgcZr29rHWFCTAa8j8ggWi9MBs+gQuUPDyF3ZCz1M AfMkoWosAicV6Lq9DPyFwGcd6CL+z0eOBFCPGXFAXY1QyxpzdHYsWJxdzOtBkF5ElSP6 f94ZOHSvDBcKY27QktslQtCFaSwC5ELsF2hYGp3ZhI//Qyxf+hS/dN6pcs61zZeFzGLK X1pMAAoOcqdUC/rjEKx/yWuB3RMvZdKdNm9rDV78f7ZEV6W10rP+n8i6Hg5YMBGxxEUY FFxw== 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=Th6kPS1QI698RrVDccqtohm6imtzSRuFVNuUYwxCNvo=; b=j3Yk81TLrvbTRhA3KL4MixC6/irLhAMOqMsGM8vB5o4/DNUxLY2yiyDaojkDKRqtB3 mpZ8paiq8n8+4f4PJPxNOr7wS9VRPfzaiuFPmBLy6CzrSCVlIbGB/HakESljMOQFGEU8 ZZdfaF/77wwMfpQ74BMUSX3MjkZkA4gHdp7AUKe34B/anvTkYtUO6b1cLHiA1xO45U/w L1kaczf8SNJHqkWf6yidfXrg9uk5pcS6RIO3iDTKOC0MoUEfLKzMe+LtssJhzrsyWyNP Uw5J5FWJzv6Zh5djbqih3cahqDb8X62V1XXtHD6BgmoMLu0B0pNwVKxIc63SD5iQoVfl 2NgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=chCiXVzu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x13si3215870ile.180.2021.09.16.09.14.43; Thu, 16 Sep 2021 09:14:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=chCiXVzu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231969AbhIPQMX (ORCPT + 99 others); Thu, 16 Sep 2021 12:12:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:47502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235072AbhIPQHf (ORCPT ); Thu, 16 Sep 2021 12:07:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 440A46127C; Thu, 16 Sep 2021 16:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808373; bh=YBCjnvBPJ660mg4CiNXoN5VQkn+Bj7j2lmfI8Xu6H5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=chCiXVzunX3I8YrR9MaT8zkrxUe9crTuVrXNtJPv+edbt8/i4x/kKw7uWNEfIpcIL UHbQFXkOhyeLsKbwzNZTi67rKlfO/rXUcHXO0I99pAEn1uXfxVTEu3xAZBau+veomf G1rMTDIVrxoWoARTd8wTBEFzPCLpTlp0bC4YU9cw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Avri Altman , Daejun Park , Bart Van Assche , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.10 066/306] scsi: ufs: Fix memory corruption by ufshcd_read_desc_param() Date: Thu, 16 Sep 2021 17:56:51 +0200 Message-Id: <20210916155756.311202825@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bart Van Assche [ Upstream commit d3d9c4570285090b533b00946b72647361f0345b ] If param_offset > buff_len then the memcpy() statement in ufshcd_read_desc_param() corrupts memory since it copies 256 + buff_len - param_offset bytes into a buffer with size buff_len. Since param_offset < 256 this results in writing past the bound of the output buffer. Link: https://lore.kernel.org/r/20210722033439.26550-2-bvanassche@acm.org Fixes: cbe193f6f093 ("scsi: ufs: Fix potential NULL pointer access during memcpy") Reviewed-by: Avri Altman Reviewed-by: Daejun Park Signed-off-by: Bart Van Assche Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/ufshcd.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 854c96e63007..4dabd09400c6 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3249,9 +3249,11 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, if (is_kmalloc) { /* Make sure we don't copy more data than available */ - if (param_offset + param_size > buff_len) - param_size = buff_len - param_offset; - memcpy(param_read_buf, &desc_buf[param_offset], param_size); + if (param_offset >= buff_len) + ret = -EINVAL; + else + memcpy(param_read_buf, &desc_buf[param_offset], + min_t(u32, param_size, buff_len - param_offset)); } out: if (is_kmalloc) -- 2.30.2