Skip to content

Commit 68c6bcd

Browse files
Erez Shitritdledford
authored andcommitted
IB/core: Fix use after free in send_leave function
The function send_leave sets the member: group->query_id (group->query_id = ret) after calling the sa_query, but leave_handler can be executed before the setting and it might delete the group object, and will get a memory corruption. Additionally, this patch gets rid of group->query_id variable which is not used. Fixes: faec2f7 ('IB/sa: Track multicast join/leave requests') Signed-off-by: Erez Shitrit <erezsh@mellanox.com> Signed-off-by: Leon Romanovsky <leon@kernel.org> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent 656aace commit 68c6bcd

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

drivers/infiniband/core/multicast.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ struct mcast_group {
106106
atomic_t refcount;
107107
enum mcast_group_state state;
108108
struct ib_sa_query *query;
109-
int query_id;
110109
u16 pkey_index;
111110
u8 leave_state;
112111
int retries;
@@ -340,11 +339,7 @@ static int send_join(struct mcast_group *group, struct mcast_member *member)
340339
member->multicast.comp_mask,
341340
3000, GFP_KERNEL, join_handler, group,
342341
&group->query);
343-
if (ret >= 0) {
344-
group->query_id = ret;
345-
ret = 0;
346-
}
347-
return ret;
342+
return (ret > 0) ? 0 : ret;
348343
}
349344

350345
static int send_leave(struct mcast_group *group, u8 leave_state)
@@ -364,11 +359,7 @@ static int send_leave(struct mcast_group *group, u8 leave_state)
364359
IB_SA_MCMEMBER_REC_JOIN_STATE,
365360
3000, GFP_KERNEL, leave_handler,
366361
group, &group->query);
367-
if (ret >= 0) {
368-
group->query_id = ret;
369-
ret = 0;
370-
}
371-
return ret;
362+
return (ret > 0) ? 0 : ret;
372363
}
373364

374365
static void join_group(struct mcast_group *group, struct mcast_member *member,

0 commit comments

Comments
 (0)