RE: [PATCH] EDAC/skx_common: Fix potential negative values in DIMM size calculation

From: Zhuo, Qiuxu
Date: Wed Jul 30 2025 - 03:56:45 EST


Hi AceLan,

> From: AceLan Kao <acelan@xxxxxxxxx> On Behalf Of Chia-Lin Kao (AceLan)
> Sent: Wednesday, July 30, 2025 2:32 PM
> To: Luck, Tony <tony.luck@xxxxxxxxx>; Borislav Petkov <bp@xxxxxxxxx>; James
> Morse <james.morse@xxxxxxx>; Mauro Carvalho Chehab
> <mchehab@xxxxxxxxxx>; Robert Richter <rric@xxxxxxxxxx>; Zhuo, Qiuxu
> <qiuxu.zhuo@xxxxxxxxx>; linux-edac@xxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx
> Subject: [PATCH] EDAC/skx_common: Fix potential negative values in DIMM
> size calculation
>
> The skx_get_dimm_attr() function can return a negative error code, which is
> then assigned to 'ranks', 'rows', or 'cols'.
>
> [ 9.344702] EDAC DEBUG: skx_get_dimm_attr: bad ranks = 3 (raw=0xffffffff)
> [ 9.344703] EDAC DEBUG: skx_get_dimm_attr: bad rows = 7 (raw=0xffffffff)
> [ 9.344703] EDAC DEBUG: skx_get_dimm_attr: bad cols = 3 (raw=0xffffffff)
> [ 9.344704] ------------[ cut here ]------------
> [ 9.344705] UBSAN: shift-out-of-bounds in
> drivers/edac/skx_common.c:453:2
> [ 9.344707] shift exponent -66 is negative
>
> The 3 values, rows, cols, and ranks are all -EINVAL(-22), so this line
> (1ull << (rows + cols + ranks)
> would become
> (1ull << ((-22) + (-22) + (-22))
> Which leads to shift exponent -66 error
>
> Add a check to ensure that 'ranks', 'rows', and 'cols' are not negative before
> they are used in the size calculation. This prevents the use of invalid values.
>
> Fixes: 88a242c98740 ("EDAC, skx_common: Separate common code out from
> skx_edac")
> Signed-off-by: Chia-Lin Kao (AceLan) <acelan.kao@xxxxxxxxxxxxx>
>

Thanks for reporting this.

Which CPU did you test it on?
Would you mind taking a complete dmesg log with the kernel option
CONFIG_EDAC_DEBUG=y (your current log showed this option had been enabled)?

Thanks!
-Qiuxu