From: Leon Romanovsky Date: Mon, 19 Mar 2018 12:20:15 +0000 (+0200) Subject: RDMA/ucma: Fix use-after-free access in ucma_close X-Git-Tag: v4.1.52~321 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7825be2b6c326b1ba1b5cf7081c42e1d1046a9ba;p=thirdparty%2Fkernel%2Fstable.git RDMA/ucma: Fix use-after-free access in ucma_close [ Upstream commit ed65a4dc22083e73bac599ded6a262318cad7baf ] The error in ucma_create_id() left ctx in the list of contexts belong to ucma file descriptor. The attempt to close this file descriptor causes to use-after-free accesses while iterating over such list. Fixes: 75216638572f ("RDMA/cma: Export rdma cm interface to userspace") Reported-by: Signed-off-by: Leon Romanovsky Reviewed-by: Sean Hefty Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c index 0ba965cb14ed7..f738ab1c65e61 100644 --- a/drivers/infiniband/core/ucma.c +++ b/drivers/infiniband/core/ucma.c @@ -411,6 +411,9 @@ err1: mutex_lock(&mut); idr_remove(&ctx_idr, ctx->id); mutex_unlock(&mut); + mutex_lock(&file->mut); + list_del(&ctx->list); + mutex_unlock(&file->mut); kfree(ctx); return ret; }