All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] mlxsw: spectrum_trap: fix unintention integer overflow on left shift
@ 2020-04-02 14:48 ` Colin King
  0 siblings, 0 replies; 10+ messages in thread
From: Colin King @ 2020-04-02 14:48 UTC (permalink / raw)
  To: Jiri Pirko, Ido Schimmel, David S . Miller, netdev
  Cc: kernel-janitors, linux-kernel

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

Shifting the integer value 1 is evaluated using 32-bit
arithmetic and then used in an expression that expects a 64-bit
value, so there is potentially an integer overflow. Fix this
by using the BIT_ULL macro to perform the shift and avoid the
overflow.

Addresses-Coverity: ("Unintentional integer overflow")
Fixes: 13f2e64b94ea ("mlxsw: spectrum_trap: Add devlink-trap policer support")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
index 9096ffd89e50..fbf714d027d8 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
@@ -643,7 +643,7 @@ static int mlxsw_sp_trap_policer_bs(u64 burst, u8 *p_burst_size,
 {
 	int bs = fls64(burst) - 1;
 
-	if (burst != (1 << bs)) {
+	if (burst != (BIT_ULL(bs))) {
 		NL_SET_ERR_MSG_MOD(extack, "Policer burst size is not power of two");
 		return -EINVAL;
 	}
-- 
2.25.1


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

* [PATCH][next] mlxsw: spectrum_trap: fix unintention integer overflow on left shift
@ 2020-04-02 14:48 ` Colin King
  0 siblings, 0 replies; 10+ messages in thread
From: Colin King @ 2020-04-02 14:48 UTC (permalink / raw)
  To: Jiri Pirko, Ido Schimmel, David S . Miller, netdev
  Cc: kernel-janitors, linux-kernel

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

Shifting the integer value 1 is evaluated using 32-bit
arithmetic and then used in an expression that expects a 64-bit
value, so there is potentially an integer overflow. Fix this
by using the BIT_ULL macro to perform the shift and avoid the
overflow.

