From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeff Layton Subject: [PATCH 2/4] vfs: explicitly cast s_maxbytes in fiemap_check_ranges Date: Fri, 7 Aug 2009 14:57:39 -0400 Message-ID: <1249671461-9071-3-git-send-email-jlayton@redhat.com> References: <1249671461-9071-1-git-send-email-jlayton@redhat.com> Cc: akpm@linux-foundation.org, hch@infradead.org, rlove@google.com, msb@google.com, viro@zeniv.linux.org.uk, hannes@cmpxchg.org To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Return-path: Received: from mx2.redhat.com ([66.187.237.31]:56744 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755060AbZHGS6C (ORCPT ); Fri, 7 Aug 2009 14:58:02 -0400 In-Reply-To: <1249671461-9071-1-git-send-email-jlayton@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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. Signed-off-by: Jeff Layton --- 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