Skip to content

Commit 70a2dc6

Browse files
committed
Merge tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 bugfixes from Ted Ts'o: "Bug fixes for ext4; most of which relate to vulnerabilities where a maliciously crafted file system image can result in a kernel OOPS or hang. At least one fix addresses an inline data bug could be triggered by userspace without the need of a crafted file system (although it does require that the inline data feature be enabled)" * tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: ext4: check superblock mapped prior to committing ext4: add more mount time checks of the superblock ext4: add more inode number paranoia checks ext4: avoid running out of journal credits when appending to an inline file jbd2: don't mark block as modified if the handle is out of credits ext4: never move the system.data xattr out of the inode body ext4: clear i_data in ext4_inode_info when removing inline data ext4: include the illegal physical block in the bad map ext4_error msg ext4: verify the depth of extent tree in ext4_find_extent() ext4: only look at the bg_flags field if it is valid ext4: make sure bitmaps and the inode table don't overlap with bg descriptors ext4: always check block group bounds in ext4_init_block_bitmap() ext4: always verify the magic number in xattr blocks ext4: add corruption check in ext4_xattr_set_entry() ext4: add warn_on_error mount option
2 parents 8979319 + a17712c commit 70a2dc6

11 files changed

Lines changed: 155 additions & 96 deletions

File tree

