Skip to contentSkip to conversation

net/mlx5: fix unintentional sign extension on shift of dest_attr->vport.vhca_id

PATCH Applied Colin Ian King 4 participants 4 messages Jan 16, 2025 – Jan 18, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5: fix unintentional sign extension on shift of dest_attr->vport.vhca_id

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")
---
 drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +1 -1
index 05329afeb9ea..f34bbbbba1c2 100644
@@ -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;
Signature · 1 line
2.47.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Colin Ian King

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")
Acked-by on v1 1/1
#2 lore raw
In reply to Colin Ian King
Quoted 9 lines · Colin Ian King

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")
#3 lore raw
In reply to Colin Ian King
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html