Commit 438bf726 authored by Colin Ian King's avatar Colin Ian King Committed by Greg Kroah-Hartman

ipmi_si: fix potential integer overflow on large shift

[ Upstream commit 97a103e6 ]

Shifting unsigned char b by an int type can lead to sign-extension
overflow. For example, if b is 0xff and the shift is 24, then top
bit is sign-extended so the final value passed to writeq has all
the upper 32 bits set.  Fix this by casting b to a 64 bit unsigned
before the shift.

Detected by CoverityScan, CID#1465246 ("Unintended sign extension")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarCorey Minyard <cminyard@mvista.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 78538bae
...@@ -51,7 +51,7 @@ static unsigned char mem_inq(const struct si_sm_io *io, unsigned int offset) ...@@ -51,7 +51,7 @@ static unsigned char mem_inq(const struct si_sm_io *io, unsigned int offset)
static void mem_outq(const struct si_sm_io *io, unsigned int offset, static void mem_outq(const struct si_sm_io *io, unsigned int offset,
unsigned char b) unsigned char b)
{ {
writeq(b << io->regshift, (io->addr)+(offset * io->regspacing)); writeq((u64)b << io->regshift, (io->addr)+(offset * io->regspacing));
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment