All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Bogdanov <d.bogdanov@yadro.com>
To: Tony Battersby <tonyb@cybernetics.com>
Cc: Nilesh Javali <njavali@marvell.com>,
	<GR-QLogic-Storage-Upstream@marvell.com>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	<target-devel@vger.kernel.org>,
	<scst-devel@lists.sourceforge.net>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [DMARC Error]Re: [PATCH 10/15] scsi: qla2xxx: fix TMR failure handling
Date: Wed, 17 Sep 2025 16:06:41 +0300	[thread overview]
Message-ID: <20250917130641.GD624@yadro.com> (raw)
In-Reply-To: <526d0d1b-79f1-47fd-bc44-6727898f381c@cybernetics.com>

On Tue, Sep 16, 2025 at 12:04:11PM -0400, Tony Battersby wrote:
> 
> On 9/12/25 10:36, Dmitry Bogdanov wrote:
> > On Mon, Sep 08, 2025 at 03:02:49PM -0400, Tony Battersby wrote:
> >> If handle_tmr() fails (e.g. -ENOMEM):
> >> - qlt_send_busy() makes no sense because it sends a SCSI command
> >>   response instead of a TMR response.
> > There is not only -ENOMEM can be returned by handle_tmr.
> 
> Indeed.  I will remove mention of -ENOMEM since it isn't really relevant.
> 
> >> +               mcmd->fc_tm_rsp = FCP_TMF_REJECTED;
> >>
> > FCP_TMF_REJECTED means that this TMF is not supported, FCP_TMF_FAILED is
> > more appretiate here.
> 
> I will make that change.
> 
> >> - Calling mempool_free() directly can lead to memory-use-after-free.
> > No, it is a API contract between modules. If handle_tmr returned an error,
> > then the caller of handle_tmr is responsible to make a cleanup.
> > Otherwise, target module (tcm_qla2xxx) is responsible. The same rule is
> > for handle_cmd.
> >> +               qlt_xmit_tm_rsp(mcmd);
> > qlt_xmit_tm_rsp does not free mcmd for TMF ABORT. So you introduce a memleak.
> 
> I just tested it, and there is no memleak.  qlt_build_abts_resp_iocb()
> sets req->outstanding_cmds[h] to mcmd, and then
> qlt_handle_abts_completion() calls ->free_mcmd after getting a response
> from the ISP.

ha->tgt.tgt_ops->free_mcmd(mcmd) can be called when mcmd was handled by the
target core, i.e. handle_tmr() returned 0. LIO's tcm_qla2xxx_free_mcmd calls
target core function transport_generic_free_cmd to clear core's command
object. Which in turns calls eventually mempool_free in qla2xxx.
But when handle_tmr returned an error then there is no that core's
command object and LIO will not free the mcmd. That is how a memleak
will happen.

> The original code had a memory-use-after-free by calling
> qlt_build_abts_resp_iocb() and then mempool_free(), and
> then qlt_handle_abts_completion() used the freed mcmd.  I can reword the
> commit message to make this clearer.

BTW, the easyest way to just to fix that use-after-free is to use
qlt_24xx_send_abts_resp instead of qlt_build_abts_resp_iocb like in other
places, where there is no mcmd and there is no need to wait the
completion from FW.

We use this patch:


From: Dmitry Bogdanov <d.bogdanov@yadro.com>
Date: Thu, 27 Apr 2023 15:41:55 +0300
Subject: [PATCH] scsi: qla2xxx: fix use-after-free on ABTS_RESP sending

If an abort was rejected by LIO Core qla2xxx sends ABTS_RESP with rejected
status. But it does not save mcmd pointer which is freed right after sending
the response to FW. It leads to use-after-free at the completion from FW.

