The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Jeff Layton <jlayton@redhat.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org, hch@infradead.org, rlove@google.com,
	msb@google.com, viro@zeniv.linux.org.uk
Subject: Re: [PATCH 2/4] vfs: explicitly cast s_maxbytes in fiemap_check_ranges
Date: Sat, 8 Aug 2009 00:12:52 +0200	[thread overview]
Message-ID: <20090807221252.GA28019@cmpxchg.org> (raw)
In-Reply-To: <1249671461-9071-3-git-send-email-jlayton@redhat.com>

On Fri, Aug 07, 2009 at 02:57:39PM -0400, Jeff Layton wrote:
> If fiemap_check_ranges is passed a large enough value, then it's
> possible that the value would be cast to a signed value for comparison
> against s_maxbytes when we change it to loff_t. Make sure that doesn't
> happen by explicitly casting s_maxbytes to an unsigned value for the
> purposes of comparison.

I think this is unneeded, C garuantees that in this case the signed
value will get promoted to an unsigned value, not the other way round.

	Hannes

> Signed-off-by: Jeff Layton <jlayton@redhat.com>
> ---
>  fs/ioctl.c |    9 +++++----
>  1 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ioctl.c b/fs/ioctl.c
> index 5612880..7b17a14 100644
> --- a/fs/ioctl.c
> +++ b/fs/ioctl.c
> @@ -162,20 +162,21 @@ EXPORT_SYMBOL(fiemap_check_flags);
>  static int fiemap_check_ranges(struct super_block *sb,
>  			       u64 start, u64 len, u64 *new_len)
>  {
> +	u64 maxbytes = (u64) sb->s_maxbytes;
> +
>  	*new_len = len;
>  
>  	if (len == 0)
>  		return -EINVAL;
>  
> -	if (start > sb->s_maxbytes)
> +	if (start > maxbytes)
>  		return -EFBIG;
>  
>  	/*
>  	 * Shrink request scope to what the fs can actually handle.
>  	 */
> -	if ((len > sb->s_maxbytes) ||
> -	    (sb->s_maxbytes - len) < start)
> -		*new_len = sb->s_maxbytes - start;
> +	if (len > maxbytes || (maxbytes - len) < start)
> +		*new_len = maxbytes - start;
>  
>  	return 0;
>  }
> -- 
> 1.6.0.6
> 

  reply	other threads:[~2009-08-07 22:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-07 18:57 [PATCH 0/4] vfs: change sb->s_maxbytes to loff_t Jeff Layton
2009-08-07 18:57 ` [PATCH 1/4] vfs: make get_sb_pseudo set s_maxbytes to value that can be cast to signed Jeff Layton
2009-08-07 22:28   ` Johannes Weiner
2009-08-07 18:57 ` [PATCH 2/4] vfs: explicitly cast s_maxbytes in fiemap_check_ranges Jeff Layton
2009-08-07 22:12   ` Johannes Weiner [this message]
2009-08-08 11:20     ` Jeff Layton
2009-08-07 18:57 ` [PATCH 3/4] vfs: change sb->s_maxbytes to a loff_t Jeff Layton
2009-08-07 20:14   ` Andreas Dilger
2009-08-07 22:51   ` Johannes Weiner
2009-08-08 11:15     ` Jeff Layton
2009-08-07 18:57 ` [PATCH 4/4] vfs: remove redundant checks in do_sendfile Jeff Layton
2009-08-07 20:58   ` Mandeep Singh Baines
2009-08-07 21:05     ` Jeff Layton

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=20090807221252.GA28019@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=jlayton@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=msb@google.com \
    --cc=rlove@google.com \
    --cc=viro@zeniv.linux.org.uk \
    /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