Skip to content

Commit

Permalink
Add KASSERT to ensure sane nsid.
Browse files Browse the repository at this point in the history
All callers are currently filtering bad nsid to this function,
however, we'll have undefined behavior if that's not true. Add the
KASSERT to prevent that.
  • Loading branch information
bsdimp committed May 1, 2020
1 parent 950475c commit d5cc572
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sys/dev/nvme/nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,18 @@ void
nvme_notify_ns(struct nvme_controller *ctrlr, int nsid)
{
struct nvme_consumer *cons;
struct nvme_namespace *ns = &ctrlr->ns[nsid - 1];
struct nvme_namespace *ns;
void *ctrlr_cookie;
uint32_t i;

KASSERT(nsid <= NVME_MAX_NAMESPACES,
("%s: Namespace notification to nsid %d exceeds range\n",
device_get_nameunit(ctrlr->dev), nsid));

if (!ctrlr->is_initialized)
return;

ns = &ctrlr->ns[nsid - 1];
for (i = 0; i < NVME_MAX_CONSUMERS; i++) {
cons = &nvme_consumer[i];
if (cons->id != INVALID_CONSUMER_ID && cons->ns_fn != NULL &&
Expand Down

0 comments on commit d5cc572

Please sign in to comment.