]> Git Repo - qemu.git/commitdiff
hw/block/nvme: fix assert crash in nvme_subsys_ns
authorKlaus Jensen <[email protected]>
Wed, 7 Apr 2021 05:07:43 +0000 (07:07 +0200)
committerKlaus Jensen <[email protected]>
Wed, 7 Apr 2021 08:48:32 +0000 (10:48 +0200)
nvme_subsys_ns() is used in contexts where the namespace identifier is
taken from an untrusted source. Commit 3921756dee6d ("hw/block/nvme:
assert namespaces array indices") tried to guard against this by
introducing an assert on the namespace identifier.

This is wrong since it is perfectly valid to call the function with an
invalid namespace identifier and like nvme_ns(), nvme_subsys_ns() should
simply return NULL.

Fixes: 3921756dee6d ("hw/block/nvme: assert namespaces array indices")
Fixes: 94d8d6d16781 ("hw/block/nvme: support allocated namespace type")
Cc: Minwoo Im <[email protected]>
Signed-off-by: Klaus Jensen <[email protected]>
Reviewed-by: Minwoo Im <[email protected]>
hw/block/nvme-subsys.h

index 24132edd005c8374642f1dd4ce17a2cf7ae26142..1cbcad9be23e9fe3e8295cbfa2c86891ce00bbb9 100644 (file)
@@ -49,12 +49,10 @@ static inline NvmeCtrl *nvme_subsys_ctrl(NvmeSubsystem *subsys,
 static inline NvmeNamespace *nvme_subsys_ns(NvmeSubsystem *subsys,
         uint32_t nsid)
 {
-    if (!subsys) {
+    if (!subsys || !nsid || nsid > NVME_MAX_NAMESPACES) {
         return NULL;
     }
 
-    assert(nsid && nsid <= NVME_MAX_NAMESPACES);
-
     return subsys->namespaces[nsid];
 }
 
This page took 0.028752 seconds and 4 git commands to generate.