Use a correct function to send ABTS_RESP when the abort is rejected by LIO Core.

Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
---
 drivers/scsi/qla2xxx/qla_target.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index b9d816b8341e..43eafdc765a3 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -2162,7 +2162,9 @@ static void qlt_do_tmr_work(struct work_struct *work)
 		switch (mcmd->tmr_func) {
 		case QLA_TGT_ABTS:
 			mcmd->fc_tm_rsp = FCP_TMF_REJECTED;
-			qlt_build_abts_resp_iocb(mcmd);
+			qlt_24xx_send_abts_resp(mcmd->qpair,
+						&mcmd->orig_iocb.abts,
+						FCP_TMF_REJECTED, false);
 			break;
 		case QLA_TGT_LUN_RESET:
 		case QLA_TGT_CLEAR_TS:
-- 
2.25.1





BR,
 Dmitry



  reply	other threads:[~2025-09-17 13:06 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-08 18:45 [PATCH 00/15] qla2xxx target mode improvements Tony Battersby
2025-09-08 18:47 ` [PATCH 01/15] Revert "scsi: qla2xxx: Perform lockless command completion in abort path" Tony Battersby
2025-09-08 18:48 ` [PATCH 02/15] scsi: qla2xxx: fix initiator mode with qlini_mode=exclusive Tony Battersby
2025-09-08 18:50 ` [PATCH 03/15] scsi: qla2xxx: fix lost interrupts with qlini_mode=disabled Tony Battersby
2025-09-08 18:51 ` [PATCH 04/15] scsi: qla2xxx: use reinit_completion on mbx_intr_comp Tony Battersby
2025-09-08 18:53 ` [PATCH 05/15] scsi: qla2xxx: remove code for unsupported hardware Tony Battersby
2025-09-08 18:54 ` [PATCH 06/15] scsi: qla2xxx: improve debug output for term exchange Tony Battersby
2025-09-08 18:56 ` [PATCH 07/15] scsi: qla2xxx: fix term exchange when cmd_sent_to_fw == 1 Tony Battersby
2025-09-08 18:58 ` [PATCH 08/15] scsi: qla2xxx: fix oops during cmd abort Tony Battersby
2025-09-08 18:59   ` [SCST PATCH " Tony Battersby
2025-09-11 14:21   ` [PATCH " Dmitry Bogdanov
2025-09-24 19:41     ` Tony Battersby
2025-09-24 19:43       ` [PATCH v2 09/16] scsi: qla2xxx: fix races with aborting commands Tony Battersby
2025-09-24 19:45         ` [SCST PATCH " Tony Battersby
2025-09-25  8:42       ` [DMARC Error]Re: [PATCH 08/15] scsi: qla2xxx: fix oops during cmd abort Dmitry Bogdanov
2025-09-08 19:01 ` [PATCH 09/15] scsi: qla2xxx: improve checks in qlt_xmit_response / qlt_rdy_to_xfer Tony Battersby
2025-09-08 19:02 ` [PATCH 10/15] scsi: qla2xxx: fix TMR failure handling Tony Battersby
2025-09-12 14:36   ` Dmitry Bogdanov
2025-09-16 16:04     ` Tony Battersby
2025-09-17 13:06       ` Dmitry Bogdanov [this message]
2025-09-17 20:38         ` [DMARC Error]Re: " Tony Battersby
2025-09-08 19:04 ` [PATCH 11/15] scsi: qla2xxx: fix invalid memory access with big CDBs Tony Battersby
2025-09-08 19:05   ` [SCST PATCH " Tony Battersby
2025-09-08 19:07 ` [PATCH 12/15] scsi: qla2xxx: add cmd->rsp_sent Tony Battersby
2025-09-08 19:08   ` [SCST PATCH " Tony Battersby
2025-09-15 13:47   ` [PATCH " Dmitry Bogdanov
2025-09-24 20:04     ` Tony Battersby
2025-09-08 19:09 ` [PATCH 13/15] scsi: qla2xxx: improve cmd logging Tony Battersby
2025-09-08 19:10 ` [PATCH 14/15] scsi: qla2xxx: add back SRR support Tony Battersby
2025-09-08 19:11   ` [SCST PATCH " Tony Battersby
2025-09-25 12:49   ` [PATCH " Xose Vazquez Perez
2025-09-25 15:30     ` Xose Vazquez Perez
2025-09-25 16:04       ` Tony Battersby
2025-09-25 17:00         ` Tony Battersby
2025-09-25 19:30           ` Tony Battersby
2025-09-08 19:13 ` [PATCH 15/15] scsi: qla2xxx: improve safety of cmd lookup by handle Tony Battersby
2025-09-08 19:14 ` [SCST PATCH] qla2x00t-32gbit: add on_abort_cmd callback Tony Battersby

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=20250917130641.GD624@yadro.com \
    --to=d.bogdanov@yadro.com \
    --cc=GR-QLogic-Storage-Upstream@marvell.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=njavali@marvell.com \
    --cc=scst-devel@lists.sourceforge.net \
    --cc=target-devel@vger.kernel.org \
    --cc=tonyb@cybernetics.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 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.