Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 May 2020 21:24:20 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r360550 - head/sys/dev/nvme
Message-ID:  <202005012124.041LOKec096213@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 &&



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005012124.041LOKec096213>