From: Johannes Weiner <hannes@cmpxchg.org>
To: Jeff Layton <jlayton@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
smfrench@gmail.com, hch@infradead.org
Subject: Re: [PATCH] fix offset checks in do_sendfile to use unsigned values
Date: Wed, 22 Jul 2009 14:59:45 +0200 [thread overview]
Message-ID: <20090722125945.GA2834@cmpxchg.org> (raw)
In-Reply-To: <1248262099-12514-2-git-send-email-jlayton@redhat.com>
On Wed, Jul 22, 2009 at 07:28:19AM -0400, Jeff Layton wrote:
> If do_sendfile is called with a "max" value of 0, it grabs the lesser
> s_maxbytes value of the two superblocks to use instead. There's a
> problem here however. s_maxbytes is an unsigned long long and it gets
> cast to a signed value. If both s_maxbytes values are large enough, max
> will end up being negative and the comparisons in this code won't work
> correctly.
>
> Change do_sendfile to use unsigned values internally for the offset
> checks.
>
> Signed-off-by: Jeff Layton <jlayton@redhat.com>
> ---
> fs/read_write.c | 6 +++---
> 1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/read_write.c b/fs/read_write.c
> index 6c8c55d..36899ff 100644
> --- a/fs/read_write.c
> +++ b/fs/read_write.c
> @@ -788,11 +788,11 @@ SYSCALL_DEFINE5(pwritev, unsigned long, fd, const struct iovec __user *, vec,
> }
>
> static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
> - size_t count, loff_t max)
> + size_t count, unsigned long long max)
> {
> struct file * in_file, * out_file;
> struct inode * in_inode, * out_inode;
> - loff_t pos;
> + unsigned long long pos;
> ssize_t retval;
> int fput_needed_in, fput_needed_out, fl;
>
> @@ -838,7 +838,7 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
> if (!max)
> max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
>
> - pos = *ppos;
> + pos = (unsigned long long) *ppos;
> retval = -EINVAL;
> if (unlikely(pos < 0))
> goto fput_out;
May it be possible that cifs is the only fs that sets sb->sb_maxbytes
to exceed loff_t? It seems the others clamp it to MAX_LFS_FILESIZE
while CIFS exceeds this by one. And then max is -1.
So, isn't the correct fix something similar to this?
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index e16d759..df56093 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -2452,10 +2452,10 @@ try_mount_again:
tcon->local_lease = volume_info->local_lease;
}
if (pSesInfo) {
- if (pSesInfo->capabilities & CAP_LARGE_FILES) {
- sb->s_maxbytes = (u64) 1 << 63;
- } else
- sb->s_maxbytes = (u64) 1 << 31; /* 2 GB */
+ if (pSesInfo->capabilities & CAP_LARGE_FILES)
+ sb->s_maxbytes = MAX_LFS_FILESIZE;
+ else
+ sb->s_maxbytes = MAX_NON_LFS;
}
/* BB FIXME fix time_gran to be larger for LANMAN sessions */
next prev parent reply other threads:[~2009-07-22 12:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-22 11:28 [PATCH] libfs: make get_sb_pseudo set s_maxbytes to value that can be cast to signed Jeff Layton
2009-07-22 11:28 ` [PATCH] fix offset checks in do_sendfile to use unsigned values Jeff Layton
2009-07-22 12:59 ` Johannes Weiner [this message]
2009-07-22 13:37 ` Jeff Layton
2009-07-22 13:51 ` Johannes Weiner
2009-07-22 14:13 ` Jeff Layton
2009-07-22 15:28 ` Steve French
2009-07-22 15:37 ` Johannes Weiner
2009-07-22 15:16 ` [PATCH] libfs: make get_sb_pseudo set s_maxbytes to value that can be cast to signed Steve French
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=20090722125945.GA2834@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=hch@infradead.org \
--cc=jlayton@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=smfrench@gmail.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).