All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Dongliang Qin <cccccccccccc777777@gmail.com>
Cc: netdev@vger.kernel.org, achender@kernel.org,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net] rds: ib: Clear the sg list when mapping an MR fails
Date: Mon, 21 Sep 2026 17:57:22 +0100	[thread overview]
Message-ID: <20260921165722.GY13925@horms.kernel.org> (raw)
In-Reply-To: <20260920063449.1594203-1-cccccccccccc777777@gmail.com>

On Sun, Sep 20, 2026 at 02:34:49PM +0800, Dongliang Qin wrote:
> rds_ib_map_frmr() stores the caller's scatterlist in the MR before DMA
> mapping and registration can fail. On failure, __rds_rdma_map() unpins
> the pages and frees the scatterlist, but rds_ib_free_frmr() can still
> return the MR to the pool with the stale pointer set.
> 
> This leaves the pool with a dangling scatterlist and can lead to local
> privilege escalation. KASAN detects the resulting use-after-free when the
> MR is later torn down:
> 
> BUG: KASAN: slab-use-after-free in __rds_ib_teardown_mr
> Read of size 8
> 
> Call Trace:
>  __rds_ib_teardown_mr
>  rds_ib_unreg_frmr
>  rds_ib_flush_mr_pool
>  rds_ib_flush_mrs
>  rds_free_mr
>  rds_setsockopt
> 
> Clear the scatterlist fields before returning an error so the caller
> retains sole ownership of the scatterlist and its pinned pages. Route a
> zero-length DMA mapping through the same cleanup path, and skip unmap
> when no mapping was created.
> 
> Fixes: 1659185fb4d0 ("RDS: IB: Support Fastreg MR (FRMR) memory registration mode")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dongliang Qin <cccccccccccc777777@gmail.com>
> ---
>  net/rds/ib_frmr.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/net/rds/ib_frmr.c b/net/rds/ib_frmr.c
> index bd8611911..fea387952 100644
> --- a/net/rds/ib_frmr.c
> +++ b/net/rds/ib_frmr.c
> @@ -213,7 +213,8 @@ static int rds_ib_map_frmr(struct rds_ib_device *rds_ibdev,
>  					 DMA_BIDIRECTIONAL);
>  	if (unlikely(!ibmr->sg_dma_len)) {
>  		pr_warn("RDS/IB: %s failed!\n", __func__);
> -		return -EBUSY;
> +		ret = -EBUSY;
> +		goto out_unmap;
>  	}

Hi Dongliang,

This approach leads to the complexity of a condition in the out_unmap
label.  I wonder if a cleaner approach would be to, instead, only store the
scatterlist in the MR once mapping has succeeded.

With such an approach I think that ibmr->sg and ibmr->sg_len would still
need to be cleared in the error path. But neither the condition in the
out_unmap label nor the hunk above would not be necessary. And I wonder
if that would be a cleaner approach.

>  
>  	frmr->sg_byte_len = 0;
> @@ -261,9 +262,13 @@ static int rds_ib_map_frmr(struct rds_ib_device *rds_ibdev,
>  	return ret;
>  
>  out_unmap:
> -	ib_dma_unmap_sg(rds_ibdev->dev, ibmr->sg, ibmr->sg_len,
> -			DMA_BIDIRECTIONAL);
> -	ibmr->sg_dma_len = 0;
> +	if (ibmr->sg_dma_len) {
> +		ib_dma_unmap_sg(rds_ibdev->dev, ibmr->sg, ibmr->sg_len,
> +				DMA_BIDIRECTIONAL);
> +		ibmr->sg_dma_len = 0;
> +	}
> +	ibmr->sg = NULL;
> +	ibmr->sg_len = 0;
>  	return ret;
>  }
>  
> -- 
> 2.43.0
> 

  parent reply	other threads:[~2026-09-21 16:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20  6:34 [PATCH net] rds: ib: Clear the sg list when mapping an MR fails Dongliang Qin
2026-09-20  6:44 ` sashiko-bot
2026-09-21 16:57 ` Simon Horman [this message]
2026-09-22  1:03   ` Allison Henderson

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=20260921165722.GY13925@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=achender@kernel.org \
    --cc=cccccccccccc777777@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rds-devel@oss.oracle.com \
    --cc=stable@vger.kernel.org \
    /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.