Skip to content

Commit 9b6d3bb

Browse files
Leon Romanovskyjgunthorpe
authored andcommitted
RDMA/mlx5: Prevent overflow in mmap offset calculations
The cmd and index variables declared as u16 and the result is supposed to be stored in u64. The C arithmetic rules doesn't promote "(index >> 8) << 16" to be u64 and leaves the end result to be u16. Fixes: 7be76be ("IB/mlx5: Introduce VAR object and its alloc/destroy methods") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Leon Romanovsky <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 9ea04d0 commit 9b6d3bb

File tree

1 file changed

+2
-2
lines changed
  • drivers/infiniband/hw/mlx5

1 file changed

+2
-2
lines changed

drivers/infiniband/hw/mlx5/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,8 +2283,8 @@ static int mlx5_ib_mmap_offset(struct mlx5_ib_dev *dev,
22832283

22842284
static u64 mlx5_entry_to_mmap_offset(struct mlx5_user_mmap_entry *entry)
22852285
{
2286-
u16 cmd = entry->rdma_entry.start_pgoff >> 16;
2287-
u16 index = entry->rdma_entry.start_pgoff & 0xFFFF;
2286+
u64 cmd = (entry->rdma_entry.start_pgoff >> 16) & 0xFFFF;
2287+
u64 index = entry->rdma_entry.start_pgoff & 0xFFFF;
22882288

22892289
return (((index >> 8) << 16) | (cmd << MLX5_IB_MMAP_CMD_SHIFT) |
22902290
(index & 0xFF)) << PAGE_SHIFT;

0 commit comments

Comments
 (0)