Skip to content

Commit fd2186d

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: "Fix two regressions in ext4 and a number of issues reported by syzbot" * tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: ext4: enable the lazy init thread when remounting read/write ext4: fix fsync for non-directories ext4: add lockdep annotations for i_data_sem for ea_inode's ext4: disallow ea_inodes with extended attributes ext4: set lockdep subclass for the ea_inode in ext4_xattr_inode_cache_find() ext4: add EA_INODE checking to ext4_iget()
2 parents 48b1320 + eb1f822 commit fd2186d

File tree

5 files changed

+64
-47
lines changed

5 files changed

+64
-47
lines changed

fs/ext4/ext4.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,11 +918,13 @@ do { \
918918
* where the second inode has larger inode number
919919
* than the first
920920
* I_DATA_SEM_QUOTA - Used for quota inodes only
921+
* I_DATA_SEM_EA - Used for ea_inodes only
921922
*/
922923
enum {
923924
I_DATA_SEM_NORMAL = 0,
924925
I_DATA_SEM_OTHER,
925926
I_DATA_SEM_QUOTA,
927+
I_DATA_SEM_EA
926928
};
927929

928930

@@ -2901,7 +2903,8 @@ typedef enum {
29012903
EXT4_IGET_NORMAL = 0,
29022904
EXT4_IGET_SPECIAL = 0x0001, /* OK to iget a system inode */
29032905
EXT4_IGET_HANDLE = 0x0002, /* Inode # is from a handle */
2904-
EXT4_IGET_BAD = 0x0004 /* Allow to iget a bad inode */
2906+
EXT4_IGET_BAD = 0x0004, /* Allow to iget a bad inode */
2907+
EXT4_IGET_EA_INODE = 0x0008 /* Inode should contain an EA value */
29052908
} ext4_iget_flags;
29062909

29072910
extern struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,

fs/ext4/fsync.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ static int ext4_fsync_journal(struct inode *inode, bool datasync,
108108
journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
109109
tid_t commit_tid = datasync ? ei->i_datasync_tid : ei->i_sync_tid;
110110

111+
/*
112+
* Fastcommit does not really support fsync on directories or other
113+
* special files. Force a full commit.
114+
*/
115+
if (!S_ISREG(inode->i_mode))
116+
return ext4_force_commit(inode->i_sb);
117+
111118
if (journal->j_flags & JBD2_BARRIER &&
112119
!jbd2_trans_will_send_data_barrier(journal, commit_tid))
113120
*needs_barrier = true;

fs/ext4/inode.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4641,6 +4641,24 @@ static inline void ext4_inode_set_iversion_queried(struct inode *inode, u64 val)
46414641
inode_set_iversion_queried(inode, val);
46424642
}
46434643

4644+
static const char *check_igot_inode(struct inode *inode, ext4_iget_flags flags)
4645+
4646+
{
4647+
if (flags & EXT4_IGET_EA_INODE) {
4648+
if (!(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL))
4649+
return "missing EA_INODE flag";
4650+
if (ext4_test_inode_state(inode, EXT4_STATE_XATTR) ||
4651+
EXT4_I(inode)->i_file_acl)
4652+
return "ea_inode with extended attributes";
4653+
} else {
4654+
if ((EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL))
4655+
return "unexpected EA_INODE flag";
4656+
}
4657+
if (is_bad_inode(inode) && !(flags & EXT4_IGET_BAD))
4658+
return "unexpected bad inode w/o EXT4_IGET_BAD";
4659+
return NULL;
4660+
}
4661+
46444662
struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
46454663
ext4_iget_flags flags, const char *function,
46464664
unsigned int line)
@@ -4650,6 +4668,7 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
46504668
struct ext4_inode_info *ei;
46514669
struct ext4_super_block *es = EXT4_SB(sb)->s_es;
46524670
struct inode *inode;
4671+
const char *err_str;
46534672
journal_t *journal = EXT4_SB(sb)->s_journal;
46544673
long ret;
46554674
loff_t size;
@@ -4677,8 +4696,14 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
46774696
inode = iget_locked(sb, ino);
46784697
if (!inode)
46794698
return ERR_PTR(-ENOMEM);
4680-
if (!(inode->i_state & I_NEW))
4699+
if (!(inode->i_state & I_NEW)) {
4700+
if ((err_str = check_igot_inode(inode, flags)) != NULL) {
4701+
ext4_error_inode(inode, function, line, 0, err_str);
4702+
iput(inode);
4703+
return ERR_PTR(-EFSCORRUPTED);
4704+
}
46814705
return inode;
4706+
}
46824707

46834708
ei = EXT4_I(inode);
46844709
iloc.bh = NULL;
@@ -4944,10 +4969,9 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
49444969
if (IS_CASEFOLDED(inode) && !ext4_has_feature_casefold(inode->i_sb))
49454970
ext4_error_inode(inode, function, line, 0,
49464971
"casefold flag without casefold feature");
4947-
if (is_bad_inode(inode) && !(flags & EXT4_IGET_BAD)) {
4948-
ext4_error_inode(inode, function, line, 0,
4949-
"bad inode without EXT4_IGET_BAD flag");
4950-
ret = -EUCLEAN;
4972+
if ((err_str = check_igot_inode(inode, flags)) != NULL) {
4973+
ext4_error_inode(inode, function, line, 0, err_str);
4974+
ret = -EFSCORRUPTED;
49514975
goto bad_inode;
49524976
}
49534977

fs/ext4/super.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6588,18 +6588,6 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb)
65886588
}
65896589
}
65906590

