Skip to content

Commit

Permalink
hw/nvme: fix null pointer access in ruh update
Browse files Browse the repository at this point in the history
The Reclaim Unit Update operation in I/O Management Receive does not
verify the presence of a configured endurance group prior to accessing
it.

Fix this.

Cc: qemu-stable@nongnu.org
Fixes: 73064ed ("hw/nvme: flexible data placement emulation")
Reviewed-by: Jesper Wendel Devantier <j.devantier@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
(cherry picked from commit 3439ba9)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
birkelund authored and Michael Tokarev committed Sep 10, 2023
1 parent 4332876 commit bb5f903
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion hw/nvme/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4333,7 +4333,13 @@ static uint16_t nvme_io_mgmt_send_ruh_update(NvmeCtrl *n, NvmeRequest *req)
uint32_t npid = (cdw10 >> 1) + 1;
unsigned int i = 0;
g_autofree uint16_t *pids = NULL;
uint32_t maxnpid = n->subsys->endgrp.fdp.nrg * n->subsys->endgrp.fdp.nruh;
uint32_t maxnpid;

if (!ns->endgrp || !ns->endgrp->fdp.enabled) {
return NVME_FDP_DISABLED | NVME_DNR;
}

maxnpid = n->subsys->endgrp.fdp.nrg * n->subsys->endgrp.fdp.nruh;

if (unlikely(npid >= MIN(NVME_FDP_MAXPIDS, maxnpid))) {
return NVME_INVALID_FIELD | NVME_DNR;
Expand Down

0 comments on commit bb5f903

Please sign in to comment.