Skip to content

Commit 7e967fd

Browse files
jgunthorpedledford
authored andcommitted
IB/ucma: Fix theoretical user triggered use-after-free
Something like this: CPU A CPU B Acked-by: Sean Hefty <[email protected]> ======================== ================================ ucma_destroy_id() wait_for_completion() .. anything ucma_put_ctx() complete() .. continues ... ucma_leave_multicast() mutex_lock(mut) atomic_inc(ctx->ref) mutex_unlock(mut) ucma_free_ctx() ucma_cleanup_multicast() mutex_lock(mut) kfree(mc) rdma_leave_multicast(mc->ctx->cm_id,.. Fix it by latching the ref at 0. Once it goes to 0 mc and ctx cannot leave the mutex(mut) protection. The other atomic_inc in ucma_get_ctx is OK because mutex(mut) protects it from racing with ucma_destroy_id. Signed-off-by: Jason Gunthorpe <[email protected]> Acked-by: Sean Hefty <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent b8ac311 commit 7e967fd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/infiniband/core/ucma.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,10 +1321,10 @@ static ssize_t ucma_leave_multicast(struct ucma_file *file,
13211321
mc = ERR_PTR(-ENOENT);
13221322
else if (mc->ctx->file != file)
13231323
mc = ERR_PTR(-EINVAL);
1324-
else {
1324+
else if (!atomic_inc_not_zero(&mc->ctx->ref))
1325+
mc = ERR_PTR(-ENXIO);
1326+
else
13251327
idr_remove(&multicast_idr, mc->id);
1326-
atomic_inc(&mc->ctx->ref);
1327-
}
13281328
mutex_unlock(&mut);
13291329

13301330
if (IS_ERR(mc)) {

0 commit comments

Comments
 (0)