From: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
To: linux-block@vger.kernel.org
Cc: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
Daniel Wagner <dwagner@suse.de>, Hannes Reinecke <hare@suse.de>,
linux-nvme@lists.infradead.org
Subject: [PATCH blktests] nvme/071: add a test for fcloop LS request use-after-free
Date: Mon, 21 Sep 2026 21:56:59 +0700 [thread overview]
Message-ID: <20260921145659.17151-1-ngocthang2710.1999@gmail.com> (raw)
Delete the fcloop remote port and then the target port while an
association is being deleted. The Disconnect Association LS is completed
from a work item that can run after nvmet_fc_unregister_targetport() freed
the pending request, which KASAN reports as a use-after-free in
fcloop_tport_lsrqst_work().
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
---
tests/nvme/071 | 70 ++++++++++++++++++++++++++++++++++++++++++++++
tests/nvme/071.out | 2 ++
2 files changed, 72 insertions(+)
create mode 100755 tests/nvme/071
create mode 100644 tests/nvme/071.out
diff --git a/tests/nvme/071 b/tests/nvme/071
new file mode 100755
index 0000000..d17ef18
--- /dev/null
+++ b/tests/nvme/071
@@ -0,0 +1,70 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2026 Nguyen Ngoc Thang
+#
+# Regression test for a use-after-free in fcloop when the target port is
+# deleted right after the remote port. Deleting the association sends a
+# Disconnect Association LS whose completion is queued while
+# nvmet_fc_unregister_targetport() is flushing nvmet_wq. The pending LS request
+# was freed before that completion ran.
+
+. tests/nvme/rc
+
+DESCRIPTION="delete fcloop target port right after remote port"
+QUICK=1
+
+requires() {
+ _nvme_requires
+ _have_loop
+ _require_nvme_trtype fc
+}
+
+set_conditions() {
+ _set_nvme_trtype "$@"
+}
+
+test() {
+ echo "Running ${TEST_NAME}"
+
+ _setup_nvmet
+
+ local i ports port host_port
+
+ _nvmet_target_setup
+
+ _get_nvmet_ports "${def_subsysnqn}" ports
+ port="${ports[0]}"
+ host_port="${ports_to_hosts[${port}]}"
+
+ for ((i = 0; i < 20; i++)); do
+ _nvme_connect_subsys
+ sleep 0.05
+
+ # Deleting the association sends a Disconnect Association LS.
+ _remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
+ sleep "0.00$(printf "%02d" "${i}")"
+
+ # Remote port first, so the LS can't reach the host anymore.
+ _nvme_fcloop_del_rport "$(_host_wwnn "${host_port}")" \
+ "$(_host_wwpn "${host_port}")" \
+ "$(_remote_wwnn "${port}")" \
+ "$(_remote_wwpn "${port}")"
+ _nvme_fcloop_del_tport "$(_remote_wwnn "${port}")" \
+ "$(_remote_wwpn "${port}")"
+
+ # The host keeps trying to reconnect, drop the controller.
+ _nvme_disconnect_subsys >> "${FULL}" 2>&1
+
+ _nvme_fcloop_add_tport "$(_remote_wwnn "${port}")" \
+ "$(_remote_wwpn "${port}")"
+ _nvme_fcloop_add_rport "$(_host_wwnn "${host_port}")" \
+ "$(_host_wwpn "${host_port}")" \
+ "$(_remote_wwnn "${port}")" \
+ "$(_remote_wwpn "${port}")"
+ _add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
+ done
+
+ _nvmet_target_cleanup
+
+ echo "Test complete"
+}
diff --git a/tests/nvme/071.out b/tests/nvme/071.out
new file mode 100644
index 0000000..146809b
--- /dev/null
+++ b/tests/nvme/071.out
@@ -0,0 +1,2 @@
+Running nvme/071
+Test complete
--
2.43.0
next reply other threads:[~2026-09-21 14:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 14:56 Nguyen Ngoc Thang [this message]
2026-09-23 8:33 ` [PATCH blktests] nvme/071: add a test for fcloop LS request use-after-free Shin'ichiro Kawasaki
2026-09-23 13:53 ` Nguyen Ngoc Thang
2026-09-23 13:49 ` [PATCH blktests v2] " Nguyen Ngoc Thang
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=20260921145659.17151-1-ngocthang2710.1999@gmail.com \
--to=ngocthang2710.1999@gmail.com \
--cc=dwagner@suse.de \
--cc=hare@suse.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=shinichiro.kawasaki@wdc.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