From: Shamir Rabinovitch Date: Tue, 10 Apr 2018 14:26:23 +0000 (-0400) Subject: RDMA/ucma: ucma_context reference leak in error path X-Git-Tag: v5.15~8782^2~82 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef95a90ae6f4f21990e1f7ced6719784a409e811;p=platform%2Fkernel%2Flinux-starfive.git RDMA/ucma: ucma_context reference leak in error path Validating input parameters should be done before getting the cm_id otherwise it can leak a cm_id reference. Fixes: 6a21dfc0d0db ("RDMA/ucma: Limit possible option size") Signed-off-by: Shamir Rabinovitch Reviewed-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe --- diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c index 7432948..680b353 100644 --- a/drivers/infiniband/core/ucma.c +++ b/drivers/infiniband/core/ucma.c @@ -1316,13 +1316,13 @@ static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf, if (copy_from_user(&cmd, inbuf, sizeof(cmd))) return -EFAULT; + if (unlikely(cmd.optlen > KMALLOC_MAX_SIZE)) + return -EINVAL; + ctx = ucma_get_ctx(file, cmd.id); if (IS_ERR(ctx)) return PTR_ERR(ctx); - if (unlikely(cmd.optlen > KMALLOC_MAX_SIZE)) - return -EINVAL; - optval = memdup_user(u64_to_user_ptr(cmd.optval), cmd.optlen); if (IS_ERR(optval)) {