OSDN Git Service

ext4: prevent getting empty inode buffer
authorZhang Yi <yi.zhang@huawei.com>
Wed, 1 Sep 2021 02:09:55 +0000 (10:09 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 4 Nov 2021 14:33:25 +0000 (10:33 -0400)
commitde01f484576d29b02fb2856387f29cfdf5ad4f19
tree570603162bc425cfabdbbc889bbb22aab6e6b6b9
parent9a1bf32c8e12b7768325e83e9b9eeb69c46435b3
ext4: prevent getting empty inode buffer

In ext4_get_inode_loc(), we may skip IO and get an zero && uptodate
inode buffer when the inode monopolize an inode block for performance
reason. For most cases, ext4_mark_iloc_dirty() will fill the inode
buffer to make it fine, but we could miss this call if something bad
happened. Finally, __ext4_get_inode_loc_noinmem() may probably get an
empty inode buffer and trigger ext4 error.

For example, if we remove a nonexistent xattr on inode A,
ext4_xattr_set_handle() will return ENODATA before invoking
ext4_mark_iloc_dirty(), it will left an uptodate but zero buffer. We
will get checksum error message in ext4_iget() when getting inode again.

  EXT4-fs error (device sda): ext4_lookup:1784: inode #131074: comm cat: iget: checksum invalid

Even worse, if we allocate another inode B at the same inode block, it
will corrupt the inode A on disk when write back inode B.

So this patch initialize the inode buffer by filling the in-mem inode
contents if we skip read I/O, ensure that the buffer is really uptodate.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20210901020955.1657340-4-yi.zhang@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/inode.c