Re: [PATCH][V2] EDAC/i10nm: shift exponent is negative

From: Koba Ko
Date: Tue Jul 04 2023 - 08:33:24 EST


On Tue, Jul 4, 2023 at 8:02 PM Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
>
> Here is a better commit message. You can just copy and paste it.
> ------------------------------------------
> [PATCH v3] EDAC/i10nm: Prevent negative shifts in skx_get_dimm_info().
>
> UBSAN generated the following warning during a timeout:
>
> UBSAN: shift-out-of-bounds in drivers/edac/skx_common.c:369:16
> shift exponent -66 is negative
>
> That most likely means that rows, cols, and ranks were all set to
> -EINVAL. Address this in two ways.
>
> 1) Change the debug output in skx_get_dimm_attr() to KERN_ERR so that
> users will know where exactly the error is.
> 2) Add a check for errors in skx_get_dimm_info().
>
> Fixes: 88a242c98740 ("EDAC, skx_common: Separate common code out from skx_edac")
> Signed-off-by:
> -----------------------------------------------

have sent V3 as per Markus' comments.
https://patchwork.kernel.org/project/linux-edac/patch/20230704095939.119620-1-koba.ko@xxxxxxxxxxxxx/
Thanks
>
> > @@ -351,6 +351,8 @@ int skx_get_dimm_info(u32 mtr, u32 mcmtr, u32 amap, struct dimm_info *dimm,
> > ranks = numrank(mtr);
> > rows = numrow(mtr);
> > cols = imc->hbm_mc ? 6 : numcol(mtr);
> > + if (ranks == -EINVAL || rows == -EINVAL || cols == -EINVAL)
> > + return 0;
>
> Change this to:
>
> if (rangks < 0 || rows < 0 || cols < 0)
> return 0;
>
> It's bad form to check for a specific error code unless there is a need.
>
> regards,
> dan carpenter
>