linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bean Huo <huobean@gmail.com>
To: alim.akhtar@samsung.com, avri.altman@wdc.com,
	asutoshd@codeaurora.org, jejb@linux.ibm.com,
	martin.petersen@oracle.com, stanley.chu@mediatek.com,
	beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com,
	cang@codeaurora.org
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	beanhuo@outlook.com
Subject: [RESENT PATCH v5 3/5] scsi: ufs: fix potential access NULL pointer while memcpy
Date: Wed,  3 Jun 2020 11:19:57 +0200	[thread overview]
Message-ID: <20200603091959.27618-4-huobean@gmail.com> (raw)
In-Reply-To: <20200603091959.27618-1-huobean@gmail.com>

From: Bean Huo <beanhuo@micron.com>

If param_offset is not 0, the memcpy length shouldn't be the
true descriptor length.

Signed-off-by: Bean Huo <beanhuo@micron.com>
---
 drivers/scsi/ufs/ufshcd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index c18c2aadbe14..7163b268ed0b 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -3210,8 +3210,8 @@ int ufshcd_read_desc_param(struct ufs_hba *hba,
 	}
 
 	/* Check wherher we will not copy more data, than available */
-	if (is_kmalloc && param_size > buff_len)
-		param_size = buff_len;
+	if (is_kmalloc && (param_offset + param_size) > buff_len)
+		param_size = buff_len - param_offset;
 
 	if (is_kmalloc)
 		memcpy(param_read_buf, &desc_buf[param_offset], param_size);
-- 
2.17.1


  parent reply	other threads:[~2020-06-03  9:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03  9:19 [RESENT PATCH v5 0/5] scsi: ufs: cleanup ufs initialization Bean Huo
2020-06-03  9:19 ` [RESENT PATCH v5 1/5] scsi: ufs: remove max_t in ufs_get_device_desc Bean Huo
2020-06-03  9:19 ` [RESENT PATCH v5 2/5] scsi: ufs: delete ufshcd_read_desc() Bean Huo
2020-06-03  9:19 ` Bean Huo [this message]
2020-06-03  9:19 ` [RESENT PATCH v5 4/5] scsi: ufs: cleanup ufs initialization path Bean Huo
2020-06-03  9:19 ` [RESENT PATCH v5 5/5] scsi: ufs: add compatibility with 3.1 UFS unit descriptor length Bean Huo
2020-06-03 10:33 ` [RESENT PATCH v5 0/5] scsi: ufs: cleanup ufs initialization Avri Altman
2020-06-16  3:59 ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200603091959.27618-4-huobean@gmail.com \
    --to=huobean@gmail.com \
    --cc=alim.akhtar@samsung.com \
    --cc=asutoshd@codeaurora.org \
    --cc=avri.altman@wdc.com \
    --cc=beanhuo@micron.com \
    --cc=beanhuo@outlook.com \
    --cc=bvanassche@acm.org \
    --cc=cang@codeaurora.org \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stanley.chu@mediatek.com \
    --cc=tomas.winkler@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).