Skip to content

Commit 06936aa

Browse files
committed
Merge tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 fixes from Ted Ts'o: "Some ext4 regression and bug fixes" * tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: ext4: clean up error handling in __ext4_fill_super() ext4: reflect error codes from ext4_multi_mount_protect() to its callers ext4: fix lost error code reporting in __ext4_fill_super() ext4: fix unused iterator variable warnings ext4: fix use-after-free read in ext4_find_extent for bigalloc + inline ext4: fix i_disksize exceeding i_size problem in paritally written case
2 parents 26c009d + d4fab7b commit 06936aa

4 files changed

Lines changed: 56 additions & 36 deletions

File tree

fs/ext4/extents.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5795,7 +5795,8 @@ int ext4_clu_mapped(struct inode *inode, ext4_lblk_t lclu)
57955795
* mapped - no physical clusters have been allocated, and the
57965796
* file has no extents
57975797
*/
5798-
if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA))
5798+
if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA) ||
5799+
ext4_has_inline_data(inode))
57995800
return 0;
58005801

58015802
/* search for the extent closest to the first block in the cluster */

fs/ext4/inode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,6 +2982,9 @@ static int ext4_da_write_end(struct file *file,
29822982
ext4_has_inline_data(inode))
29832983
return ext4_write_inline_data_end(inode, pos, len, copied, page);
29842984

2985+
if (unlikely(copied < len) && !PageUptodate(page))
2986+
copied = 0;
2987+
29852988
start = pos & (PAGE_SIZE - 1);
29862989
end = start + copied - 1;
29872990

