Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef95a90a authored by Shamir Rabinovitch's avatar Shamir Rabinovitch Committed by Jason Gunthorpe
Browse files

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: 6a21dfc0 ("RDMA/ucma: Limit possible option size")
Signed-off-by: default avatarShamir Rabinovitch <shamir.rabinovitch@oracle.com>
Reviewed-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 60cc43fc
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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)) {