All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: lirongqing <lirongqing@baidu.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH] RDMA/uverbs: Drop restrack ref on ib_init_ucontext() failure in GET_CONTEXT
Date: Wed, 16 Sep 2026 09:07:28 +0000	[thread overview]
Message-ID: <20260916090728.848F81F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260916085529.1838-1-lirongqing@baidu.com>

> From: Li RongQing <lirongqing@baidu.com>
> 
> The UVERBS_METHOD_GET_CONTEXT handler allocates the ucontext via
> ib_alloc_ucontext(), which calls rdma_restrack_new() (initialising the
> kref to 1) and rdma_restrack_set_name(NULL), the latter attaching the
> current task and taking a task_struct reference.  When ib_init_ucontext()
> subsequently fails, the error path only does:
> 
> 	kfree(attrs->context);
> 	attrs->context = NULL;
> 
> without first calling rdma_restrack_put() on &attrs->context->res.  The
> kref therefore never reaches zero, restrack_release() is never invoked,
> and put_task_struct() is never called, so the task_struct reference taken
> during set_name is leaked permanently.
> 
> A local user with access to an RDMA device can repeat this path (e.g. by
> hitting an RDMA cgroup limit or supplying invalid ucaps) and leak one
> task_struct reference per attempt, eventually preventing those processes
> from being reaped or exhausting memory.
> 
> The legacy ib_uverbs_get_context() path already handles this correctly
> at its err_ucontext label, where rdma_restrack_put() precedes kfree().
> Mirror that ordering here.
> 
> Fixes: a1123418ba10 ("RDMA/uverbs: Add ioctl command to get a device context")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260916085529.1838-1-lirongqing@baidu.com?part=1


  reply	other threads:[~2026-09-16  9:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  8:55 [PATCH] RDMA/uverbs: Drop restrack ref on ib_init_ucontext() failure in GET_CONTEXT lirongqing
2026-09-16  9:07 ` sashiko-bot [this message]
2026-09-18 12:49 ` Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260916090728.848F81F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.