Skip to content

Commit 17b38fb

Browse files
Doron Tsurdledford
authored andcommitted
IB/core: Fix memory corruption in ib_cache_gid_set_default_gid
When ib_cache_gid_set_default_gid is called from several threads, updating the table could make find_gid fail, therefore a negative index will be retruned and an invalid table entry will be used. Locking find_gid as well fixes this problem. Fixes: 03db3a2 ('IB/core: Add RoCE GID table management') Signed-off-by: Doron Tsur <[email protected]> Signed-off-by: Matan Barak <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 0b5c927 commit 17b38fb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/infiniband/core/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,12 @@ void ib_cache_gid_set_default_gid(struct ib_device *ib_dev, u8 port,
508508
memset(&gid_attr, 0, sizeof(gid_attr));
509509
gid_attr.ndev = ndev;
510510

511+
mutex_lock(&table->lock);
511512
ix = find_gid(table, NULL, NULL, true, GID_ATTR_FIND_MASK_DEFAULT);
512513

513514
/* Coudn't find default GID location */
514515
WARN_ON(ix < 0);
515516

516-
mutex_lock(&table->lock);
517517
if (!__ib_cache_gid_get(ib_dev, port, ix,
518518
&current_gid, &current_gid_attr) &&
519519
mode == IB_CACHE_GID_DEFAULT_MODE_SET &&

0 commit comments

Comments
 (0)