From 819da9acc86344b031c5df56b22f83d9b570db6a Mon Sep 17 00:00:00 2001 From: Mark Zhang Date: Fri, 26 Apr 2024 14:17:55 +0300 Subject: [PATCH] librdmacm: Fix an overflow bug in qsort comparison function [ Upstream commit c4a5ac8bba611206e062c0955fb605bfc0f48b0f ] 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: e5d371cb0af0 ("librdmacm: Globally store and sort IB device list") Signed-off-by: Mark Zhang Reviewed-by: Leon Romanovsky Signed-off-by: Yishai Hadas Signed-off-by: Nicolas Morey --- librdmacm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/librdmacm/cma.c b/librdmacm/cma.c index 6eccbb774..fe64f5ebe 100644 --- a/librdmacm/cma.c +++ b/librdmacm/cma.c @@ -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)