Skip to contentSkip to conversation

nvme/070: add a test for Identify CNS 07h NULL pointer dereference

PATCH In review Guixin Liu 4 participants 6 messages Aug 4 – Sep 17 NVMe

lore
Share & tools
lore

Guixin Liu

author
#0 lore raw

PATCH v2 1/1 nvme/070: add a test for Identify CNS 07h NULL pointer dereference

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/[email protected]/

---
v1 -> v2:
- Use "nvme list-ns --csi=0" instead of a raw admin-passthru to issue Identify CNS 07h, as suggested by Nilay and Shinichiro; it drives the same target code path via the existing nvme-cli subcommand.

 tests/nvme/070     | 52 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/nvme/070.out |  2 ++
 2 files changed, 54 insertions(+)
 create mode 100755 tests/nvme/070
 create mode 100644 tests/nvme/070.out
tests/nvme/070 new file +52 -0
new file mode 100755
index 0000000..b7d8bc5
@@ -0,0 +1,52 @@
+#!/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}")
+
+	# "nvme list-ns --csi=0" issues Identify CNS 07h (Active Namespace ID
+	# list for the specified I/O Command Set, here NVM), starting from NSID
+	# 0 so the enabled namespace (NSID 1) is listed. That is exactly the
+	# condition that used to dereference the NULL req->ns in the target.
+	if ! nvme list-ns "/dev/${nvmedev}" --csi=0 >> "${FULL}" 2>&1; then
+		echo "Error: Identify CNS 07h (list-ns --csi=0) failed"
+	fi
+
+	_nvme_disconnect_subsys
+
+	_nvmet_target_cleanup
+
+	echo "Test complete"
+}
tests/nvme/070.out new file +2 -0
new file mode 100644
index 0000000..b765a28
@@ -0,0 +1,2 @@
+Running nvme/070
+Test complete
Signature · 1 line
2.43.7
Reviewed-by on v2 1/1
#1 lore raw
Quoted 92 lines · Guixin Liu

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/[email protected]/

---
v1 -> v2:
- Use "nvme list-ns --csi=0" instead of a raw admin-passthru to issue Identify CNS 07h, as suggested by Nilay and Shinichiro; it drives the same target code path via the existing nvme-cli subcommand.

  tests/nvme/070     | 52 ++++++++++++++++++++++++++++++++++++++++++++++
  tests/nvme/070.out |  2 ++
  2 files changed, 54 insertions(+)

create mode 100755 tests/nvme/070
create mode 100644 tests/nvme/070.out

tests/nvme/070 new file +52 -0
new file mode 100755
index 0000000..b7d8bc5
@@ -0,0 +1,52 @@
+#!/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}")
+
+	# "nvme list-ns --csi=0" issues Identify CNS 07h (Active Namespace ID
+	# list for the specified I/O Command Set, here NVM), starting from NSID
+	# 0 so the enabled namespace (NSID 1) is listed. That is exactly the
+	# condition that used to dereference the NULL req->ns in the target.
+	if ! nvme list-ns "/dev/${nvmedev}" --csi=0 >> "${FULL}" 2>&1; then
+		echo "Error: Identify CNS 07h (list-ns --csi=0) failed"
+	fi
+
+	_nvme_disconnect_subsys
+
+	_nvmet_target_cleanup
+
+	echo "Test complete"
+}
tests/nvme/070.out new file +0 -0
new file mode 100644
index 0000000..b765a28

tests/nvme/070.out line 2

Quoted 2 lines
tests/nvme/070.out new file +2 -0
@@ -0,0 +1,2 @@
+Running nvme/070
+Test complete

Looks good to me.

Reviewed-by on v2 1/1
#2 lore raw
In reply to Guixin Liu
Quoted 14 lines · Guixin Liu

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/[email protected]/

Quoted 8 lines

---
v1 -> v2:
- Use "nvme list-ns --csi=0" instead of a raw admin-passthru to issue Identify CNS 07h, as suggested by Nilay and Shinichiro; it drives the same target code path via the existing nvme-cli subcommand.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
#3 lore raw
In reply to Guixin Liu
Quoted 14 lines · Guixin Liu

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/[email protected]/

Quoted 7 lines

---
v1 -> v2:
- Use "nvme list-ns --csi=0" instead of a raw admin-passthru to issue Identify CNS 07h, as suggested by Nilay and Shinichiro; it drives the same target code path via the existing nvme-cli subcommand.

Thanks for this v2 patch. It looks good to me. I will wait for the kernel side fix get settled on Linus master branch before I apply this patch.

author
#4 lore raw
Quoted 22 lines · Shin'ichiro Kawasaki
Quoted 14 lines · Guixin Liu

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/[email protected]/

Quoted 7 lines

---
v1 -> v2:
- Use "nvme list-ns --csi=0" instead of a raw admin-passthru to issue Identify CNS 07h, as suggested by Nilay and Shinichiro; it drives the same target code path via the existing nvme-cli subcommand.

Quoted 2 lines

Thanks for this v2 patch. It looks good to me. I will wait for the kernel side fix get settled on Linus master branch before I apply this patch.

Hi Shin'ichiro, the kernel side fix patch is already applied to master, could you please apply this patch?

Best Regards,
Guixin Liu

#5 lore raw

On Sep 16, 2026 / 19:40, Guixin Liu wrote:
[...]

Quoted 2 lines

Hi Shin'ichiro, the kernel side fix patch is already applied to master, could you please apply this patch?

Thanks for the heads-up. I applied the patch.