public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Martin Wilck <mwilck@suse.com>
To: Daniel Wagner <dwagner@suse.de>, linux-scsi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Nilesh Javali <njavali@marvell.com>
Subject: Re: [PATCH 1/4] qla2xxx: Reset done and free callback pointer on release
Date: Thu, 27 Aug 2020 12:12:04 +0200	[thread overview]
Message-ID: <04f76144372753cceab48f59f7f2aaea017f021f.camel@suse.com> (raw)
In-Reply-To: <20200827095829.63871-2-dwagner@suse.de>

On Thu, 2020-08-27 at 11:58 +0200, Daniel Wagner wrote:
> Reset ->done and ->free when releasing the srb. There is a hidden
> use-after-free bug in the driver which corrupts the srb memory pool
> which originates from the cleanup callbacks. By explicitly resetting
> the callbacks to NULL, we workaround the memory corruption.
> 
> An extensive search didn't bring any lights on the real problem. The
> initial idea was to set both pointers to NULL and try to catch
> invalid
> accesses. But instead the memory corruption was gone and the driver
> didn't crash.
> 
> Signed-off-by: Daniel Wagner <dwagner@suse.de>
> ---
>  drivers/scsi/qla2xxx/qla_inline.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/scsi/qla2xxx/qla_inline.h
> b/drivers/scsi/qla2xxx/qla_inline.h
> index 861dc522723c..6d41d758fc17 100644
> --- a/drivers/scsi/qla2xxx/qla_inline.h
> +++ b/drivers/scsi/qla2xxx/qla_inline.h
> @@ -211,6 +211,8 @@ static inline void
>  qla2xxx_rel_qpair_sp(struct qla_qpair *qpair, srb_t *sp)
>  {
>  	sp->qpair = NULL;
> +	sp->done = NULL;
> +	sp->free = NULL;
>  	mempool_free(sp, qpair->srb_mempool);
>  	QLA_QPAIR_MARK_NOT_BUSY(qpair);
>  }

Both sp->done() and sp->free() are called all over the place without
making sure the pointers are non-null. If these functions can be called
for freed sp's, wouldn't that mean we'd crash?

How about setting them to a dummy function that prints a big fat
warning?

Martin



  reply	other threads:[~2020-08-27 10:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-27  9:58 [PATCH 0/4] qla2xxx: A couple crash fixes Daniel Wagner
2020-08-27  9:58 ` [PATCH 1/4] qla2xxx: Reset done and free callback pointer on release Daniel Wagner
2020-08-27 10:12   ` Martin Wilck [this message]
2020-08-27 11:42     ` Daniel Wagner
2020-08-27  9:58 ` [PATCH 2/4] qla2xxx: Simplify return value logic in qla2x00_get_sp_from_handle() Daniel Wagner
2020-08-27  9:58 ` [PATCH 3/4] qla2xxx: Drop unused function argument from qla2x00_get_sp_from_handle() Daniel Wagner
2020-08-27  9:58 ` [PATCH 4/4] qla2xxx: Handle incorrect entry_type entries Daniel Wagner
2020-08-27 10:17   ` Martin Wilck
2020-08-27 11:46     ` Daniel Wagner
2020-08-27 12:45       ` Martin Wilck

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=04f76144372753cceab48f59f7f2aaea017f021f.camel@suse.com \
    --to=mwilck@suse.com \
    --cc=dwagner@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=njavali@marvell.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