Skip to content

Commit e108b0a

Browse files
akky16gregkh
authored andcommitted
misc: amd-sbi: Address potential integer overflow issue reported in smatch
Smatch warnings are reported for below commit, Commit bb13a84 ("misc: amd-sbi: Add support for CPUID protocol") from Apr 28, 2025 (linux-next), leads to the following Smatch static checker warning: drivers/misc/amd-sbi/rmi-core.c:132 rmi_cpuid_read() warn: bitwise OR is zero '0xffffffff00000000 & 0xffff' drivers/misc/amd-sbi/rmi-core.c:132 rmi_cpuid_read() warn: potential integer overflow from user 'msg->cpu_in_out << 32' drivers/misc/amd-sbi/rmi-core.c:213 rmi_mca_msr_read() warn: bitwise OR is zero '0xffffffff00000000 & 0xffff' drivers/misc/amd-sbi/rmi-core.c:213 rmi_mca_msr_read() warn: potential integer overflow from user 'msg->mcamsr_in_out << 32' CPUID & MCAMSR thread data from input is available at byte 4 & 5, this patch fixes to copy the user data correctly in the argument. Previously, CPUID and MCAMSR data is return only for thread 0. Fixes: bb13a84 ("misc: amd-sbi: Add support for CPUID protocol") Fixes: 69b1ba8 ("misc: amd-sbi: Add support for read MCA register protocol") Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Reviewed-by: Naveen Krishna Chatradhi <[email protected]> Signed-off-by: Akshay Gupta <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1b98304 commit e108b0a

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/misc/amd-sbi/rmi-core.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#define RD_MCA_CMD 0x86
4343

4444
/* CPUID MCAMSR mask & index */
45-
#define CPUID_MCA_THRD_MASK GENMASK(15, 0)
4645
#define CPUID_MCA_THRD_INDEX 32
4746
#define CPUID_MCA_FUNC_MASK GENMASK(31, 0)
4847
#define CPUID_EXT_FUNC_INDEX 56
@@ -129,7 +128,7 @@ static int rmi_cpuid_read(struct sbrmi_data *data,
129128
goto exit_unlock;
130129
}
131130

132-
thread = msg->cpu_in_out << CPUID_MCA_THRD_INDEX & CPUID_MCA_THRD_MASK;
131+
thread = msg->cpu_in_out >> CPUID_MCA_THRD_INDEX;
133132

134133
/* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */
135134
if (thread > 127) {
@@ -210,7 +209,7 @@ static int rmi_mca_msr_read(struct sbrmi_data *data,
210209
goto exit_unlock;
211210
}
212211

213-
thread = msg->mcamsr_in_out << CPUID_MCA_THRD_INDEX & CPUID_MCA_THRD_MASK;
212+
thread = msg->mcamsr_in_out >> CPUID_MCA_THRD_INDEX;
214213

215214
/* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */
216215
if (thread > 127) {

0 commit comments

Comments
 (0)