]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
EDAC/{skx_common,skx}: Fix UBSAN shift-out-of-bounds in skx_get_dimm_info
authorzhoumin <teczm@foxmail.com>
Thu, 26 Mar 2026 09:14:03 +0000 (17:14 +0800)
committerTony Luck <tony.luck@intel.com>
Fri, 29 May 2026 15:34:12 +0000 (08:34 -0700)
When the skx_get_dimm_attr() helper returns -EINVAL,
skx_get_dimm_info() does not validate these return values before using
them in a shift operation:

    size = ((1ull << (rows + cols + ranks)) * banks) >> (20 - 3);

If all three values are -22, the shift exponent becomes -66, triggering
a UBSAN shift-out-of-bounds error:

    UBSAN: shift-out-of-bounds in drivers/edac/skx_common.c
    shift exponent -66 is negative

Fixes: 88a242c98740 ("EDAC, skx_common: Separate common code out from skx_edac")
Signed-off-by: zhoumin <teczm@foxmail.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
Link: https://patch.msgid.link/tencent_2A0CC835A18366643CBD2865B169948AB409@qq.com
drivers/edac/skx_common.c

index a9557c8344bc133ecc8c5343b4a44e07cbe89682..f15de0ea96c87e1e63a45fb5c409c22548f65bf0 100644 (file)
@@ -466,6 +466,9 @@ int skx_get_dimm_info(u32 mtr, u32 mcmtr, u32 amap, struct dimm_info *dimm,
        rows = numrow(mtr);
        cols = imc->hbm_mc ? 6 : numcol(mtr);
 
+       if (ranks < 0 || rows < 0 || cols < 0)
+               return 0;
+
        if (imc->hbm_mc) {
                banks = 32;
                mtype = MEM_HBM2;