Addresses-Coverity: ("Unintentional integer overflow")
Fixes: 13f2e64b94ea ("mlxsw: spectrum_trap: Add devlink-trap policer support")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
index 9096ffd89e50..fbf714d027d8 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
@@ -643,7 +643,7 @@ static int mlxsw_sp_trap_policer_bs(u64 burst, u8 *p_burst_size,
 {
 	int bs = fls64(burst) - 1;
 
-	if (burst != (1 << bs)) {
+	if (burst != (BIT_ULL(bs))) {
 		NL_SET_ERR_MSG_MOD(extack, "Policer burst size is not power of two");
 		return -EINVAL;
 	}
-- 
2.25.1

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

* Re: [PATCH][next] mlxsw: spectrum_trap: fix unintention integer overflow on left shift
  2020-04-02 14:48 ` Colin King
@ 2020-04-02 15:48   ` Ido Schimmel
  -1 siblings, 0 replies; 10+ messages in thread
From: Ido Schimmel @ 2020-04-02 15:48 UTC (permalink / raw)
  To: Colin King
  Cc: Jiri Pirko, David S . Miller, netdev, kernel-janitors, linux-kernel

On Thu, Apr 02, 2020 at 03:48:51PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Shifting the integer value 1 is evaluated using 32-bit
> arithmetic and then used in an expression that expects a 64-bit
> value, so there is potentially an integer overflow. Fix this
> by using the BIT_ULL macro to perform the shift and avoid the
> overflow.
> 
> Addresses-Coverity: ("Unintentional integer overflow")
> Fixes: 13f2e64b94ea ("mlxsw: spectrum_trap: Add devlink-trap policer support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

For net:

Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Tested-by: Ido Schimmel <idosch@mellanox.com>

Thanks

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

* Re: [PATCH][next] mlxsw: spectrum_trap: fix unintention integer overflow on left shift
@ 2020-04-02 15:48   ` Ido Schimmel
  0 siblings, 0 replies; 10+ messages in thread
From: Ido Schimmel @ 2020-04-02 15:48 UTC (permalink / raw)
  To: Colin King
  Cc: Jiri Pirko, David S . Miller, netdev, kernel-janitors, linux-kernel

On Thu, Apr 02, 2020 at 03:48:51PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Shifting the integer value 1 is evaluated using 32-bit
> arithmetic and then used in an expression that expects a 64-bit
> value, so there is potentially an integer overflow. Fix this
> by using the BIT_ULL macro to perform the shift and avoid the
> overflow.
> 
> Addresses-Coverity: ("Unintentional integer overflow")
> Fixes: 13f2e64b94ea ("mlxsw: spectrum_trap: Add devlink-trap policer support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

For net:

Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Tested-by: Ido Schimmel <idosch@mellanox.com>

Thanks

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

* Re: [PATCH][next] mlxsw: spectrum_trap: fix unintention integer overflow on left shift
  2020-04-02 14:48 ` Colin King
@ 2020-04-03  1:00   ` David Miller
  -1 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2020-04-03  1:00 UTC (permalink / raw)
  To: colin.king; +Cc: jiri, idosch, netdev, kernel-janitors, linux-kernel

From: Colin King <colin.king@canonical.com>
Date: Thu,  2 Apr 2020 15:48:51 +0100

> From: Colin Ian King <colin.king@canonical.com>
> 
> Shifting the integer value 1 is evaluated using 32-bit
> arithmetic and then used in an expression that expects a 64-bit
> value, so there is potentially an integer overflow. Fix this
> by using the BIT_ULL macro to perform the shift and avoid the
> overflow.
> 
> Addresses-Coverity: ("Unintentional integer overflow")
> Fixes: 13f2e64b94ea ("mlxsw: spectrum_trap: Add devlink-trap policer support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied, thanks.

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

* Re: [PATCH][next] mlxsw: spectrum_trap: fix unintention integer overflow on left shift
@ 2020-04-03  1:00   ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2020-04-03  1:00 UTC (permalink / raw)
  To: colin.king; +Cc: jiri, idosch, netdev, kernel-janitors, linux-kernel

From: Colin King <colin.king@canonical.com>
Date: Thu,  2 Apr 2020 15:48:51 +0100

> From: Colin Ian King <colin.king@canonical.com>
> 
> Shifting the integer value 1 is evaluated using 32-bit
> arithmetic and then used in an expression that expects a 64-bit
> value, so there is potentially an integer overflow. Fix this
> by using the BIT_ULL macro to perform the shift and avoid the
> overflow.
> 
> Addresses-Coverity: ("Unintentional integer overflow")
> Fixes: 13f2e64b94ea ("mlxsw: spectrum_trap: Add devlink-trap policer support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied, thanks.

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

* Re: [PATCH][next] mlxsw: spectrum_trap: fix unintention integer overflow on left shift
  2020-04-02 14:48 ` Colin King
@ 2020-04-03  8:46   ` Dan Carpenter
  -1 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2020-04-03  8:46 UTC (permalink / raw)
  To: Colin King
  Cc: Jiri Pirko, Ido Schimmel, David S . Miller, netdev,
	kernel-janitors, linux-kernel

On Thu, Apr 02, 2020 at 03:48:51PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Shifting the integer value 1 is evaluated using 32-bit
> arithmetic and then used in an expression that expects a 64-bit
> value, so there is potentially an integer overflow. Fix this
> by using the BIT_ULL macro to perform the shift and avoid the
> overflow.
> 
> Addresses-Coverity: ("Unintentional integer overflow")
> Fixes: 13f2e64b94ea ("mlxsw: spectrum_trap: Add devlink-trap policer support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> index 9096ffd89e50..fbf714d027d8 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> @@ -643,7 +643,7 @@ static int mlxsw_sp_trap_policer_bs(u64 burst, u8 *p_burst_size,
>  {
>  	int bs = fls64(burst) - 1;
>  
> -	if (burst != (1 << bs)) {
> +	if (burst != (BIT_ULL(bs))) {

Please delete the extra parentheses.

	if (burst != BIT_ULL(bs)) {

regards,
dan carpenter


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

* Re: [PATCH][next] mlxsw: spectrum_trap: fix unintention integer overflow on left shift
@ 2020-04-03  8:46   ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2020-04-03  8:46 UTC (permalink / raw)
  To: Colin King
  Cc: Jiri Pirko, Ido Schimmel, David S . Miller, netdev,
	kernel-janitors, linux-kernel

On Thu, Apr 02, 2020 at 03:48:51PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Shifting the integer value 1 is evaluated using 32-bit
> arithmetic and then used in an expression that expects a 64-bit
> value, so there is potentially an integer overflow. Fix this
> by using the BIT_ULL macro to perform the shift and avoid the
> overflow.
> 
> Addresses-Coverity: ("Unintentional integer overflow")
> Fixes: 13f2e64b94ea ("mlxsw: spectrum_trap: Add devlink-trap policer support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> index 9096ffd89e50..fbf714d027d8 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> @@ -643,7 +643,7 @@ static int mlxsw_sp_trap_policer_bs(u64 burst, u8 *p_burst_size,
>  {
>  	int bs = fls64(burst) - 1;
>  
> -	if (burst != (1 << bs)) {
> +	if (burst != (BIT_ULL(bs))) {

Please delete the extra parentheses.

	if (burst != BIT_ULL(bs)) {

regards,
dan carpenter

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

* Re: [PATCH][next] mlxsw: spectrum_trap: Fix unintentional integer overflow on left shift
  2020-04-02 14:48 ` Colin King
@ 2020-04-03 16:05 ` Markus Elfring
  -1 siblings, 0 replies; 10+ messages in thread
From: Markus Elfring @ 2020-04-03 16:05 UTC (permalink / raw)
  To: Colin Ian King, David S. Miller, Ido Schimmel, Jiri Pirko, netdev
  Cc: kernel-janitors, linux-kernel

> Addresses-Coverity: ("Unintentional integer overflow")

Will a slightly different commit subject be more appropriate
according to such information?

Regards,
Markus

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

* Re: [PATCH][next] mlxsw: spectrum_trap: Fix unintentional integer overflow on left shift
@ 2020-04-03 16:05 ` Markus Elfring
  0 siblings, 0 replies; 10+ messages in thread
From: Markus Elfring @ 2020-04-03 16:05 UTC (permalink / raw)
  To: Colin Ian King, David S. Miller, Ido Schimmel, Jiri Pirko, netdev
  Cc: kernel-janitors, linux-kernel

> Addresses-Coverity: ("Unintentional integer overflow")

Will a slightly different commit subject be more appropriate
according to such information?

Regards,
Markus

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

end of thread, other threads:[~2020-04-03 16:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-03 16:05 [PATCH][next] mlxsw: spectrum_trap: Fix unintentional integer overflow on left shift Markus Elfring
2020-04-03 16:05 ` Markus Elfring
  -- strict thread matches above, loose matches on Subject: below --
2020-04-02 14:48 [PATCH][next] mlxsw: spectrum_trap: fix unintention " Colin King
2020-04-02 14:48 ` Colin King
2020-04-02 15:48 ` Ido Schimmel
2020-04-02 15:48   ` Ido Schimmel
2020-04-03  1:00 ` David Miller
2020-04-03  1:00   ` David Miller
2020-04-03  8:46 ` Dan Carpenter
2020-04-03  8:46   ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.