Skip to content

Commit 42cb56a

Browse files
jtlaytonAl Viro
authored andcommitted
vfs: change sb->s_maxbytes to a loff_t
sb->s_maxbytes is supposed to indicate the maximum size of a file that can exist on the filesystem. It's declared as an unsigned long long. Even if a filesystem has no inherent limit that prevents it from using every bit in that unsigned long long, it's still problematic to set it to anything larger than MAX_LFS_FILESIZE. There are places in the kernel that cast s_maxbytes to a signed value. If it's set too large then this cast makes it a negative number and generally breaks the comparison. Change s_maxbytes to be loff_t instead. That should help eliminate the temptation to set it too large by making it a signed value. Also, add a warning for couple of releases to help catch filesystems that set s_maxbytes too large. Eventually we can either convert this to a BUG() or just remove it and in the hope that no one will get it wrong now that it's a signed value. Signed-off-by: Jeff Layton <jlayton@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Robert Love <rlove@google.com> Cc: Mandeep Singh Baines <msb@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 5aa98b7 commit 42cb56a

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎fs/super.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,16 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void
892892
if (error)
893893
goto out_sb;
894894

895+
/*
896+
* filesystems should never set s_maxbytes larger than MAX_LFS_FILESIZE
897+
* but s_maxbytes was an unsigned long long for many releases. Throw
898+
* this warning for a little while to try and catch filesystems that
899+
* violate this rule. This warning should be either removed or
900+
* converted to a BUG() in 2.6.34.
901+
*/
902+
WARN((mnt->mnt_sb->s_maxbytes < 0), "%s set sb->s_maxbytes to "
903+
"negative value (%lld)\n", type->name, mnt->mnt_sb->s_maxbytes);
904+
895905
mnt->mnt_mountpoint = mnt->mnt_root;
896906
mnt->mnt_parent = mnt;
897907
up_write(&mnt->mnt_sb->s_umount);

‎include/linux/fs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ struct super_block {
13151315
unsigned long s_blocksize;
13161316
unsigned char s_blocksize_bits;
13171317
unsigned char s_dirt;
1318-
unsigned long long s_maxbytes; /* Max file size */
1318+
loff_t s_maxbytes; /* Max file size */
13191319
struct file_system_type *s_type;
13201320
const struct super_operations *s_op;
13211321
const struct dquot_operations *dq_op;

0 commit comments

Comments
 (0)