Skip to content

Commit b600866

Browse files
Andreas Gruenbachergregkh
authored andcommitted
iov_iter: Fix iov_iter_get_pages{,_alloc} page fault return value
[ Upstream commit 814a667 ] 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>
1 parent 219df0f commit b600866

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

lib/iov_iter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ ssize_t iov_iter_get_pages(struct iov_iter *i,
13431343
res = get_user_pages_fast(addr, n,
13441344
iov_iter_rw(i) != WRITE ? FOLL_WRITE : 0,
13451345
pages);
1346-
if (unlikely(res < 0))
1346+
if (unlikely(res <= 0))
13471347
return res;
13481348
return (res == n ? len : res * PAGE_SIZE) - *start;
13491349
0;}),({
@@ -1424,8 +1424,9 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,
14241424
return -ENOMEM;
14251425
res = get_user_pages_fast(addr, n,
14261426
iov_iter_rw(i) != WRITE ? FOLL_WRITE : 0, p);
1427-
if (unlikely(res < 0)) {
1427+
if (unlikely(res <= 0)) {
14281428
kvfree(p);
1429+
*pages = NULL;
14291430
return res;
14301431
}
14311432
*pages = p;

0 commit comments

Comments
 (0)