Commit c4a6f6e7 authored by Hongbo Yao's avatar Hongbo Yao Committed by Greg Kroah-Hartman

nvme-pci: fix out of bounds access in nvme_cqe_pending

[ Upstream commit dcca1662 ]

There is an out of bounds array access in nvme_cqe_peding().

When enable irq_thread for nvme interrupt, there is racing between the
nvmeq->cq_head updating and reading.

nvmeq->cq_head is updated in nvme_update_cq_head(), if nvmeq->cq_head
equals nvmeq->q_depth and before its value set to zero, nvme_cqe_pending()
uses its value as an array index, the index will be out of bounds.
Signed-off-by: default avatarHongbo Yao <>
[hch: slight coding style update]
Signed-off-by: default avatarChristoph Hellwig <>
Signed-off-by: default avatarSasha Levin <>
parent e0b9c207
......@@ -913,9 +913,11 @@ static void nvme_complete_cqes(struct nvme_queue *nvmeq, u16 start, u16 end)
static inline void nvme_update_cq_head(struct nvme_queue *nvmeq)
if (++nvmeq->cq_head == nvmeq->q_depth) {
if (nvmeq->cq_head == nvmeq->q_depth - 1) {
nvmeq->cq_head = 0;
nvmeq->cq_phase = !nvmeq->cq_phase;
} else {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment