Skip to content

Commit 95fc841

Browse files
ebiggersgregkh
authored andcommitted
fs/minix: set s_maxbytes correctly
[ Upstream commit 32ac86e ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a906b86 commit 95fc841

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

fs/minix/inode.c

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

158-
static bool minix_check_superblock(struct minix_sb_info *sbi)
158+
static bool minix_check_superblock(struct super_block *sb)
159159
{
160+
struct minix_sb_info *sbi = minix_sb(sb);
161+
160162
if (sbi->s_imap_blocks == 0 || sbi->s_zmap_blocks == 0)
161163
return false;
162164

@@ -166,7 +168,7 @@ static bool minix_check_superblock(struct minix_sb_info *sbi)
166168
* of indirect blocks which places the limit well above U32_MAX.
167169
*/
168170
if (sbi->s_version == MINIX_V1 &&
169-
sbi->s_max_size > (7 + 512 + 512*512) * BLOCK_SIZE)
171+
sb->s_maxbytes > (7 + 512 + 512*512) * BLOCK_SIZE)
170172
return false;
171173

172174
return true;
@@ -207,7 +209,7 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
207209
sbi->s_zmap_blocks = ms->s_zmap_blocks;
208210
sbi->s_firstdatazone = ms->s_firstdatazone;
209211
sbi->s_log_zone_size = ms->s_log_zone_size;
210-
sbi->s_max_size = ms->s_max_size;
212+
s->s_maxbytes = ms->s_max_size;
211213
s->s_magic = ms->s_magic;
212214
if (s->s_magic == MINIX_SUPER_MAGIC) {
213215
sbi->s_version = MINIX_V1;
@@ -238,7 +240,7 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
238240
sbi->s_zmap_blocks = m3s->s_zmap_blocks;
239241
sbi->s_firstdatazone = m3s->s_firstdatazone;
240242
sbi->s_log_zone_size = m3s->s_log_zone_size;
241-
sbi->s_max_size = m3s->s_max_size;
243+
s->s_maxbytes = m3s->s_max_size;
242244
sbi->s_ninodes = m3s->s_ninodes;
243245
sbi->s_nzones = m3s->s_zones;
244246
sbi->s_dirsize = 64;
@@ -250,7 +252,7 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
250252
} else
251253
goto out_no_fs;
252254

253-
if (!minix_check_superblock(sbi))
255+
if (!minix_check_superblock(s))
254256
goto out_illegal_sb;
255257

256258
/*

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)