LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] scsi: bnx2fc: fix incorrect cast to u64 on shift operation
@ 2019-05-04 16:48 Colin King
  2019-05-08  8:56 ` Saurav Kashyap
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Colin King @ 2019-05-04 16:48 UTC (permalink / raw)
  To: QLogic-Storage-Upstream, James E . J . Bottomley,
	Martin K . Petersen, linux-scsi
  Cc: kernel-janitors, linux-kernel

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

Currently an int is being shifted and the result is being cast to a u64
which leads to undefined behaviour if the shift is more than 31 bits. Fix
this by casting the integer value 1 to u64 before the shift operation.

Addresses-Coverity: ("Bad shift operation")
Fixes: 7b594769120b ("[SCSI] bnx2fc: Handle REC_TOV error code from firmware")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/scsi/bnx2fc/bnx2fc_hwi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/bnx2fc/bnx2fc_hwi.c b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
index 19734ec7f42e..747f019fb393 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_hwi.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
@@ -830,7 +830,7 @@ static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
 			((u64)err_entry->data.err_warn_bitmap_hi << 32) |
 			(u64)err_entry->data.err_warn_bitmap_lo;
 		for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
-			if (err_warn_bit_map & (u64) (1 << i)) {
+			if (err_warn_bit_map & ((u64)1 << i)) {
 				err_warn = i;
 				break;
 			}
-- 
2.20.1


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

* Re: [PATCH] scsi: bnx2fc: fix incorrect cast to u64 on shift operation
  2019-05-04 16:48 [PATCH] scsi: bnx2fc: fix incorrect cast to u64 on shift operation Colin King
@ 2019-05-08  8:56 ` Saurav Kashyap
  2019-05-08  9:35 ` Christophe JAILLET
  2019-05-14 17:12 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Saurav Kashyap @ 2019-05-08  8:56 UTC (permalink / raw)
  To: Colin King, QLogic-Storage-Upstream, James E . J . Bottomley,
	Martin K . Petersen, linux-scsi
  Cc: kernel-janitors, linux-kernel



-----Original Message-----
From: <linux-scsi-owner@vger.kernel.org> on behalf of Colin King
<colin.king@canonical.com>
Date: Saturday, 4 May 2019 at 10:18 PM
To: "QLogic-Storage-Upstream@qlogic.com"
<QLogic-Storage-Upstream@qlogic.com>, "James E . J . Bottomley"
<jejb@linux.ibm.com>, "Martin K . Petersen" <martin.petersen@oracle.com>,
"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>
Cc: "kernel-janitors@vger.kernel.org" <kernel-janitors@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH] scsi: bnx2fc: fix incorrect cast to u64 on shift operation

>From: Colin Ian King <colin.king@canonical.com>
>
>Currently an int is being shifted and the result is being cast to a u64
>which leads to undefined behaviour if the shift is more than 31 bits. Fix
>this by casting the integer value 1 to u64 before the shift operation.
>
>Addresses-Coverity: ("Bad shift operation")
>Fixes: 7b594769120b ("[SCSI] bnx2fc: Handle REC_TOV error code from
>firmware")
>Signed-off-by: Colin Ian King <colin.king@canonical.com>
>---
> drivers/scsi/bnx2fc/bnx2fc_hwi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/drivers/scsi/bnx2fc/bnx2fc_hwi.c
>b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
>index 19734ec7f42e..747f019fb393 100644
>--- a/drivers/scsi/bnx2fc/bnx2fc_hwi.c
>+++ b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
>@@ -830,7 +830,7 @@ static void bnx2fc_process_unsol_compl(struct
>bnx2fc_rport *tgt, u16 wqe)
> 			((u64)err_entry->data.err_warn_bitmap_hi << 32) |
> 			(u64)err_entry->data.err_warn_bitmap_lo;
> 		for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
>-			if (err_warn_bit_map & (u64) (1 << i)) {
>+			if (err_warn_bit_map & ((u64)1 << i)) {
> 				err_warn = i;
> 				break;
> 			}
>-- 
>2.20.1

Thanks for the Patch.

Acked-by: Saurav Kashyap <skashyap@marvell.com>

>


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

* Re: [PATCH] scsi: bnx2fc: fix incorrect cast to u64 on shift operation
  2019-05-04 16:48 [PATCH] scsi: bnx2fc: fix incorrect cast to u64 on shift operation Colin King
  2019-05-08  8:56 ` Saurav Kashyap
@ 2019-05-08  9:35 ` Christophe JAILLET
  2019-05-14 17:12 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2019-05-08  9:35 UTC (permalink / raw)
  To: Colin King, QLogic-Storage-Upstream, James E . J . Bottomley,
	Martin K . Petersen, linux-scsi
  Cc: kernel-janitors, linux-kernel

Le 04/05/2019 à 18:48, Colin King a écrit :
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently an int is being shifted and the result is being cast to a u64
> which leads to undefined behaviour if the shift is more than 31 bits. Fix
> this by casting the integer value 1 to u64 before the shift operation.
>
> Addresses-Coverity: ("Bad shift operation")
> Fixes: 7b594769120b ("[SCSI] bnx2fc: Handle REC_TOV error code from firmware")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   drivers/scsi/bnx2fc/bnx2fc_hwi.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/bnx2fc/bnx2fc_hwi.c b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
> index 19734ec7f42e..747f019fb393 100644
> --- a/drivers/scsi/bnx2fc/bnx2fc_hwi.c
> +++ b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
> @@ -830,7 +830,7 @@ static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
>   			((u64)err_entry->data.err_warn_bitmap_hi << 32) |
>   			(u64)err_entry->data.err_warn_bitmap_lo;
>   		for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
> -			if (err_warn_bit_map & (u64) (1 << i)) {
> +			if (err_warn_bit_map & ((u64)1 << i)) {
>   				err_warn = i;
>   				break;
>   			}


Hi, just for the records and if you need additional ack, see

    https://lkml.org/lkml/2016/11/26/172

just my 2c :-)

CJ


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

* Re: [PATCH] scsi: bnx2fc: fix incorrect cast to u64 on shift operation
  2019-05-04 16:48 [PATCH] scsi: bnx2fc: fix incorrect cast to u64 on shift operation Colin King
  2019-05-08  8:56 ` Saurav Kashyap
  2019-05-08  9:35 ` Christophe JAILLET
@ 2019-05-14 17:12 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2019-05-14 17:12 UTC (permalink / raw)
  To: Colin King
  Cc: QLogic-Storage-Upstream, James E . J . Bottomley,
	Martin K . Petersen, linux-scsi, kernel-janitors, linux-kernel


Colin,

> Currently an int is being shifted and the result is being cast to a
> u64 which leads to undefined behaviour if the shift is more than 31
> bits. Fix this by casting the integer value 1 to u64 before the shift
> operation.

Applied to 5.2/scsi-fixes, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2019-05-14 17:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-04 16:48 [PATCH] scsi: bnx2fc: fix incorrect cast to u64 on shift operation Colin King
2019-05-08  8:56 ` Saurav Kashyap
2019-05-08  9:35 ` Christophe JAILLET
2019-05-14 17:12 ` 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).