svn commit: r360550 - head/sys/dev/nvme

Warner Losh imp at FreeBSD.org
Fri May 1 21:24:24 UTC 2020


Author: imp
Date: Fri May  1 21:24:19 2020
New Revision: 360550
URL: https://svnweb.freebsd.org/changeset/base/360550

Log:
  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.

Modified:
  head/sys/dev/nvme/nvme.c

Modified: head/sys/dev/nvme/nvme.c
==============================================================================
--- head/sys/dev/nvme/nvme.c	Fri May  1 21:24:15 2020	(r360549)
+++ head/sys/dev/nvme/nvme.c	Fri May  1 21:24:19 2020	(r360550)
@@ -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 &&


More information about the svn-src-all mailing list