nvme-multipath: avoid size_t underflow in ANA log bounds checks
PATCH 1/1 nvme-multipath: avoid size_t underflow in ANA log bounds checks
The ANA log bounds checks subtract the required size from ana_log_size in unsigned arithmetic, which can wrap when a rogue or buggy target reports an oversized nnsids. Compare as "ana_log_size - offset < required" instead, so the subtraction can't underflow and bypass the check.
Signed-off-by Martin George <[email protected]>
--- drivers/nvme/host/multipath.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/multipath.c +2 -2
@@ -878,7 +878,7 @@ static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data,u32 nr_nsids;size_t nsid_buf_size; -if (WARN_ON_ONCE (offset > ctrl->ana_log_size -sizeof (*desc))) +if (WARN_ON_ONCE (ctrl->ana_log_size - offset <sizeof (*desc)))return -EINVAL ; nr_nsids =le32_to_cpu (desc->nnsids);
@@ -894,7 +894,7 @@ static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data,return -EINVAL ; offset +=sizeof (*desc); -if (WARN_ON_ONCE (offset > ctrl->ana_log_size - nsid_buf_size)) +if (WARN_ON_ONCE (ctrl->ana_log_size - offset < nsid_buf_size))return -EINVAL ; error =cb (ctrl, desc, data);
Signature · 1 line
2.43.0
Keith Busch
maintainerQuoted 4 lines · Martin George
The ANA log bounds checks subtract the required size from
ana_log_sizein unsigned arithmetic, which can wrap when a rogue or buggy target reports an oversized nnsids. Compare as "ana_log_size- offset < required" instead, so the subtraction can't underflow and bypass the check.
Looks good, applied to nvme-7.4.