RDMA/cache: fix invalid-free of flex-array data_vec in release_gid_table
PATCH 1/1 RDMA/cache: fix invalid-free of flex-array data_vec in release_gid_table
Commit 74e2711bb2af ("RDMA/core: Use kzalloc_flex for GID table") converted alloc_gid_table() to use kzalloc_flex(), which allocates the ib_gid_table struct and its trailing data_vec flex array member in a single contiguous slab block.
However, release_gid_table() was not updated accordingly and still calls kfree(table->data_vec), passing a pointer that points 216 bytes into the middle of the slab object rather than its head. This is an invalid free which KASAN catches as:
BUG: KASAN: invalid-free in release_gid_table+0x384/0x470
Since data_vec is now a flex array member of ib_gid_table, it is freed implicitly when kfree(table) is called. Remove the redundant and invalid kfree(table->data_vec).
--- drivers/infiniband/core/cache.c | 1 - 1 file changed, 1 deletion(-)
drivers/infiniband/core/cache.c +0 -1
@@ -801,7 +801,6 @@ static void release_gid_table(struct ib_device *device, }mutex_destroy (&table->lock); -kfree (table->data_vec);kfree (table); }
Signature · 1 line
2.43.0
Quoted 39 lines · Deepanshu Kartikey
Commit
74e2711bb2af("RDMA/core: Usekzalloc_flexfor GID table") convertedalloc_gid_table()to usekzalloc_flex(), which allocates theib_gid_tablestruct and its trailingdata_vecflex array member in a single contiguous slab block.However,
release_gid_table()was not updated accordingly and still callskfree(table->data_vec), passing a pointer that points 216 bytes into the middle of the slab object rather than its head. This is an invalid free which KASAN catches as:BUG: KASAN: invalid-free in release_gid_table+0x384/0x470Since
data_vecis now a flex array member ofib_gid_table, it is freed implicitly when kfree(table) is called. Remove the redundant and invalidkfree(table->data_vec).Fixes 74e2711bb2af ("RDMA/core: Use kzalloc_flex for GID table")Reported-by [email protected]Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- drivers/infiniband/core/cache.c | 1 - 1 file changed, 1 deletion(-)drivers/infiniband/core/cache.c +0
-2@@ -801,7 +801,6 @@ static void release_gid_table(struct ib_device *device, }mutex_destroy (&table->lock); -kfree (table->data_vec);kfree (table); } --
Quoted 2 lines
2.43.0
Gentle ping on this patch. Please let me know the status of this patch.
Thanks
Deepanshu Kartikey
Quoted 7 lines · Deepanshu Kartikey
Quoted 7 lines
drivers/infiniband/core/cache.c +0
-0@@ -801,7 +801,6 @@ static void release_gid_table(struct ib_device *device, }
Quoted 8 lines
drivers/infiniband/core/cache.c static void release_gid_table(struct ib_device *device, · line 806
Quoted 6 lines
drivers/infiniband/core/cache.c +0
-1mutex_destroy (&table->lock); -kfree (table->data_vec);kfree (table); }Gentle ping on this patch. Please let me know the status of this patch.
Oh, I think a different version was picked up
Thanks,
Jason