nvme: Fix parsing of ANA log page
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
@@ -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
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Thanks, applied to nvme-5.4. This is a new branch that was force pushed to replace the previously defunct one with the same name.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerThe 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?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
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
Keith Busch
maintainerQuoted 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