stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for 4.4, 4.9, 4.14] RDMA/ucma: ucma_context reference leak in error path
@ 2020-09-24  9:24 Nobuhiro Iwamatsu
  2020-09-24 23:15 ` Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Nobuhiro Iwamatsu @ 2020-09-24  9:24 UTC (permalink / raw)
  To: stable
  Cc: Shamir Rabinovitch, Leon Romanovsky, Jason Gunthorpe, Nobuhiro Iwamatsu

From: Shamir Rabinovitch <shamir.rabinovitch@oracle.com>

commit ef95a90ae6f4f21990e1f7ced6719784a409e811 upstream.

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 <shamir.rabinovitch@oracle.com>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
[iwamatsu: Backported to 4.4, 4.9 and 4.14: adjust context]
Signed-off-by: Nobuhiro Iwamatsu (CIP) <nobuhiro1.iwamatsu@toshiba.co.jp>
---
 drivers/infiniband/core/ucma.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index 3e4d3d5560bf10..6315f77b4a58c1 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -1295,13 +1295,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((void __user *) (unsigned long) cmd.optval,
 			     cmd.optlen);
 	if (IS_ERR(optval)) {
--
2.28.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH for 4.4, 4.9, 4.14] RDMA/ucma: ucma_context reference leak in error path
  2020-09-24  9:24 [PATCH for 4.4, 4.9, 4.14] RDMA/ucma: ucma_context reference leak in error path Nobuhiro Iwamatsu
@ 2020-09-24 23:15 ` Sasha Levin
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2020-09-24 23:15 UTC (permalink / raw)
  To: Nobuhiro Iwamatsu
  Cc: stable, Shamir Rabinovitch, Leon Romanovsky, Jason Gunthorpe

On Thu, Sep 24, 2020 at 06:24:49PM +0900, Nobuhiro Iwamatsu wrote:
>From: Shamir Rabinovitch <shamir.rabinovitch@oracle.com>
>
>commit ef95a90ae6f4f21990e1f7ced6719784a409e811 upstream.
>
>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 <shamir.rabinovitch@oracle.com>
>Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
>Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
>[iwamatsu: Backported to 4.4, 4.9 and 4.14: adjust context]
>Signed-off-by: Nobuhiro Iwamatsu (CIP) <nobuhiro1.iwamatsu@toshiba.co.jp>

Queued up, thanks!

-- 
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-24 23:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-24  9:24 [PATCH for 4.4, 4.9, 4.14] RDMA/ucma: ucma_context reference leak in error path Nobuhiro Iwamatsu
2020-09-24 23:15 ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).