Skip to contentSkip to conversation

nvme: Fix parsing of ANA log page

PATCH Applied Prabhath Sajeepa 5 participants 6 messages Oct 28, 2019 – Oct 30, 2019 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: Fix parsing of ANA log page

Check validity of offset into ANA log buffer before accessing nvme_ana_group_desc. This check ensures the size of ANA log buffer >= offset + sizeof(nvme_ana_group_desc)

---
 drivers/nvme/host/multipath.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/nvme/host/multipath.c +8 -4
index 30de7ef..cbd2b3d 100644
@@ -444,8 +444,14 @@ static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data,
 
 	for (i = 0; i < le16_to_cpu(ctrl->ana_log_buf->ngrps); i++) {
 		struct nvme_ana_group_desc *desc = base + offset;
-		u32 nr_nsids = le32_to_cpu(desc->nnsids);
-		size_t nsid_buf_size = nr_nsids * sizeof(__le32);
+		u32 nr_nsids;
+		size_t nsid_buf_size;
+
+		if (WARN_ON_ONCE(offset > ctrl->ana_log_size - sizeof(*desc)))
+			return -EINVAL;
+
+		nr_nsids = le32_to_cpu(desc->nnsids);
+		nsid_buf_size = nr_nsids * sizeof(__le32);
 
 		if (WARN_ON_ONCE(desc->grpid == 0))
 			return -EINVAL;
@@ -465,8 +471,6 @@ static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data,
 			return error;
 
 		offset += nsid_buf_size;
-		if (WARN_ON_ONCE(offset > ctrl->ana_log_size - sizeof(*desc)))
-			return -EINVAL;
 	}
 
 	return 0;
Signature · 7 lines
2.7.4


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#4 lore raw
Quoted 5 lines · Christoph Hellwig

The only thing this changes is that we now also execute the check for the first entry parsed. But the log size should never be so small for this to matter. Can you explain what problem your are trying to solve?

I had hard time finding out that scenario.

Prabhat, can you please explain ?

Quoted 5 lines

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

maintainer
#5 lore raw
Quoted 10 lines · Chaitanya Kulkarni
Quoted 5 lines · Christoph Hellwig

The only thing this changes is that we now also execute the check for the first entry parsed. But the log size should never be so small for this to matter. Can you explain what problem your are trying to solve?

I had hard time finding out that scenario.

Prabhat, can you please explain ?

The scenario should only apply if the controller reports an invalid nanagrpid of 0, which spec disallows when ANA CMIC is set. We're not validating nanagrpid compliance though, so this "fix" should only help with broken controller implementations.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme