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. Commit3921756dee
("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:3921756dee
("hw/block/nvme: assert namespaces array indices") Fixes:94d8d6d167
("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>
This commit is contained in:
parent
8eb5c8069a
commit
ec20329748
@ -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];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user