2020-12-11 19:42:38

by Jaegeuk Kim

[permalink] [raw]
Subject: [PATCH] scsi: ufs: fix memory boundary check for UFS 3.0

From: Jaegeuk Kim <[email protected]>

If param_offset is greater than what UFS supports, it'll give kernel panic.

Signed-off-by: Jaegeuk Kim <[email protected]>
Change-Id: I48ea6f3f3074bd42abf4ecf8be87806732f3e6a3
---
drivers/scsi/ufs/ufshcd.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index d6a3a0ba6960..04687661d0df 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -3194,6 +3194,9 @@ int ufshcd_read_desc_param(struct ufs_hba *hba,
return -EINVAL;
}

+ if (param_offset > buff_len)
+ return -EINVAL;
+
/* Check whether we need temp memory */
if (param_offset != 0 || param_size < buff_len) {
desc_buf = kmalloc(buff_len, GFP_KERNEL);
--
2.29.2.576.ga3fc446d84-goog


2020-12-13 02:47:53

by Eric Biggers

[permalink] [raw]
Subject: Re: [PATCH] scsi: ufs: fix memory boundary check for UFS 3.0

On Fri, Dec 11, 2020 at 11:38:14AM -0800, Jaegeuk Kim wrote:
> From: Jaegeuk Kim <[email protected]>
>
> If param_offset is greater than what UFS supports, it'll give kernel panic.
>
> Signed-off-by: Jaegeuk Kim <[email protected]>
> Change-Id: I48ea6f3f3074bd42abf4ecf8be87806732f3e6a3
> ---
> drivers/scsi/ufs/ufshcd.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index d6a3a0ba6960..04687661d0df 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -3194,6 +3194,9 @@ int ufshcd_read_desc_param(struct ufs_hba *hba,
> return -EINVAL;
> }
>
> + if (param_offset > buff_len)
> + return -EINVAL;
> +
> /* Check whether we need temp memory */
> if (param_offset != 0 || param_size < buff_len) {
> desc_buf = kmalloc(buff_len, GFP_KERNEL);
> --

Didn't this already get fixed by:

commit 1699f980d87fb678a669490462cf0b9517c1fb47
Author: Can Guo <[email protected]>
Date: Wed Oct 21 22:59:00 2020 -0700

scsi: ufs: Fix unexpected values from ufshcd_read_desc_param()

2020-12-13 02:50:41

by Jaegeuk Kim

[permalink] [raw]
Subject: Re: [PATCH] scsi: ufs: fix memory boundary check for UFS 3.0

On 12/11, Eric Biggers wrote:
> On Fri, Dec 11, 2020 at 11:38:14AM -0800, Jaegeuk Kim wrote:
> > From: Jaegeuk Kim <[email protected]>
> >
> > If param_offset is greater than what UFS supports, it'll give kernel panic.
> >
> > Signed-off-by: Jaegeuk Kim <[email protected]>
> > Change-Id: I48ea6f3f3074bd42abf4ecf8be87806732f3e6a3
> > ---
> > drivers/scsi/ufs/ufshcd.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> > index d6a3a0ba6960..04687661d0df 100644
> > --- a/drivers/scsi/ufs/ufshcd.c
> > +++ b/drivers/scsi/ufs/ufshcd.c
> > @@ -3194,6 +3194,9 @@ int ufshcd_read_desc_param(struct ufs_hba *hba,
> > return -EINVAL;
> > }
> >
> > + if (param_offset > buff_len)
> > + return -EINVAL;
> > +
> > /* Check whether we need temp memory */
> > if (param_offset != 0 || param_size < buff_len) {
> > desc_buf = kmalloc(buff_len, GFP_KERNEL);
> > --
>
> Didn't this already get fixed by:
>
> commit 1699f980d87fb678a669490462cf0b9517c1fb47
> Author: Can Guo <[email protected]>
> Date: Wed Oct 21 22:59:00 2020 -0700
>
> scsi: ufs: Fix unexpected values from ufshcd_read_desc_param()

Oh, cool. Yes, please ignore this.

Thanks,