[PATCH] EDAC/i10nm: shift exponent is negative

From: Koba Ko
Date: Wed Jun 28 2023 - 04:58:09 EST


UBSAN complains this error
~~~
UBSAN: shift-out-of-bounds in drivers/edac/skx_common.c:369:16
shift exponent -66 is negative
Call Trace:
<TASK>
dump_stack_lvl+0x48/0x70
dump_stack+0x10/0x20
__ubsan_handle_shift_out_of_bounds+0x1ac/0x360
skx_get_dimm_info.cold+0x91/0x175 [i10nm_edac]
? kvasprintf_const+0x2a/0xb0
i10nm_get_dimm_config+0x23c/0x340 [i10nm_edac]
skx_register_mci+0x139/0x1e0 [i10nm_edac]
? __pfx_i10nm_get_dimm_config+0x10/0x10 [i10nm_edac]
i10nm_init+0x403/0xd10 [i10nm_edac]
? __pfx_i10nm_init+0x10/0x10 [i10nm_edac]
do_one_initcall+0x5b/0x250
do_init_module+0x68/0x260
load_module+0xb45/0xcd0
? kernel_read_file+0x2a4/0x320
__do_sys_finit_module+0xc4/0x140
? __do_sys_finit_module+0xc4/0x140
__x64_sys_finit_module+0x18/0x30
do_syscall_64+0x58/0x90
? syscall_exit_to_user_mode+0x29/0x50
? do_syscall_64+0x67/0x90
? syscall_exit_to_user_mode+0x29/0x50
? do_syscall_64+0x67/0x90
? do_syscall_64+0x67/0x90
? __flush_smp_call_function_queue+0x122/0x1f0
? exit_to_user_mode_prepare+0x30/0xb0
? irqentry_exit_to_user_mode+0x9/0x20
? irqentry_exit+0x43/0x50
? sysvec_call_function+0x4b/0xd0
entry_SYSCALL_64_after_hwframe+0x72/0xdc
~~~

when get rows, cols and ranks, the returned error value doesn't be
handled.

check the return value is EINVAL, if yes, directly return 0.

Signed-off-by: Koba Ko <koba.ko@xxxxxxxxxxxxx>
---
drivers/edac/skx_common.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/edac/skx_common.c b/drivers/edac/skx_common.c
index 2a00e0503f0d5..98baed1617c9f 100644
--- a/drivers/edac/skx_common.c
+++ b/drivers/edac/skx_common.c
@@ -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;

if (imc->hbm_mc) {
banks = 32;
--
2.34.1