git: 90a63b91ec09 - stable/12 - Add KASSERT to ensure sane nsid.
Warner Losh
imp at FreeBSD.org
Sat Jul 31 00:21:21 UTC 2021
The branch stable/12 has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=90a63b91ec092e94f97d87f0f187cf1d393ee4a0
commit 90a63b91ec092e94f97d87f0f187cf1d393ee4a0
Author: Warner Losh <imp at FreeBSD.org>
AuthorDate: 2020-05-01 21:24:19 +0000
Commit: Warner Losh <imp at FreeBSD.org>
CommitDate: 2021-07-31 00:02:51 +0000
Add KASSERT to ensure sane nsid.
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.
(cherry picked from commit d5cc572ce6009993fb3c4f6c887194b9ec3c9815)
---
sys/dev/nvme/nvme.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/sys/dev/nvme/nvme.c b/sys/dev/nvme/nvme.c
index 97f35afb36da..843aa80bb4fb 100644
--- a/sys/dev/nvme/nvme.c
+++ b/sys/dev/nvme/nvme.c
@@ -291,13 +291,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 &&
More information about the dev-commits-src-all
mailing list