All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH blktests] nvme/070: add a test for Identify CNS 07h NULL pointer dereference
@ 2026-07-31  3:26 Guixin Liu
  2026-08-01 14:01 ` Nilay Shroff
  0 siblings, 1 reply; 4+ messages in thread
From: Guixin Liu @ 2026-07-31  3:26 UTC (permalink / raw)
  To: shinichiro.kawasaki, Keith Busch, Jens Axboe, Christoph Hellwig,
	Sagi Grimberg, Hannes Reinecke, nilay, Chaitanya Kulkarni,
	Kanchan Joshi
  Cc: linux-nvme

nvmet_execute_identify_nslist() handles both the Active Namespace ID list
(CNS 02h) and the per-command-set variant (CNS 07h). For CNS 07h it
filtered the list on req->ns->csi, but this handler never resolves
req->ns, so it is always NULL. As soon as an enabled namespace with an
NSID above the requested value exists, the target dereferenced a NULL
pointer and oopsed.

This test connects a target with a single namespace and issues an
Identify with CNS 07h starting from NSID 0, which is exactly the
condition that triggered the crash. Without the kernel fix [0] the target
oopses; with it the command completes normally.

[0] https://lore.kernel.org/linux-nvme/20260730043105.3071328-2-kanie@linux.alibaba.com/

Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
 tests/nvme/070     | 54 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/nvme/070.out |  2 ++
 2 files changed, 56 insertions(+)
 create mode 100755 tests/nvme/070
 create mode 100644 tests/nvme/070.out

diff --git a/tests/nvme/070 b/tests/nvme/070
new file mode 100755
index 0000000..1f29a69
--- /dev/null
+++ b/tests/nvme/070
@@ -0,0 +1,54 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2026 Guixin Liu
+#
+# Regression test for the NULL pointer dereference in
+# nvmet_execute_identify_nslist() when handling Identify CNS 07h (Active
+# Namespace ID List for the specified I/O Command Set). The CNS 07h handler
+# filtered the list on req->ns->csi, but this handler never resolves req->ns
+# so it is always NULL. As soon as an enabled namespace with an NSID above the
+# requested value exists, the target dereferenced a NULL pointer and oopsed.
+
+. tests/nvme/rc
+
+DESCRIPTION="issue Identify CNS 07h (per-command-set active NS list)"
+QUICK=1
+
+requires() {
+	_nvme_requires
+	_have_loop
+	_require_nvme_trtype_is_fabrics
+}
+
+set_conditions() {
+	_set_nvme_trtype "$@"
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	_setup_nvmet
+
+	_nvmet_target_setup
+
+	_nvme_connect_subsys
+
+	local nvmedev
+	nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
+
+	# CNS 07h == Active Namespace ID list for the specified I/O Command Set.
+	# CDW10 bits[7:0] hold the CNS; CDW11 bits[31:24] hold the CSI (0 == NVM).
+	# Request from NSID 0 so the enabled namespace (NSID 1) is listed, which
+	# is exactly the condition that used to dereference the NULL req->ns.
+	if ! nvme admin-passthru "/dev/${nvmedev}" --opcode=0x06 \
+		--namespace-id=0 --cdw10=0x07 --cdw11=0 --data-len=4096 -r \
+		>> "${FULL}" 2>&1; then
+		echo "Error: Identify CNS 07h failed"
+	fi
+
+	_nvme_disconnect_subsys
+
+	_nvmet_target_cleanup
+
+	echo "Test complete"
+}
diff --git a/tests/nvme/070.out b/tests/nvme/070.out
new file mode 100644
index 0000000..b765a28
--- /dev/null
+++ b/tests/nvme/070.out
@@ -0,0 +1,2 @@
+Running nvme/070
+Test complete
-- 
2.43.7



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH blktests] nvme/070: add a test for Identify CNS 07h NULL pointer dereference
  2026-07-31  3:26 [PATCH blktests] nvme/070: add a test for Identify CNS 07h NULL pointer dereference Guixin Liu
@ 2026-08-01 14:01 ` Nilay Shroff
  2026-08-03  4:14   ` Shin'ichiro Kawasaki
  0 siblings, 1 reply; 4+ messages in thread
From: Nilay Shroff @ 2026-08-01 14:01 UTC (permalink / raw)
  To: Guixin Liu, shinichiro.kawasaki, Keith Busch, Jens Axboe,
	Christoph Hellwig, Sagi Grimberg, Hannes Reinecke,
	Chaitanya Kulkarni, Kanchan Joshi
  Cc: linux-nvme

On 7/31/26 8:56 AM, Guixin Liu wrote:
> +test() {
> +	echo "Running ${TEST_NAME}"
> +
> +	_setup_nvmet
> +
> +	_nvmet_target_setup
> +
> +	_nvme_connect_subsys
> +
> +	local nvmedev
> +	nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
> +
> +	# CNS 07h == Active Namespace ID list for the specified I/O Command Set.
> +	# CDW10 bits[7:0] hold the CNS; CDW11 bits[31:24] hold the CSI (0 == NVM).
> +	# Request from NSID 0 so the enabled namespace (NSID 1) is listed, which
> +	# is exactly the condition that used to dereference the NULL req->ns.
> +	if ! nvme admin-passthru "/dev/${nvmedev}" --opcode=0x06 \
> +		--namespace-id=0 --cdw10=0x07 --cdw11=0 --data-len=4096 -r \
> +		>> "${FULL}" 2>&1; then
> +		echo "Error: Identify CNS 07h failed"
> +	fi

The nvme admin-passthru ... works but why instead not use the existing
"nvme list-ns /dev/<nvmedev> --csi=0 ?

Thanks,
--Nilay


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH blktests] nvme/070: add a test for Identify CNS 07h NULL pointer dereference
  2026-08-01 14:01 ` Nilay Shroff