‎fs/ext4/balloc.c‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ static int ext4_init_block_bitmap(struct super_block *sb,
184184
unsigned int bit, bit_max;
185185
struct ext4_sb_info *sbi = EXT4_SB(sb);
186186
ext4_fsblk_t start, tmp;
187-
int flex_bg = 0;
188187

189188
J_ASSERT_BH(bh, buffer_locked(bh));
190189

@@ -207,22 +206,19 @@ static int ext4_init_block_bitmap(struct super_block *sb,
207206

208207
start = ext4_group_first_block_no(sb, block_group);
209208

210-
if (ext4_has_feature_flex_bg(sb))
211-
flex_bg = 1;
212-
213209
/* Set bits for block and inode bitmaps, and inode table */
214210
tmp = ext4_block_bitmap(sb, gdp);
215-
if (!flex_bg || ext4_block_in_group(sb, tmp, block_group))
211+
if (ext4_block_in_group(sb, tmp, block_group))
216212
ext4_set_bit(EXT4_B2C(sbi, tmp - start), bh->b_data);
217213

218214
tmp = ext4_inode_bitmap(sb, gdp);
219-
if (!flex_bg || ext4_block_in_group(sb, tmp, block_group))
215+
if (ext4_block_in_group(sb, tmp, block_group))
220216
ext4_set_bit(EXT4_B2C(sbi, tmp - start), bh->b_data);
221217

222218
tmp = ext4_inode_table(sb, gdp);
223219
for (; tmp < ext4_inode_table(sb, gdp) +
224220
sbi->s_itb_per_group; tmp++) {
225-
if (!flex_bg || ext4_block_in_group(sb, tmp, block_group))
221+
if (ext4_block_in_group(sb, tmp, block_group))
226222
ext4_set_bit(EXT4_B2C(sbi, tmp - start), bh->b_data);
227223
}
228224

@@ -442,7 +438,16 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
442438
goto verify;
443439
}
444440
ext4_lock_group(sb, block_group);
445-
if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
441+
if (ext4_has_group_desc_csum(sb) &&
442+
(desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))) {
443+
if (block_group == 0) {
444+
ext4_unlock_group(sb, block_group);
445+
unlock_buffer(bh);
446+
ext4_error(sb, "Block bitmap for bg 0 marked "
447+
"uninitialized");
448+
err = -EFSCORRUPTED;
449+
goto out;
450+
}
446451
err = ext4_init_block_bitmap(sb, bh, block_group, desc);
447452
set_bitmap_uptodate(bh);
448453
set_buffer_uptodate(bh);

‎fs/ext4/ext4.h‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ struct ext4_inode_info {
11141114
#define EXT4_MOUNT_DIOREAD_NOLOCK 0x400000 /* Enable support for dio read nolocking */
11151115
#define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */
11161116
#define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */
1117+
#define EXT4_MOUNT_WARN_ON_ERROR 0x2000000 /* Trigger WARN_ON on error */
11171118
#define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */
11181119
#define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */
11191120
#define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */
@@ -1507,11 +1508,6 @@ static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
15071508
static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
15081509
{
15091510
return ino == EXT4_ROOT_INO ||
1510-
ino == EXT4_USR_QUOTA_INO ||
1511-
ino == EXT4_GRP_QUOTA_INO ||
1512-
ino == EXT4_BOOT_LOADER_INO ||
1513-
ino == EXT4_JOURNAL_INO ||
1514-
ino == EXT4_RESIZE_INO ||
15151511
(ino >= EXT4_FIRST_INO(sb) &&
15161512
ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count));
15171513
}
@@ -3018,9 +3014,6 @@ extern int ext4_inline_data_fiemap(struct inode *inode,
30183014
struct iomap;
30193015
extern int ext4_inline_data_iomap(struct inode *inode, struct iomap *iomap);
30203016

3021-
extern int ext4_try_to_evict_inline_data(handle_t *handle,
3022-
struct inode *inode,
3023-
int needed);
30243017
extern int ext4_inline_data_truncate(struct inode *inode, int *has_inline);
30253018

30263019
extern int ext4_convert_inline_data(struct inode *inode);

‎fs/ext4/ext4_extents.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct ext4_extent_header {
9191
};
9292

9393
#define EXT4_EXT_MAGIC cpu_to_le16(0xf30a)
94+
#define EXT4_MAX_EXTENT_DEPTH 5
9495

9596
#define EXT4_EXTENT_TAIL_OFFSET(hdr) \
9697
(sizeof(struct ext4_extent_header) + \

‎fs/ext4/extents.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,12 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block,
869869

870870
eh = ext_inode_hdr(inode);
871871
depth = ext_depth(inode);
872+
if (depth < 0 || depth > EXT4_MAX_EXTENT_DEPTH) {
873+
EXT4_ERROR_INODE(inode, "inode has invalid extent depth: %d",
874+
depth);
875+
ret = -EFSCORRUPTED;
876+
goto err;
877+
}
872878

873879
if (path) {
874880
ext4_ext_drop_refs(path);

‎fs/ext4/ialloc.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,16 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
150150
}
151151

152152
ext4_lock_group(sb, block_group);
153-
if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {
153+
if (ext4_has_group_desc_csum(sb) &&
154+
(desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT))) {
155+
if (block_group == 0) {
156+
ext4_unlock_group(sb, block_group);
157+
unlock_buffer(bh);
158+
ext4_error(sb, "Inode bitmap for bg 0 marked "
159+
"uninitialized");
160+
err = -EFSCORRUPTED;
161+
goto out;
162+
}
154163
memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8);
155164
ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb),
156165
sb->s_blocksize * 8, bh->b_data);
@@ -994,7 +1003,8 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
9941003

9951004
/* recheck and clear flag under lock if we still need to */
9961005
ext4_lock_group(sb, group);
997-
if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
1006+
if (ext4_has_group_desc_csum(sb) &&
1007+
(gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))) {
9981008
gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);
9991009
ext4_free_group_clusters_set(sb, gdp,
10001010
ext4_free_clusters_after_init(sb, group, gdp));

