All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Natalia Petrova <n.petrova@fintech.ru>
Cc: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	ldv-project@linuxtesting.org,
	Alexey Khoroshilov <khoroshilov@ispras.ru>
Subject: Re: [PATCH] rdmavt: avoid NULL pointer dereference in rvt_qp_exit()
Date: Tue, 18 Oct 2022 11:41:21 +0300	[thread overview]
Message-ID: <Y05msUNgnQTWmXyh@unreal> (raw)
In-Reply-To: <20221017142652.13906-1-n.petrova@fintech.ru>

On Mon, Oct 17, 2022 at 05:26:52PM +0300, Natalia Petrova wrote:
> rvt_qp_exit() checks 'rdi->qp_dev' for NULL, but the pointer is
> dereferenced before that in rvt_free_all_qps().
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: f92e48718889 ("IB/rdmavt: Reset all QPs when the device is shut
> down")

Please never break fixes line.

> Signed-off-by: Natalia Petrova <n.petrova@fintech.ru>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
>  drivers/infiniband/sw/rdmavt/qp.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/infiniband/sw/rdmavt/qp.c b/drivers/infiniband/sw/rdmavt/qp.c
> index 3acab569fbb9..06e755975f61 100644
> --- a/drivers/infiniband/sw/rdmavt/qp.c
> +++ b/drivers/infiniband/sw/rdmavt/qp.c
> @@ -459,13 +459,16 @@ static unsigned rvt_free_all_qps(struct rvt_dev_info *rdi)
>   */
>  void rvt_qp_exit(struct rvt_dev_info *rdi)
>  {
> -	u32 qps_inuse = rvt_free_all_qps(rdi);
> +	u32 qps_inuse = 0;
> +
> +	if (!rdi->qp_dev)
> +		return;
> +
> +	qps_inuse = rvt_free_all_qps(rdi);

These lines are not needed.

>  
>  	if (qps_inuse)
>  		rvt_pr_err(rdi, "QP memory leak! %u still in use\n",
>  			   qps_inuse);
> -	if (!rdi->qp_dev)
> -		return;

It is enough to delete these two lines. At this stage, rdi->qp_dev always
exists as it was created in rvt_register_device().

Thanks

  reply	other threads:[~2022-10-18  8:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17 14:26 [PATCH] rdmavt: avoid NULL pointer dereference in rvt_qp_exit() Natalia Petrova
2022-10-18  8:41 ` Leon Romanovsky [this message]
2022-10-18 14:24   ` Dennis Dalessandro
2023-03-03 12:44     ` [PATCH v2] rdmavt: delete unnecessary NULL check Natalia Petrova
2023-03-14  9:26       ` 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=Y05msUNgnQTWmXyh@unreal \
    --to=leon@kernel.org \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=jgg@ziepe.ca \
    --cc=khoroshilov@ispras.ru \
    --cc=ldv-project@linuxtesting.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=n.petrova@fintech.ru \
    /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.