@ 2026-08-03  4:14   ` Shin'ichiro Kawasaki
  2026-08-04  2:37     ` Guixin Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Shin'ichiro Kawasaki @ 2026-08-03  4:14 UTC (permalink / raw)
  To: Nilay Shroff
  Cc: Guixin Liu, Keith Busch, Jens Axboe, Christoph Hellwig,
	Sagi Grimberg, Hannes Reinecke, Chaitanya Kulkarni, Kanchan Joshi,
	linux-nvme

On Aug 01, 2026 / 19:31, Nilay Shroff wrote:
> On 7/31/26 8:56 AM, Guixin Liu wrote:
> > +test() {
> > +	echo "Running ${TEST_NAME}"
> > +
> > +	_setup_nvmet
> > +
> > +	_nvmet_target_setup
> > +
> > +	_nvme_connect_subsys
> > +
> > +	local nvmedev
> > +	nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
> > +
> > +	# CNS 07h == Active Namespace ID list for the specified I/O Command Set.
> > +	# CDW10 bits[7:0] hold the CNS; CDW11 bits[31:24] hold the CSI (0 == NVM).
> > +	# Request from NSID 0 so the enabled namespace (NSID 1) is listed, which
> > +	# is exactly the condition that used to dereference the NULL req->ns.
> > +	if ! nvme admin-passthru "/dev/${nvmedev}" --opcode=0x06 \
> > +		--namespace-id=0 --cdw10=0x07 --cdw11=0 --data-len=4096 -r \
> > +		>> "${FULL}" 2>&1; then
> > +		echo "Error: Identify CNS 07h failed"
> > +	fi
> 
> The nvme admin-passthru ... works but why instead not use the existing
> "nvme list-ns /dev/<nvmedev> --csi=0 ?

The patch looks good to me. I also confirmed that the test case recreates the
NULL pointer dereference that the kernel patch "nvmet: fix NULL pointer
dereference in nvmet_execute_identify_nslist()" fixes. Good.

I also confirmed that "nvme list-ns /dev/<nvmedev> --csi=0" can recreate the
NULL pointer dereference. I'm okay either way admin-passthru or list-ns. I
would like to know Guixin's view about it.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH blktests] nvme/070: add a test for Identify CNS 07h NULL pointer dereference
  2026-08-03  4:14   ` Shin'ichiro Kawasaki
@ 2026-08-04  2:37     ` Guixin Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Guixin Liu @ 2026-08-04  2:37 UTC (permalink / raw)
  To: Shin'ichiro Kawasaki, Nilay Shroff
  Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	Hannes Reinecke, Chaitanya Kulkarni, Kanchan Joshi, linux-nvme



在 2026/8/3 12:14, Shin'ichiro Kawasaki 写道:
> On Aug 01, 2026 / 19:31, Nilay Shroff wrote:
>> On 7/31/26 8:56 AM, Guixin Liu wrote:
>>> +test() {
>>> +	echo "Running ${TEST_NAME}"
>>> +
>>> +	_setup_nvmet
>>> +
>>> +	_nvmet_target_setup
>>> +
>>> +	_nvme_connect_subsys
>>> +
>>> +	local nvmedev
>>> +	nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
>>> +
>>> +	# CNS 07h == Active Namespace ID list for the specified I/O Command Set.
>>> +	# CDW10 bits[7:0] hold the CNS; CDW11 bits[31:24] hold the CSI (0 == NVM).
>>> +	# Request from NSID 0 so the enabled namespace (NSID 1) is listed, which
>>> +	# is exactly the condition that used to dereference the NULL req->ns.
>>> +	if ! nvme admin-passthru "/dev/${nvmedev}" --opcode=0x06 \
>>> +		--namespace-id=0 --cdw10=0x07 --cdw11=0 --data-len=4096 -r \
>>> +		>> "${FULL}" 2>&1; then
>>> +		echo "Error: Identify CNS 07h failed"
>>> +	fi
>> The nvme admin-passthru ... works but why instead not use the existing
>> "nvme list-ns /dev/<nvmedev> --csi=0 ?
> The patch looks good to me. I also confirmed that the test case recreates the
> NULL pointer dereference that the kernel patch "nvmet: fix NULL pointer
> dereference in nvmet_execute_identify_nslist()" fixes. Good.
>
> I also confirmed that "nvme list-ns /dev/<nvmedev> --csi=0" can recreate the
> NULL pointer dereference. I'm okay either way admin-passthru or list-ns. I
> would like to know Guixin's view about it.

I think nvme list-ns /dev/<nvmedev> --csi=0 is better, I will change this in v2, thanks.

Best Regards,
Guixin Liu




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-04  2:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-31  3:26 [PATCH blktests] nvme/070: add a test for Identify CNS 07h NULL pointer dereference Guixin Liu
2026-08-01 14:01 ` Nilay Shroff
2026-08-03  4:14   ` Shin'ichiro Kawasaki
2026-08-04  2:37     ` Guixin Liu

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.