From ed0a9ca2a3cceedc0e6e889472de1cec55ca2faf Mon Sep 17 00:00:00 2001 From: Hans Rosenfeld Date: Mon, 9 Sep 2019 18:04:22 +0000 Subject: 11969 Attempting to attach an invalid nvme namespace will cause a panic Reviewed by: Robert Mustacchi Reviewed by: Jerry Jelinek Reviewed by: Andy Fiddaman Reviewed by: Yuri Pankov Approved by: Richard Lowe --- usr/src/uts/common/io/nvme/nvme.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/usr/src/uts/common/io/nvme/nvme.c b/usr/src/uts/common/io/nvme/nvme.c index d1fa87c881..e37d0598c3 100644 --- a/usr/src/uts/common/io/nvme/nvme.c +++ b/usr/src/uts/common/io/nvme/nvme.c @@ -4550,6 +4550,9 @@ nvme_ioctl_detach(nvme_t *nvme, int nsid, nvme_ioctl_t *nioc, int mode, if (nsid == 0) return (EINVAL); + if (nvme->n_ns[nsid - 1].ns_ignore) + return (0); + rv = bd_detach_handle(nvme->n_ns[nsid - 1].ns_bd_hdl); if (rv != DDI_SUCCESS) rv = EBUSY; @@ -4580,6 +4583,14 @@ nvme_ioctl_attach(nvme_t *nvme, int nsid, nvme_ioctl_t *nioc, int mode, kmem_free(idns, sizeof (nvme_identify_nsid_t)); + if (nvme->n_ns[nsid - 1].ns_ignore) + return (ENOTSUP); + + if (nvme->n_ns[nsid - 1].ns_bd_hdl == NULL) + nvme->n_ns[nsid - 1].ns_bd_hdl = bd_alloc_handle( + &nvme->n_ns[nsid - 1], &nvme_bd_ops, &nvme->n_prp_dma_attr, + KM_SLEEP); + rv = bd_attach_handle(nvme->n_dip, nvme->n_ns[nsid - 1].ns_bd_hdl); if (rv != DDI_SUCCESS) rv = EBUSY; -- cgit v1.2.3