ipmi_si: fix potential integer overflow on large shift
authorColin Ian King <colin.king@canonical.com>
Tue, 5 Jun 2018 16:51:07 +0000 (17:51 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Nov 2019 17:46:56 +0000 (18:46 +0100)
commit438bf726def0f5bdc418b1c4ac038355a55f306a
treec912e1f60ea7448e7b570fcec2680bc7283509cb
parent78538bae1dab67036efaf9b675b60f1c2f5635b2
ipmi_si: fix potential integer overflow on large shift

[ Upstream commit 97a103e6b584442cd848887ed8d47be2410b7e09 ]

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: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Corey Minyard <cminyard@mvista.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/char/ipmi/ipmi_si_mem_io.c