Skip to contentSkip to conversation

block/nvme: Fix possible array index out of bounds in nvme_process_completion()

PATCH New Alex Chen 1 participant 1 message Dec 8, 2020 Block layer

lore
Share & tools
lore

Alex Chen

author
#0 lore raw

PATCH 1/1 block/nvme: Fix possible array index out of bounds in nvme_process_completion()

The range of 'cid' is [1, NVME_QUEUE_SIZE-1], so when 'cid' is equal to NVME_QUEUE_SIZE, it should be continued, otherwise it will lead to array index out of bounds when accessing 'q->reqs[cid-1]'

---
 block/nvme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/nvme.c +1 -1
index a06a188d53..3a2b3f5486 100644
@@ -402,7 +402,7 @@ static bool nvme_process_completion(NVMeQueuePair *q)
             q->cq_phase = !q->cq_phase;
         }
         cid = le16_to_cpu(c->cid);
-        if (cid == 0 || cid > NVME_QUEUE_SIZE) {
+        if (cid == 0 || cid >= NVME_QUEUE_SIZE) {
             warn_report("NVMe: Unexpected CID in completion queue: %"PRIu32", "
                         "queue size: %u", cid, NVME_QUEUE_SIZE);
             continue;
Signature · 1 line
2.19.1