nvmet-tcp: fix out-of-bounds access when receiving multiple h2cdata PDUs
authorSagi Grimberg <sagi@grimberg.me>
Wed, 3 Feb 2021 09:20:25 +0000 (01:20 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Feb 2021 08:29:15 +0000 (09:29 +0100)
commitc1debbaf158d674f64ce75e98266d01731e97c21
tree78e3434dc110e25d1a5b03e9d4b8c21a041b8053
parentb9464c5f4663442bdf5f53550eaf30fe0f28b517
nvmet-tcp: fix out-of-bounds access when receiving multiple h2cdata PDUs

[ Upstream commit cb8563f5c735a042ea2dd7df1ad55ae06d63ffeb ]

When the host sends multiple h2cdata PDUs, we keep track on
the receive progress and calculate the scatterlist index and
offsets.

The issue is that sg_offset should only be kept for the first
iov entry we map in the iovec as this is the difference between
our cursor and the sg entry offset itself.

In addition, the sg index was calculated wrong because we should
not round up when dividing the command byte offset with PAG_SIZE.

Fixes: 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
Reported-by: Narayan Ayalasomayajula <Narayan.Ayalasomayajula@wdc.com>
Tested-by: Narayan Ayalasomayajula <Narayan.Ayalasomayajula@wdc.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/target/tcp.c