Skip to content

Commit 32ac86e

Browse files
ebiggerstorvalds
authored andcommitted
fs/minix: set s_maxbytes correctly
The minix filesystem leaves super_block::s_maxbytes at MAX_NON_LFS rather than setting it to the actual filesystem-specific limit. This is broken because it means userspace doesn't see the standard behavior like getting EFBIG and SIGXFSZ when exceeding the maximum file size. Fix this by setting s_maxbytes correctly. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Qiujun Huang <anenbupt@gmail.com> Link: http://lkml.kernel.org/r/20200628060846.682158-5-ebiggers@kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 270ef41 commit 32ac86e

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

fs/minix/inode.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@ static int minix_remount (struct super_block * sb, int * flags, char * data)
150150
return 0;
151151
}
152152

153-
static bool minix_check_superblock(struct minix_sb_info *sbi)
153+
static bool minix_check_superblock(struct super_block *sb)
154154
{
155+
struct minix_sb_info *sbi = minix_sb(sb);
156+
155157
if (sbi->s_imap_blocks == 0 || sbi->s_zmap_blocks == 0)
156158
return false;
157159

@@ -161,7 +163,7 @@ static bool minix_check_superblock(struct minix_sb_info *sbi)
161163
* of indirect blocks which places the limit well above U32_MAX.
162164
*/
163165
if (sbi->s_version == MINIX_V1 &&
164-
sbi->s_max_size > (7 + 512 + 512*512) * BLOCK_SIZE)
166+
sb->s_maxbytes > (7 + 512 + 512*512) * BLOCK_SIZE)
165167
return false;
166168

167169
return true;
@@ -202,7 +204,7 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
202204
sbi->s_zmap_blocks = ms->s_zmap_blocks;
203205
sbi->s_firstdatazone = ms->s_firstdatazone;
204206
sbi->s_log_zone_size = ms->s_log_zone_size;
205-
sbi->s_max_size = ms->s_max_size;
207+
s->s_maxbytes = ms->s_max_size;
206208
s->s_magic = ms->s_magic;
207209
if (s->s_magic == MINIX_SUPER_MAGIC) {
208210
sbi->s_version = MINIX_V1;
@@ -233,7 +235,7 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
233235
sbi->s_zmap_blocks = m3s->s_zmap_blocks;
234236
sbi->s_firstdatazone = m3s->s_firstdatazone;
235237
sbi->s_log_zone_size = m3s->s_log_zone_size;
236-
sbi->s_max_size = m3s->s_max_size;
238+
s->s_maxbytes = m3s->s_max_size;
237239
sbi->s_ninodes = m3s->s_ninodes;
238240
sbi->s_nzones = m3s->s_zones;
239241
sbi->s_dirsize = 64;
@@ -245,7 +247,7 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
245247
} else
246248
goto out_no_fs;
247249

248-
if (!minix_check_superblock(sbi))
250+
if (!minix_check_superblock(s))
249251
goto out_illegal_sb;
250252

251253
/*

fs/minix/itree_v1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static int block_to_path(struct inode * inode, long block, int offsets[DEPTH])
2929
if (block < 0) {
3030
printk("MINIX-fs: block_to_path: block %ld < 0 on dev %pg\n",
3131
block, inode->i_sb->s_bdev);
32-
} else if (block >= (minix_sb(inode->i_sb)->s_max_size/BLOCK_SIZE)) {
32+
} else if (block >= inode->i_sb->s_maxbytes/BLOCK_SIZE) {
3333
if (printk_ratelimit())
3434
printk("MINIX-fs: block_to_path: "
3535
"block %ld too big on dev %pg\n",

fs/minix/itree_v2.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ static int block_to_path(struct inode * inode, long block, int offsets[DEPTH])
3232
if (block < 0) {
3333
printk("MINIX-fs: block_to_path: block %ld < 0 on dev %pg\n",
3434
block, sb->s_bdev);
35-
} else if ((u64)block * (u64)sb->s_blocksize >=
36-
minix_sb(sb)->s_max_size) {
35+
} else if ((u64)block * (u64)sb->s_blocksize >= sb->s_maxbytes) {
3736
if (printk_ratelimit())
3837
printk("MINIX-fs: block_to_path: "
3938
"block %ld too big on dev %pg\n",

fs/minix/minix.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ struct minix_sb_info {
3232
unsigned long s_zmap_blocks;
3333
unsigned long s_firstdatazone;
3434
unsigned long s_log_zone_size;
35-
unsigned long s_max_size;
3635
int s_dirsize;
3736
int s_namelen;
3837
struct buffer_head ** s_imap;

0 commit comments

Comments
 (0)