Skip to content

Commit

Permalink
mlx5: Avoid that mlx5_ib_sg_to_klms() overflows the klms[] array
Browse files Browse the repository at this point in the history
ib_map_mr_sg() can pass an SG-list to .map_mr_sg() that is larger
than what fits into a single MR. .map_mr_sg() must not attempt to
map more SG-list elements than what fits into a single MR.
Hence make sure that mlx5_ib_sg_to_klms() does not write outside
the MR klms[] array.

Fixes: b005d31 ("mlx5: Add arbitrary sg list support")
Signed-off-by: Bart Van Assche <[email protected]>
Reviewed-by: Max Gurtovoy <[email protected]>
Cc: Sagi Grimberg <[email protected]>
Cc: Leon Romanovsky <[email protected]>
Cc: Israel Rukshin <[email protected]>
Cc: <[email protected]>
Acked-by: Leon Romanovsky <[email protected]>
Reviewed-by: Sagi Grimberg <[email protected]>
Signed-off-by: Doug Ledford <[email protected]>
  • Loading branch information
Bart Van Assche authored and dledford committed Jul 17, 2017
1 parent 91647f4 commit 99975cd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/infiniband/hw/mlx5/mr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ mlx5_ib_sg_to_klms(struct mlx5_ib_mr *mr,
mr->ndescs = sg_nents;

for_each_sg(sgl, sg, sg_nents, i) {
if (unlikely(i > mr->max_descs))
if (unlikely(i >= mr->max_descs))
break;
klms[i].va = cpu_to_be64(sg_dma_address(sg) + sg_offset);
klms[i].bcount = cpu_to_be32(sg_dma_len(sg) - sg_offset);
Expand Down

0 comments on commit 99975cd

Please sign in to comment.