nvme-pci: avoid hmb desc array idx out-of-bound when hmmaxd set.
authorMinwoo Im <minwoo.im.dev@gmail.com>
Thu, 16 Nov 2017 16:34:24 +0000 (01:34 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 3 Feb 2018 16:38:58 +0000 (17:38 +0100)
commit93a4bcf2c4252a518a128df1d017a7d5b1a814c2
tree202299fa7ec5546840018c0ef66f6955f2774d11
parent128dc55f891c79535dbf278e332f0f8fedfa7469
nvme-pci: avoid hmb desc array idx out-of-bound when hmmaxd set.

[ Upstream commit 244a8fe40a09c218622eb9927b9090b0a9b73a1a ]

hmb descriptor idx out-of-bound occurs in case of below conditions.
preferred = 128MiB
chunk_size = 4MiB
hmmaxd = 1

Current code will not allow rmmod which will free hmb descriptors
to be done successfully in above case.

"descs[i]" will be set in for-loop without seeing any conditions
related to "max_entries" after a single "descs" was allocated by
(max_entries = 1) in this case.

Added a condition into for-loop to check index of descriptors.

Fixes: 044a9df1("nvme-pci: implement the HMB entry number and size limitations")
Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
Reviewed-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvme/host/pci.c