diff mbox series

[23/44] iov_iter_get_pages{,_alloc}(): cap the maxsize with MAX_RW_COUNT

Message ID 20220622041552.737754-23-viro@zeniv.linux.org.uk (mailing list archive)
State New, archived
Headers show
Series [01/44] 9p: handling Rerror without copy_from_iter_full() | expand

Commit Message

Al Viro June 22, 2022, 4:15 a.m. UTC
All callers can and should handle iov_iter_get_pages() returning
fewer pages than requested.  All in-kernel ones do.  And it makes
the arithmetical overflow analysis much simpler...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 lib/iov_iter.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Jeff Layton June 28, 2022, 11:41 a.m. UTC | #1
On Wed, 2022-06-22 at 05:15 +0100, Al Viro wrote:
> All callers can and should handle iov_iter_get_pages() returning
> fewer pages than requested.  All in-kernel ones do.  And it makes
> the arithmetical overflow analysis much simpler...
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
>  lib/iov_iter.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/lib/iov_iter.c b/lib/iov_iter.c
> index 30f4158382d6..c3fb7853dbe8 100644
> --- a/lib/iov_iter.c
> +++ b/lib/iov_iter.c
> @@ -1367,6 +1367,8 @@ ssize_t iov_iter_get_pages(struct iov_iter *i,
>  		maxsize = i->count;
>  	if (!maxsize)
>  		return 0;
> +	if (maxsize > MAX_RW_COUNT)
> +		maxsize = MAX_RW_COUNT;
>  
>  	if (likely(user_backed_iter(i))) {
>  		unsigned int gup_flags = 0;
> @@ -1485,6 +1487,8 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,
>  		maxsize = i->count;
>  	if (!maxsize)
>  		return 0;
> +	if (maxsize > MAX_RW_COUNT)
> +		maxsize = MAX_RW_COUNT;
>  
>  	if (likely(user_backed_iter(i))) {
>  		unsigned int gup_flags = 0;


Reviewed-by: Jeff Layton <jlayton@kernel.org>
diff mbox series

Patch

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 30f4158382d6..c3fb7853dbe8 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1367,6 +1367,8 @@  ssize_t iov_iter_get_pages(struct iov_iter *i,
 		maxsize = i->count;
 	if (!maxsize)
 		return 0;
+	if (maxsize > MAX_RW_COUNT)
+		maxsize = MAX_RW_COUNT;
 
 	if (likely(user_backed_iter(i))) {
 		unsigned int gup_flags = 0;
@@ -1485,6 +1487,8 @@  ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,
 		maxsize = i->count;
 	if (!maxsize)
 		return 0;
+	if (maxsize > MAX_RW_COUNT)
+		maxsize = MAX_RW_COUNT;
 
 	if (likely(user_backed_iter(i))) {
 		unsigned int gup_flags = 0;