diff options
author | Hongbo Yao <yaohongbo@huawei.com> | 2019-01-07 10:22:07 +0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-02-20 10:25:41 +0100 |
commit | 095cfdf857a38972762d92379a848349fda00fe1 (patch) | |
tree | 3caa671e6da4370cdb3465f3a4c62974780645a5 /drivers | |
parent | 1e746fe215eb0e37ff1d91bb894a410e2eb05796 (diff) | |
download | linux-stable-095cfdf857a38972762d92379a848349fda00fe1.tar.gz linux-stable-095cfdf857a38972762d92379a848349fda00fe1.tar.bz2 linux-stable-095cfdf857a38972762d92379a848349fda00fe1.zip |
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/nvme/host/pci.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 40f76b4f08fc..f46313f441ec 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -908,9 +908,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++; } } |