diff options
author | Klaus Jensen <k.jensen@samsung.com> | 2021-04-07 07:07:43 +0200 |
---|---|---|
committer | Klaus Jensen <k.jensen@samsung.com> | 2021-04-07 10:48:32 +0200 |
commit | ec20329748d02728b823443436fe26eadb04f8cc (patch) | |
tree | 17c4e239670f5d48e9a969755cb629d7a1db2aaa /hw | |
parent | 8eb5c8069a5ccb8dadf35765b6f9cca10fb98b84 (diff) | |
download | qemu-ec20329748d02728b823443436fe26eadb04f8cc.zip qemu-ec20329748d02728b823443436fe26eadb04f8cc.tar.gz qemu-ec20329748d02728b823443436fe26eadb04f8cc.tar.bz2 |
hw/block/nvme: fix assert crash in nvme_subsys_ns
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 <minwoo.im.dev@gmail.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Minwoo Im <minwoo.im.dev@gmail.com>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/block/nvme-subsys.h | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h index 24132ed..1cbcad9 100644 --- a/hw/block/nvme-subsys.h +++ b/hw/block/nvme-subsys.h @@ -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]; } |