Skip to contentSkip to conversation

nvmet: fix NULL pointer dereference in nvmet_execute_identify_ns_zns()

PATCH Applied Guixin Liu 4 participants 4 messages Aug 4 – Aug 10

Subsystems (2)
lore
Share & tools
lore

Guixin Liu

author
#0 lore raw

PATCH 1/1 nvmet: fix NULL pointer dereference in nvmet_execute_identify_ns_zns()

When a host issues an Identify command with CNS 05h (I/O Command Set specific Identify Namespace) and CSI 02h (ZNS) targeting a file-backed namespace, nvmet_execute_identify_ns_zns() calls bdev_is_zoned() on req->ns->bdev. A file-backed namespace has no block device, so req->ns->bdev is NULL and bdev_is_zoned() dereferences it, oopsing.

The I/O command set is selected by the host-supplied CSI field and the command is routed here whenever CONFIG_BLK_DEV_ZONED is enabled, independent of the namespace backing type, so any file-backed namespace is exposed.

Reject the command with Invalid Field when the namespace is not backed by a block device.

Fixes aaf2e048af27 ("nvmet: add ZBD over ZNS backend support")
---
 drivers/nvme/target/zns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/zns.c +1 -1
index f00921931eb6..a13befd5f3ad 100644
@@ -116,7 +116,7 @@ void nvmet_execute_identify_ns_zns(struct nvmet_req *req)
 		mutex_unlock(&req->ns->subsys->lock);
 	}
 
-	if (!bdev_is_zoned(req->ns->bdev)) {
+	if (!req->ns->bdev || !bdev_is_zoned(req->ns->bdev)) {
 		status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
 		req->error_loc = offsetof(struct nvme_identify, nsid);
 		goto out;
Signature · 1 line
2.43.7
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Guixin Liu

When a host issues an Identify command with CNS 05h (I/O Command Set specific Identify Namespace) and CSI 02h (ZNS) targeting a file-backed namespace, nvmet_execute_identify_ns_zns() calls bdev_is_zoned() on req->ns->bdev. A file-backed namespace has no block device, so req->ns->bdev is NULL and bdev_is_zoned() dereferences it, oopsing.

The I/O command set is selected by the host-supplied CSI field and the command is routed here whenever CONFIG_BLK_DEV_ZONED is enabled, independent of the namespace backing type, so any file-backed namespace is exposed.

Quoted 5 lines

Reject the command with Invalid Field when the namespace is not backed by a block device.

Fixes aaf2e048af27 ("nvmet: add ZBD over ZNS backend support")

Looks good to me.

Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer Applied
#3 lore raw
In reply to Guixin Liu
Quoted 5 lines · Guixin Liu

When a host issues an Identify command with CNS 05h (I/O Command Set specific Identify Namespace) and CSI 02h (ZNS) targeting a file-backed namespace, nvmet_execute_identify_ns_zns() calls bdev_is_zoned() on req->ns->bdev. A file-backed namespace has no block device, so req->ns->bdev is NULL and bdev_is_zoned() dereferences it, oopsing.

Thanks, applied to nvme-7.3.