nvme-tcp: fix possible data corruption with bio merges
authorSagi Grimberg <sagi@grimberg.me>
Wed, 13 Jan 2021 21:56:57 +0000 (13:56 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Jan 2021 17:27:30 +0000 (18:27 +0100)
commitb1e9f635a5e3a2f2ba7461f73426ad54d247ac9c
treef1f3ae0f8cf7177dc4f15c25e9ed4958b6c37aa6
parentc09af1ee7c232d22b0264fbc69b997b1b851ade8
nvme-tcp: fix possible data corruption with bio merges

commit ca1ff67d0fb14f39cf0cc5102b1fbcc3b14f6fb9 upstream.

When a bio merges, we can get a request that spans multiple
bios, and the overall request payload size is the sum of
all bios. When we calculate how much we need to send
from the existing bio (and bvec), we did not take into
account the iov_iter byte count cap.

Since multipage bvecs support, bvecs can split in the middle
which means that when we account for the last bvec send we
should also take the iov_iter byte count cap as it might be
lower than the last bvec size.

Reported-by: Hao Wang <pkuwangh@gmail.com>
Fixes: 3f2304f8c6d6 ("nvme-tcp: add NVMe over TCP host driver")
Tested-by: Hao Wang <pkuwangh@gmail.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvme/host/tcp.c