kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8
@ 2021-06-21 15:17 Colin King
  2021-06-23  1:17 ` Martin K. Petersen
  2021-06-29  4:10 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2021-06-21 15:17 UTC (permalink / raw)
  To: Hannes Reinecke, James E . J . Bottomley, Martin K . Petersen,
	linux-scsi
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The shifting of the u8 integer returned fom ahc_inb(ahc, port+3) by
24 bits to the left will be promoted to a 32 bit signed int and then
sign-extended to a u64. In the event that the top bit of the u8
is set then all then all the upper 32 bits of the u64 end up as
also being set because of the sign-extension. Fix this by
casting the u8 values to a u64 before the 24 bit left shift.

[ This dates back to 2002, I found the offending commit from the git
history git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git,
commit f58eb66c0b0a ("Update aic7xxx driver to 6.2.10...") ]

Addresses-Coverity: ("Unintended sign extension")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/scsi/aic7xxx/aic7xxx_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c
index 4b04ab8908f8..a396f048a031 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -493,7 +493,7 @@ ahc_inq(struct ahc_softc *ahc, u_int port)
 	return ((ahc_inb(ahc, port))
 	      | (ahc_inb(ahc, port+1) << 8)
 	      | (ahc_inb(ahc, port+2) << 16)
-	      | (ahc_inb(ahc, port+3) << 24)
+	      | (((uint64_t)ahc_inb(ahc, port+3)) << 24)
 	      | (((uint64_t)ahc_inb(ahc, port+4)) << 32)
 	      | (((uint64_t)ahc_inb(ahc, port+5)) << 40)
 	      | (((uint64_t)ahc_inb(ahc, port+6)) << 48)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8
  2021-06-21 15:17 [PATCH] scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8 Colin King
@ 2021-06-23  1:17 ` Martin K. Petersen
  2021-06-29  4:10 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2021-06-23  1:17 UTC (permalink / raw)
  To: Colin King
  Cc: Hannes Reinecke, James E . J . Bottomley, Martin K . Petersen,
	linux-scsi, kernel-janitors, linux-kernel


Colin,

> The shifting of the u8 integer returned fom ahc_inb(ahc, port+3) by 24
> bits to the left will be promoted to a 32 bit signed int and then
> sign-extended to a u64.

Applied to 5.14/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8
  2021-06-21 15:17 [PATCH] scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8 Colin King
  2021-06-23  1:17 ` Martin K. Petersen
@ 2021-06-29  4:10 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2021-06-29  4:10 UTC (permalink / raw)
  To: linux-scsi, Colin King, Hannes Reinecke, James E . J . Bottomley
  Cc: Martin K . Petersen, kernel-janitors, linux-kernel

On Mon, 21 Jun 2021 16:17:27 +0100, Colin King wrote:

> The shifting of the u8 integer returned fom ahc_inb(ahc, port+3) by
> 24 bits to the left will be promoted to a 32 bit signed int and then
> sign-extended to a u64. In the event that the top bit of the u8
> is set then all then all the upper 32 bits of the u64 end up as
> also being set because of the sign-extension. Fix this by
> casting the u8 values to a u64 before the 24 bit left shift.
> 
> [...]

Applied to 5.14/scsi-queue, thanks!

[1/1] scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8
      https://git.kernel.org/mkp/scsi/c/332a9dd1d86f

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-29  4:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21 15:17 [PATCH] scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8 Colin King
2021-06-23  1:17 ` Martin K. Petersen
2021-06-29  4:10 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).