netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] net/mlx5: fix unintentional sign extension on shift of dest_attr->vport.vhca_id
@ 2025-01-16 18:17 Colin Ian King
  2025-01-17 10:58 ` Simon Horman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Colin Ian King @ 2025-01-16 18:17 UTC (permalink / raw)
  To: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Andrew Lunn,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Moshe Shemesh, Yevgeny Kliteynik, Mark Bloch, netdev, linux-rdma
  Cc: kernel-janitors, linux-kernel

Shifting dest_attr->vport.vhca_id << 16 results in a promotion from an
unsigned 16 bit integer to a 32 bit signed integer, this is then sign
extended to a 64 bit unsigned long on 64 bitarchitectures. If vhca_id is
greater than 0x7fff then this leads to a sign extended result where all
the upper 32 bits of idx are set to 1. Fix this by casting vhca_id
to the same type as idx before performing the shift.

Fixes: 8e2e08a6d1e0 ("net/mlx5: fs, add support for dest vport HWS action")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
index 05329afeb9ea..f34bbbbba1c2 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
@@ -417,7 +417,7 @@ mlx5_fs_get_dest_action_vport(struct mlx5_fs_hws_context *fs_ctx,
 	vport_num = is_dest_type_uplink ? MLX5_VPORT_UPLINK : dest_attr->vport.num;
 	if (vhca_id_valid) {
 		dests_xa = &fs_ctx->hws_pool.vport_vhca_dests;
-		idx = dest_attr->vport.vhca_id << 16 | vport_num;
+		idx = (unsigned long)dest_attr->vport.vhca_id << 16 | vport_num;
 	} else {
 		dests_xa = &fs_ctx->hws_pool.vport_dests;
 		idx = vport_num;
-- 
2.47.1


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

* Re: [PATCH][next] net/mlx5: fix unintentional sign extension on shift of dest_attr->vport.vhca_id
  2025-01-16 18:17 [PATCH][next] net/mlx5: fix unintentional sign extension on shift of dest_attr->vport.vhca_id Colin Ian King
@ 2025-01-17 10:58 ` Simon Horman
  2025-01-17 11:44 ` Moshe Shemesh
  2025-01-18  4:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2025-01-17 10:58 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Andrew Lunn,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Moshe Shemesh, Yevgeny Kliteynik, Mark Bloch, netdev, linux-rdma,
	kernel-janitors, linux-kernel

On Thu, Jan 16, 2025 at 06:17:00PM +0000, Colin Ian King wrote:
> Shifting dest_attr->vport.vhca_id << 16 results in a promotion from an
> unsigned 16 bit integer to a 32 bit signed integer, this is then sign
> extended to a 64 bit unsigned long on 64 bitarchitectures. If vhca_id is
> greater than 0x7fff then this leads to a sign extended result where all
> the upper 32 bits of idx are set to 1. Fix this by casting vhca_id
> to the same type as idx before performing the shift.
> 
> Fixes: 8e2e08a6d1e0 ("net/mlx5: fs, add support for dest vport HWS action")
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>

Reviewed-by: Simon Horman <horms@kernel.org>


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

* Re: [PATCH][next] net/mlx5: fix unintentional sign extension on shift of dest_attr->vport.vhca_id
  2025-01-16 18:17 [PATCH][next] net/mlx5: fix unintentional sign extension on shift of dest_attr->vport.vhca_id Colin Ian King
  2025-01-17 10:58 ` Simon Horman
@ 2025-01-17 11:44 ` Moshe Shemesh
  2025-01-18  4:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Moshe Shemesh @ 2025-01-17 11:44 UTC (permalink / raw)
  To: Colin Ian King, Saeed Mahameed, Leon Romanovsky, Tariq Toukan,
	Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Yevgeny Kliteynik, Mark Bloch, netdev, linux-rdma
  Cc: kernel-janitors, linux-kernel



On 1/16/2025 8:17 PM, Colin Ian King wrote:
> Shifting dest_attr->vport.vhca_id << 16 results in a promotion from an
> unsigned 16 bit integer to a 32 bit signed integer, this is then sign
> extended to a 64 bit unsigned long on 64 bitarchitectures. If vhca_id is
> greater than 0x7fff then this leads to a sign extended result where all
> the upper 32 bits of idx are set to 1. Fix this by casting vhca_id
> to the same type as idx before performing the shift.
> 
> Fixes: 8e2e08a6d1e0 ("net/mlx5: fs, add support for dest vport HWS action")
> Signed-off-by: Colin Ian King<colin.i.king@gmail.com>

Acked-by: Moshe Shemesh <moshe@nvidia.com>


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

* Re: [PATCH][next] net/mlx5: fix unintentional sign extension on shift of dest_attr->vport.vhca_id
  2025-01-16 18:17 [PATCH][next] net/mlx5: fix unintentional sign extension on shift of dest_attr->vport.vhca_id Colin Ian King
  2025-01-17 10:58 ` Simon Horman
  2025-01-17 11:44 ` Moshe Shemesh
@ 2025-01-18  4:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-01-18  4:00 UTC (permalink / raw)
  To: Colin Ian King
  Cc: saeedm, leon, tariqt, andrew+netdev, davem, edumazet, kuba,
	pabeni, moshe, kliteyn, mbloch, netdev, linux-rdma,
	kernel-janitors, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 16 Jan 2025 18:17:00 +0000 you wrote:
> Shifting dest_attr->vport.vhca_id << 16 results in a promotion from an
> unsigned 16 bit integer to a 32 bit signed integer, this is then sign
> extended to a 64 bit unsigned long on 64 bitarchitectures. If vhca_id is
> greater than 0x7fff then this leads to a sign extended result where all
> the upper 32 bits of idx are set to 1. Fix this by casting vhca_id
> to the same type as idx before performing the shift.
> 
> [...]

Here is the summary with links:
  - [next] net/mlx5: fix unintentional sign extension on shift of dest_attr->vport.vhca_id
    https://git.kernel.org/netdev/net-next/c/41c5d104f338

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2025-01-18  4:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-16 18:17 [PATCH][next] net/mlx5: fix unintentional sign extension on shift of dest_attr->vport.vhca_id Colin Ian King
2025-01-17 10:58 ` Simon Horman
2025-01-17 11:44 ` Moshe Shemesh
2025-01-18  4:00 ` patchwork-bot+netdevbpf

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).