[PATCH][SRU Cosmic] nvme-pci: fix out of bounds access in nvme_cqe_pending

dann frazier dann.frazier at canonical.com
Tue Mar 5 23:24:27 UTC 2019


From: Hongbo Yao <yaohongbo at huawei.com>

BugLink: https://bugs.launchpad.net/bugs/1818747

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: Hongbo Yao <yaohongbo at huawei.com>
[hch: slight coding style update]
Signed-off-by: Christoph Hellwig <hch at lst.de>
(cherry picked from commit dcca1662727220d18fa351097ddff33f95f516c5)
Signed-off-by: dann frazier <dann.frazier at canonical.com>
---
 drivers/nvme/host/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index feac4fef26c57..697ddbb400639 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -980,9 +980,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 {
+		nvmeq->cq_head++;
 	}
 }
 
-- 
2.20.1




More information about the kernel-team mailing list