6591-
/*
6592-
* Reinitialize lazy itable initialization thread based on
6593-
* current settings
6594-
*/
6595-
if (sb_rdonly(sb) || !test_opt(sb, INIT_INODE_TABLE))
6596-
ext4_unregister_li_request(sb);
6597-
else {
6598-
ext4_group_t first_not_zeroed;
6599-
first_not_zeroed = ext4_has_uninit_itable(sb);
6600-
ext4_register_li_request(sb, first_not_zeroed);
6601-
}
6602-
66036591
/*
66046592
* Handle creation of system zone data early because it can fail.
66056593
* Releasing of existing data is done when we are sure remount will
@@ -6637,6 +6625,18 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb)
66376625
if (enable_rw)
66386626
sb->s_flags &= ~SB_RDONLY;
66396627

6628+
/*
6629+
* Reinitialize lazy itable initialization thread based on
6630+
* current settings
6631+
*/
6632+
if (sb_rdonly(sb) || !test_opt(sb, INIT_INODE_TABLE))
6633+
ext4_unregister_li_request(sb);
6634+
else {
6635+
ext4_group_t first_not_zeroed;
6636+
first_not_zeroed = ext4_has_uninit_itable(sb);
6637+
ext4_register_li_request(sb, first_not_zeroed);
6638+
}
6639+
66406640
if (!ext4_has_feature_mmp(sb) || sb_rdonly(sb))
66416641
ext4_stop_mmpd(sbi);
66426642

fs/ext4/xattr.c

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ ext4_expand_inode_array(struct ext4_xattr_inode_array **ea_inode_array,
121121
#ifdef CONFIG_LOCKDEP
122122
void ext4_xattr_inode_set_class(struct inode *ea_inode)
123123
{
124+
struct ext4_inode_info *ei = EXT4_I(ea_inode);
125+
124126
lockdep_set_subclass(&ea_inode->i_rwsem, 1);
127+
(void) ei; /* shut up clang warning if !CONFIG_LOCKDEP */
128+
lockdep_set_subclass(&ei->i_data_sem, I_DATA_SEM_EA);
125129
}
126130
#endif
127131

@@ -433,31 +437,14 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,
433437
return -EFSCORRUPTED;
434438
}
435439

436-
inode = ext4_iget(parent->i_sb, ea_ino, EXT4_IGET_NORMAL);
440+
inode = ext4_iget(parent->i_sb, ea_ino, EXT4_IGET_EA_INODE);
437441
if (IS_ERR(inode)) {
438442
err = PTR_ERR(inode);
439443
ext4_error(parent->i_sb,
440444
"error while reading EA inode %lu err=%d", ea_ino,
441445
err);
442446
return err;
443447
}
444-
445-
if (is_bad_inode(inode)) {
446-
ext4_error(parent->i_sb,
447-
"error while reading EA inode %lu is_bad_inode",
448-
ea_ino);
449-
err = -EIO;
450-
goto error;
451-
}
452-
453-
if (!(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) {
454-
ext4_error(parent->i_sb,
455-
"EA inode %lu does not have EXT4_EA_INODE_FL flag",
456-
ea_ino);
457-
err = -EINVAL;
458-
goto error;
459-
}
460-
461448
ext4_xattr_inode_set_class(inode);
462449

463450
/*
@@ -478,9 +465,6 @@ static int ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,
478465

479466
*ea_inode = inode;
480467
return 0;
481-
error:
482-
iput(inode);
483-
return err;
484468
}
485469

486470
/* Remove entry from mbcache when EA inode is getting evicted */
@@ -1556,11 +1540,11 @@ ext4_xattr_inode_cache_find(struct inode *inode, const void *value,
15561540

15571541
while (ce) {
15581542
ea_inode = ext4_iget(inode->i_sb, ce->e_value,
1559-
EXT4_IGET_NORMAL);
1560-
if (!IS_ERR(ea_inode) &&
1561-
!is_bad_inode(ea_inode) &&
1562-
(EXT4_I(ea_inode)->i_flags & EXT4_EA_INODE_FL) &&
1563-
i_size_read(ea_inode) == value_len &&
1543+
EXT4_IGET_EA_INODE);
1544+
if (IS_ERR(ea_inode))
1545+
goto next_entry;
1546+
ext4_xattr_inode_set_class(ea_inode);
1547+
if (i_size_read(ea_inode) == value_len &&
15641548
!ext4_xattr_inode_read(ea_inode, ea_data, value_len) &&
15651549
!ext4_xattr_inode_verify_hashes(ea_inode, NULL, ea_data,
15661550
value_len) &&
@@ -1570,9 +1554,8 @@ ext4_xattr_inode_cache_find(struct inode *inode, const void *value,
15701554
kvfree(ea_data);
15711555
return ea_inode;
15721556
}
1573-
1574-
if (!IS_ERR(ea_inode))
1575-
iput(ea_inode);
1557+
iput(ea_inode);
1558+
next_entry:
15761559
ce = mb_cache_entry_find_next(ea_inode_cache, ce);
15771560
}
15781561
kvfree(ea_data);

0 commit comments

Comments
 (0)