fs/ext4/mmp.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ int ext4_multi_mount_protect(struct super_block *sb,
282282
if (mmp_block < le32_to_cpu(es->s_first_data_block) ||
283283
mmp_block >= ext4_blocks_count(es)) {
284284
ext4_warning(sb, "Invalid MMP block in superblock");
285+
retval = -EINVAL;
285286
goto failed;
286287
}
287288

@@ -307,6 +308,7 @@ int ext4_multi_mount_protect(struct super_block *sb,
307308

308309
if (seq == EXT4_MMP_SEQ_FSCK) {
309310
dump_mmp_msg(sb, mmp, "fsck is running on the filesystem");
311+
retval = -EBUSY;
310312
goto failed;
311313
}
312314

@@ -320,6 +322,7 @@ int ext4_multi_mount_protect(struct super_block *sb,
320322

321323
if (schedule_timeout_interruptible(HZ * wait_time) != 0) {
322324
ext4_warning(sb, "MMP startup interrupted, failing mount\n");
325+
retval = -ETIMEDOUT;
323326
goto failed;
324327
}
325328

@@ -330,6 +333,7 @@ int ext4_multi_mount_protect(struct super_block *sb,
330333
if (seq != le32_to_cpu(mmp->mmp_seq)) {
331334
dump_mmp_msg(sb, mmp,
332335
"Device is already active on another node.");
336+
retval = -EBUSY;
333337
goto failed;
334338
}
335339

@@ -349,6 +353,7 @@ int ext4_multi_mount_protect(struct super_block *sb,
349353
*/
350354
if (schedule_timeout_interruptible(HZ * wait_time) != 0) {
351355
ext4_warning(sb, "MMP startup interrupted, failing mount");
356+
retval = -ETIMEDOUT;
352357
goto failed;
353358
}
354359

@@ -359,6 +364,7 @@ int ext4_multi_mount_protect(struct super_block *sb,
359364
if (seq != le32_to_cpu(mmp->mmp_seq)) {
360365
dump_mmp_msg(sb, mmp,
361366
"Device is already active on another node.");
367+
retval = -EBUSY;
362368
goto failed;
363369
}
364370

@@ -378,12 +384,13 @@ int ext4_multi_mount_protect(struct super_block *sb,
378384
EXT4_SB(sb)->s_mmp_tsk = NULL;
379385
ext4_warning(sb, "Unable to create kmmpd thread for %s.",
380386
sb->s_id);
387+
retval = -ENOMEM;
381388
goto failed;
382389
}
383390

384391
return 0;
385392

386393
failed:
387394
brelse(bh);
388-
return 1;
395+
return retval;
389396
}

fs/ext4/super.c

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ static void ext4_put_super(struct super_block *sb)
12591259
struct ext4_sb_info *sbi = EXT4_SB(sb);
12601260
struct ext4_super_block *es = sbi->s_es;
12611261
int aborted = 0;
1262-
int i, err;
1262+
int err;
12631263

12641264
/*
12651265
* Unregister sysfs before destroying jbd2 journal.
@@ -1311,7 +1311,7 @@ static void ext4_put_super(struct super_block *sb)
13111311
ext4_flex_groups_free(sbi);
13121312
ext4_percpu_param_destroy(sbi);
13131313
#ifdef CONFIG_QUOTA
1314-
for (i = 0; i < EXT4_MAXQUOTAS; i++)
1314+
for (int i = 0; i < EXT4_MAXQUOTAS; i++)
13151315
kfree(get_qf_name(sb, sbi, i));
13161316
#endif
13171317

@@ -5196,10 +5196,8 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
51965196
struct ext4_sb_info *sbi = EXT4_SB(sb);
51975197
ext4_fsblk_t logical_sb_block;
51985198
struct inode *root;
5199-
int ret = -ENOMEM;
5200-
unsigned int i;
52015199
int needs_recovery;
5202-
int err = 0;
5200+
int err;
52035201
ext4_group_t first_not_zeroed;
52045202
struct ext4_fs_context *ctx = fc->fs_private;
52055203
int silent = fc->sb_flags & SB_SILENT;
@@ -5212,8 +5210,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
52125210
sbi->s_sectors_written_start =
52135211
part_stat_read(sb->s_bdev, sectors[STAT_WRITE]);
52145212

5215-
/* -EINVAL is default */
5216-
ret = -EINVAL;
52175213
err = ext4_load_super(sb, &logical_sb_block, silent);
52185214
if (err)
52195215
goto out_fail;
@@ -5239,7 +5235,8 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
52395235
*/
52405236
sbi->s_li_wait_mult = EXT4_DEF_LI_WAIT_MULT;
52415237

5242-
if (ext4_inode_info_init(sb, es))
5238+
err = ext4_inode_info_init(sb, es);
5239+
if (err)
52435240
goto failed_mount;
52445241

52455242
err = parse_apply_sb_mount_options(sb, ctx);
@@ -5255,10 +5252,12 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
52555252

52565253
ext4_apply_options(fc, sb);
52575254

5258-
if (ext4_encoding_init(sb, es))
5255+
err = ext4_encoding_init(sb, es);
5256+
if (err)
52595257
goto failed_mount;
52605258

5261-
if (ext4_check_journal_data_mode(sb))
5259+
err = ext4_check_journal_data_mode(sb);
5260+
if (err)
52625261
goto failed_mount;
52635262

52645263
sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
@@ -5267,18 +5266,22 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
52675266
/* i_version is always enabled now */
52685267
sb->s_flags |= SB_I_VERSION;
52695268

5270-
if (ext4_check_feature_compatibility(sb, es, silent))
5269+
err = ext4_check_feature_compatibility(sb, es, silent);
5270+
if (err)
52715271
goto failed_mount;
52725272

5273-
if (ext4_block_group_meta_init(sb, silent))
5273+
err = ext4_block_group_meta_init(sb, silent);
5274+
if (err)
52745275
goto failed_mount;
52755276

52765277
ext4_hash_info_init(sb);
52775278

5278-
if (ext4_handle_clustersize(sb))
5279+
err = ext4_handle_clustersize(sb);
5280+
if (err)
52795281
goto failed_mount;
52805282

5281-
if (ext4_check_geometry(sb, es))
5283+
err = ext4_check_geometry(sb, es);
5284+
if (err)
52825285
goto failed_mount;
52835286

52845287
timer_setup(&sbi->s_err_report, print_daily_error_info, 0);
@@ -5289,8 +5292,8 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
52895292
if (err)
52905293
goto failed_mount3;
52915294

5292-
/* Register extent status tree shrinker */
5293-
if (ext4_es_register_shrinker(sbi))
5295+
err = ext4_es_register_shrinker(sbi);
5296+
if (err)
52945297
goto failed_mount3;
52955298

52965299
sbi->s_stripe = ext4_get_stripe_size(sbi);
@@ -5329,10 +5332,13 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
53295332
ext4_has_feature_orphan_present(sb) ||
53305333
ext4_has_feature_journal_needs_recovery(sb));
53315334

5332-
if (ext4_has_feature_mmp(sb) && !sb_rdonly(sb))
5333-
if (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))
5335+
if (ext4_has_feature_mmp(sb) && !sb_rdonly(sb)) {
5336+
err = ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block));
5337+
if (err)
53345338
goto failed_mount3a;
5339+
}
53355340

5341+
err = -EINVAL;
53365342
/*
53375343
* The first inode we look at is the journal inode. Don't try
53385344
* root first: it may be modified in the journal!
@@ -5384,6 +5390,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
53845390
if (!sbi->s_ea_block_cache) {
53855391
ext4_msg(sb, KERN_ERR,
53865392
"Failed to create ea_block_cache");
5393+
err = -EINVAL;
53875394
goto failed_mount_wq;
53885395
}
53895396

@@ -5392,6 +5399,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
53925399
if (!sbi->s_ea_inode_cache) {
53935400
ext4_msg(sb, KERN_ERR,
53945401
"Failed to create ea_inode_cache");
5402+
err = -EINVAL;
53955403
goto failed_mount_wq;
53965404
}
53975405
}
@@ -5426,7 +5434,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
54265434
alloc_workqueue("ext4-rsv-conversion", WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
54275435
if (!EXT4_SB(sb)->rsv_conversion_wq) {
54285436
printk(KERN_ERR "EXT4-fs: failed to create workqueue\n");
5429-
ret = -ENOMEM;
5437+
err = -ENOMEM;
54305438
goto failed_mount4;
54315439
}
54325440

@@ -5438,28 +5446,28 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
54385446
root = ext4_iget(sb, EXT4_ROOT_INO, EXT4_IGET_SPECIAL);
54395447
if (IS_ERR(root)) {
54405448
ext4_msg(sb, KERN_ERR, "get root inode failed");
5441-
ret = PTR_ERR(root);
5449+
err = PTR_ERR(root);
54425450
root = NULL;
54435451
goto failed_mount4;
54445452
}
54455453
if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
54465454
ext4_msg(sb, KERN_ERR, "corrupt root inode, run e2fsck");
54475455
iput(root);
5456+
err = -EFSCORRUPTED;
54485457
goto failed_mount4;
54495458
}
54505459

54515460
sb->s_root = d_make_root(root);
54525461
if (!sb->s_root) {
54535462
ext4_msg(sb, KERN_ERR, "get root dentry failed");
5454-
ret = -ENOMEM;
5463+
err = -ENOMEM;
54555464
goto failed_mount4;
54565465
}
54575466

5458-
ret = ext4_setup_super(sb, es, sb_rdonly(sb));
5459-
if (ret == -EROFS) {
5467+
err = ext4_setup_super(sb, es, sb_rdonly(sb));
5468+
if (err == -EROFS) {
54605469
sb->s_flags |= SB_RDONLY;
5461-
ret = 0;
5462-
} else if (ret)
5470+
} else if (err)
54635471
goto failed_mount4a;
54645472

54655473
ext4_set_resv_clusters(sb);
@@ -5503,15 +5511,16 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
55035511
sbi->s_journal->j_commit_callback =
55045512
ext4_journal_commit_callback;
55055513

5506-
if (ext4_percpu_param_init(sbi))
5514+
err = ext4_percpu_param_init(sbi);
5515+
if (err)
55075516
goto failed_mount6;
55085517

55095518
if (ext4_has_feature_flex_bg(sb))
55105519
if (!ext4_fill_flex_info(sb)) {
55115520
ext4_msg(sb, KERN_ERR,
55125521
"unable to initialize "
55135522
"flex_bg meta info!");
5514-
ret = -ENOMEM;
5523+
err = -ENOMEM;
55155524
goto failed_mount6;
55165525
}
55175526

@@ -5628,7 +5637,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
56285637
#endif
56295638

56305639
#ifdef CONFIG_QUOTA
5631-
for (i = 0; i < EXT4_MAXQUOTAS; i++)
5640+
for (unsigned int i = 0; i < EXT4_MAXQUOTAS; i++)
56325641
kfree(get_qf_name(sb, sbi, i));
56335642
#endif
56345643
fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
@@ -5637,7 +5646,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
56375646
ext4_blkdev_remove(sbi);
56385647
out_fail:
56395648
sb->s_fs_info = NULL;
5640-
return err ? err : ret;
5649+
return err;
56415650
}
56425651

56435652
static int ext4_fill_super(struct super_block *sb, struct fs_context *fc)
@@ -6565,12 +6574,12 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb)
65656574
goto restore_opts;
65666575

65676576
sb->s_flags &= ~SB_RDONLY;
6568-
if (ext4_has_feature_mmp(sb))
6569-
if (ext4_multi_mount_protect(sb,
6570-
le64_to_cpu(es->s_mmp_block))) {
6571-
err = -EROFS;
6577+
if (ext4_has_feature_mmp(sb)) {
6578+
err = ext4_multi_mount_protect(sb,
6579+
le64_to_cpu(es->s_mmp_block));
6580+
if (err)
65726581
goto restore_opts;
6573-
}
6582+
}
65746583
#ifdef CONFIG_QUOTA
65756584
enable_quota = 1;
65766585
#endif

0 commit comments

Comments
 (0)