‎fs/ext4/inline.c‎

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ static int ext4_destroy_inline_data_nolock(handle_t *handle,
437437

438438
memset((void *)ext4_raw_inode(&is.iloc)->i_block,
439439
0, EXT4_MIN_INLINE_DATA_SIZE);
440+
memset(ei->i_data, 0, EXT4_MIN_INLINE_DATA_SIZE);
440441

441442
if (ext4_has_feature_extents(inode->i_sb)) {
442443
if (S_ISDIR(inode->i_mode) ||
@@ -886,11 +887,11 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
886887
flags |= AOP_FLAG_NOFS;
887888

888889
if (ret == -ENOSPC) {
890+
ext4_journal_stop(handle);
889891
ret = ext4_da_convert_inline_data_to_extent(mapping,
890892
inode,
891893
flags,
892894
fsdata);
893-
ext4_journal_stop(handle);
894895
if (ret == -ENOSPC &&
895896
ext4_should_retry_alloc(inode->i_sb, &retries))
896897
goto retry_journal;
@@ -1890,42 +1891,6 @@ int ext4_inline_data_fiemap(struct inode *inode,
18901891
return (error < 0 ? error : 0);
18911892
}
18921893

1893-
/*
1894-
* Called during xattr set, and if we can sparse space 'needed',
1895-
* just create the extent tree evict the data to the outer block.
1896-
*
1897-
* We use jbd2 instead of page cache to move data to the 1st block
1898-
* so that the whole transaction can be committed as a whole and
1899-
* the data isn't lost because of the delayed page cache write.
1900-
*/
1901-
int ext4_try_to_evict_inline_data(handle_t *handle,
1902-
struct inode *inode,
1903-
int needed)
1904-
{
1905-
int error;
1906-
struct ext4_xattr_entry *entry;
1907-
struct ext4_inode *raw_inode;
1908-
struct ext4_iloc iloc;
1909-
1910-
error = ext4_get_inode_loc(inode, &iloc);
1911-
if (error)
1912-
return error;
1913-
1914-
raw_inode = ext4_raw_inode(&iloc);
1915-
entry = (struct ext4_xattr_entry *)((void *)raw_inode +
1916-
EXT4_I(inode)->i_inline_off);
1917-
if (EXT4_XATTR_LEN(entry->e_name_len) +
1918-
EXT4_XATTR_SIZE(le32_to_cpu(entry->e_value_size)) < needed) {
1919-
error = -ENOSPC;
1920-
goto out;
1921-
}
1922-
1923-
error = ext4_convert_inline_data_nolock(handle, inode, &iloc);
1924-
out:
1925-
brelse(iloc.bh);
1926-
return error;
1927-
}
1928-
19291894
int ext4_inline_data_truncate(struct inode *inode, int *has_inline)
19301895
{
19311896
handle_t *handle;

‎fs/ext4/inode.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ static int __check_block_validity(struct inode *inode, const char *func,
402402
if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), map->m_pblk,
403403
map->m_len)) {
404404
ext4_error_inode(inode, func, line, map->m_pblk,
405-
"lblock %lu mapped to illegal pblock "
405+
"lblock %lu mapped to illegal pblock %llu "
406406
"(length %d)", (unsigned long) map->m_lblk,
407-
map->m_len);
407+
map->m_pblk, map->m_len);
408408
return -EFSCORRUPTED;
409409
}
410410
return 0;
@@ -4506,7 +4506,8 @@ static int __ext4_get_inode_loc(struct inode *inode,
45064506
int inodes_per_block, inode_offset;
45074507

45084508
iloc->bh = NULL;
4509-
if (!ext4_valid_inum(sb, inode->i_ino))
4509+
if (inode->i_ino < EXT4_ROOT_INO ||
4510+
inode->i_ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count))
45104511
return -EFSCORRUPTED;
45114512

45124513
iloc->block_group = (inode->i_ino - 1) / EXT4_INODES_PER_GROUP(sb);

‎fs/ext4/mballoc.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,8 @@ int ext4_mb_add_groupinfo(struct super_block *sb, ext4_group_t group,
24232423
* initialize bb_free to be able to skip
24242424
* empty groups without initialization
24252425
*/
2426-
if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
2426+
if (ext4_has_group_desc_csum(sb) &&
2427+
(desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))) {
24272428
meta_group_info[i]->bb_free =
24282429
ext4_free_clusters_after_init(sb, group, desc);
24292430
} else {
@@ -2989,7 +2990,8 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
29892990
#endif
29902991
ext4_set_bits(bitmap_bh->b_data, ac->ac_b_ex.fe_start,
29912992
ac->ac_b_ex.fe_len);
2992-
if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
2993+
if (ext4_has_group_desc_csum(sb) &&
2994+
(gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))) {
29932995
gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);
29942996
ext4_free_group_clusters_set(sb, gdp,
29952997
ext4_free_clusters_after_init(sb,

0 commit comments

Comments
 (0)