iov_iter: Fix iov_iter_get_pages{,_alloc} page fault return value
authorAndreas Gruenbacher <agruenba@redhat.com>
Wed, 21 Jul 2021 17:03:47 +0000 (19:03 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Nov 2021 18:16:15 +0000 (19:16 +0100)
commitc45c83c1716f3eac30bfdf21c60f1f09b8e598c2
tree19749213bce1b3ed6290326dfefb8ad24c8aa106
parentd78de051ff328f98cd534d4bc1bfee1f4f829f61
iov_iter: Fix iov_iter_get_pages{,_alloc} page fault return value

[ Upstream commit 814a66741b9ffb5e1ba119e368b178edb0b7322d ]

Both iov_iter_get_pages and iov_iter_get_pages_alloc return the number
of bytes of the iovec they could get the pages for.  When they cannot
get any pages, they're supposed to return 0, but when the start of the
iovec isn't page aligned, the calculation goes wrong and they return a
negative value.  Fix both functions.

In addition, change iov_iter_get_pages_alloc to return NULL in that case
to prevent resource leaks.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
lib/iov_iter.c