linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mimi Zohar <zohar@linux.ibm.com>
To: Eric Biggers <ebiggers@kernel.org>,
	linux-fsdevel@vger.kernel.org,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>,
	Dmitry Kasatkin <dmitry.kasatkin@huawei.com>
Subject: Re: [PATCH] vfs: require i_size <= SIZE_MAX in kernel_read_file()
Date: Fri, 21 Sep 2018 14:42:15 -0400	[thread overview]
Message-ID: <1537555335.3830.344.camel@linux.ibm.com> (raw)
In-Reply-To: <20180907191624.186623-1-ebiggers@kernel.org>

On Fri, 2018-09-07 at 12:16 -0700, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> On 32-bit systems, the buffer allocated by kernel_read_file() is too
> small if the file size is > SIZE_MAX, due to truncation to size_t.
> 
> Fortunately, since the 'count' argument to kernel_read() is also
> truncated to size_t, only the allocated space is filled; then, -EIO is
> returned since 'pos != i_size' after the read loop.
> 
> But this is not obvious and seems incidental.  We should be more
> explicit about this case.  So, fail early if i_size > SIZE_MAX.
> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>

Thanks!

> ---
>  fs/exec.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/exec.c b/fs/exec.c
> index 1ebf6e5a521d..fc281b738a98 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -908,14 +908,14 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size,
>  		goto out;
> 
>  	i_size = i_size_read(file_inode(file));
> -	if (max_size > 0 && i_size > max_size) {
> -		ret = -EFBIG;
> -		goto out;
> -	}
>  	if (i_size <= 0) {
>  		ret = -EINVAL;
>  		goto out;
>  	}
> +	if (i_size > SIZE_MAX || (max_size > 0 && i_size > max_size)) {
> +		ret = -EFBIG;
> +		goto out;
> +	}
> 
>  	if (id != READING_FIRMWARE_PREALLOC_BUFFER)
>  		*buf = vmalloc(i_size);

  reply	other threads:[~2018-09-22  0:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-07 19:16 [PATCH] vfs: require i_size <= SIZE_MAX in kernel_read_file() Eric Biggers
2018-09-21 18:42 ` Mimi Zohar [this message]
2018-10-03 23:43 ` Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1537555335.3830.344.camel@linux.ibm.com \
    --to=zohar@linux.ibm.com \
    --cc=dmitry.kasatkin@huawei.com \
    --cc=ebiggers@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zohar@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).