From: Jason Gunthorpe <jgg@nvidia.com>
To: Bob Pearson <rpearsonhpe@gmail.com>
Cc: zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org
Subject: Re: [PATCH for-next v14 08/10] RDMA/rxe: Stop lookup of partially built objects
Date: Mon, 9 May 2022 09:21:18 -0300 [thread overview]
Message-ID: <20220509122118.GA844594@nvidia.com> (raw)
In-Reply-To: <20220421014042.26985-9-rpearsonhpe@gmail.com>
On Wed, Apr 20, 2022 at 08:40:41PM -0500, Bob Pearson wrote:
> Currently the rdma_rxe driver has a security weakness due to giving
> objects which are partially initialized indices allowing external
> actors to gain access to them by sending packets which refer to
> their index (e.g. qpn, rkey, etc) causing unpredictable results.
>
> This patch adds a new API rxe_finalize(obj) which enables looking up
> pool objects from indices using rxe_pool_get_index() for
> AH, QP, MR, and MW. They are added in create verbs only after the
> objects are fully initialized.
>
> It also adds wait for completion to destroy/dealloc verbs to assure that
> all references have been dropped before returning to rdma_core by
> implementing a new rxe_pool API rxe_cleanup() which drops a reference
> to the object and then waits for all other references to be dropped.
> When the last reference is dropped the object is completed by kref.
> After that it cleans up the object and if locally allocated frees
> the memory.
>
> Combined with deferring cleanup code to type specific cleanup
> routines this allows all pending activity referring to objects to
> complete before returning to rdma_core.
This seems fine, except the AH problem needs to be fixed before
applying this patch since it looks like it worsens it on the destoy
side now too.
> +int __rxe_cleanup(struct rxe_pool_elem *elem)
> +{
> struct rxe_pool *pool = elem->pool;
> + struct xarray *xa = &pool->xa;
> + static int timeout = RXE_POOL_TIMEOUT;
> + unsigned long flags;
> + int ret, err = 0;
> + void *xa_ret;
>
> - xa_erase(&pool->xa, elem->index);
> + /* erase xarray entry to prevent looking up
> + * the pool elem from its index
> + */
> + xa_lock_irqsave(xa, flags);
> + xa_ret = __xa_erase(xa, elem->index);
> + xa_unlock_irqrestore(xa, flags);
> + WARN_ON(xa_err(xa_ret));
> +
> + /* if this is the last call to rxe_put complete the
> + * object. It is safe to touch elem after this since
> + * it is freed below
> + */
> + __rxe_put(elem);
> +
> + if (timeout) {
> + ret = wait_for_completion_timeout(&elem->complete, timeout);
The atomic version of this should just spin, I guess, but is there
even any condition where an AH can be held? Maybe the atomic version
just returns succees..
> + if (!ret) {
> + pr_warn("Timed out waiting for %s#%d to complete\n",
> + pool->name, elem->index);
> + if (++pool->timeouts >= RXE_POOL_MAX_TIMEOUTS)
> + timeout = 0;
> +
> + err = -EINVAL;
This is also something of a bug, the xa was erased but now we have
this zombie element floating around, so when we call this again (and
the core code will call it again) the xa will be corrupted.
Could mitigate this by using xa_cmpxchng instead of erase and ignore
the return code.
Jason
next prev parent reply other threads:[~2022-05-09 12:21 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 1:40 [PATCH for-next v14 00/10] Fix race conditions in rxe_pool Bob Pearson
2022-04-21 1:40 ` [PATCH for-next v14 01/10] RDMA/rxe: Remove IB_SRQ_INIT_MASK Bob Pearson
2022-04-21 1:40 ` [PATCH for-next v14 02/10] RDMA/rxe: Add rxe_srq_cleanup() Bob Pearson
2022-05-09 12:02 ` Jason Gunthorpe
2022-04-21 1:40 ` [PATCH for-next v14 03/10] RDMA/rxe: Check rxe_get() return value Bob Pearson
2022-04-21 1:40 ` [PATCH for-next v14 04/10] RDMA/rxe: Move qp cleanup code to rxe_qp_do_cleanup() Bob Pearson
2022-04-21 1:40 ` [PATCH for-next v14 05/10] RDMA/rxe: Move mr cleanup code to rxe_mr_cleanup() Bob Pearson
2022-04-21 1:40 ` [PATCH for-next v14 06/10] RDMA/rxe: Move mw cleanup code to rxe_mw_cleanup() Bob Pearson
2022-05-09 12:08 ` Jason Gunthorpe
2022-04-21 1:40 ` [PATCH for-next v14 07/10] RDMA/rxe: Enforce IBA C11-17 Bob Pearson
2022-04-21 1:40 ` [PATCH for-next v14 08/10] RDMA/rxe: Stop lookup of partially built objects Bob Pearson
2022-05-09 12:21 ` Jason Gunthorpe [this message]
2022-04-21 1:40 ` [PATCH for-next v14 09/10] RDMA/rxe: Convert read side locking to rcu Bob Pearson
2022-05-09 11:58 ` Jason Gunthorpe
2022-04-21 1:40 ` [PATCH for-next v14 10/10] RDMA/rxe: Cleanup rxe_pool.c Bob Pearson
2022-05-09 12:17 ` Jason Gunthorpe
2022-05-09 18:23 ` [PATCH for-next v14 00/10] Fix race conditions in rxe_pool Jason Gunthorpe
2022-05-10 0:35 ` Yanjun Zhu
2022-05-10 12:43 ` Jason Gunthorpe
2022-05-24 3:53 ` yangx.jy
2022-05-24 11:57 ` Jason Gunthorpe
2022-05-24 18:22 ` Bob Pearson
2022-05-24 18:26 ` Jason Gunthorpe
2022-05-24 18:27 ` Bob Pearson
2022-05-24 18:41 ` Jason Gunthorpe
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=20220509122118.GA844594@nvidia.com \
--to=jgg@nvidia.com \
--cc=linux-rdma@vger.kernel.org \
--cc=rpearsonhpe@gmail.com \
--cc=zyjzyj2000@gmail.com \
/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 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).