Skip to content

Commit

Permalink
librdmacm: Fix an overflow bug in qsort comparison function
Browse files Browse the repository at this point in the history
The comparison function dev_cmp() doesn't work with 64b pointers in some
cases, as it casts the pointer to int. For example it's not able to sort
this list:
  {0xfffe0c2f0b00, 0xaaac741b4a90, 0xaaac741b4d70}

Fixes: e5d371c ("librdmacm: Globally store and sort IB device list")
Signed-off-by: Mark Zhang <[email protected]>
Reviewed-by: Leon Romanovsky <[email protected]>
Signed-off-by: Yishai Hadas <[email protected]>
  • Loading branch information
MarkZhang81 authored and Yishai Hadas committed May 5, 2024
1 parent 9a0fc3a commit c4a5ac8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion librdmacm/cma.c
Expand Up @@ -311,7 +311,7 @@ static void remove_cma_dev(struct cma_device *cma_dev)

static int dev_cmp(const void *a, const void *b)
{
return (int)(*(char *const *)a - *(char *const *)b);
return (*(uintptr_t *)a > *(uintptr_t *)b) - (*(uintptr_t *)a < *(uintptr_t *)b);
}

static int sync_devices_list(void)
Expand Down

0 comments on commit c4a5ac8

Please sign in to comment.