nvme-pci: fix out of bounds access in nvme_cqe_pending
authorHongbo Yao <yaohongbo@huawei.com>
Mon, 7 Jan 2019 02:22:07 +0000 (10:22 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Feb 2019 09:25:41 +0000 (10:25 +0100)
commit095cfdf857a38972762d92379a848349fda00fe1
tree3caa671e6da4370cdb3465f3a4c62974780645a5
parent1e746fe215eb0e37ff1d91bb894a410e2eb05796
nvme-pci: fix out of bounds access in nvme_cqe_pending

[ Upstream commit dcca1662727220d18fa351097ddff33f95f516c5 ]

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@huawei.com>
[hch: slight coding style update]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/host/pci.c