When lazily zeroing an inode table, ext4_init_inode_table() issues a cache flush to make sure the zeroed blocks have reached the disk before setting the EXT4_BG_INODE_ZEROED flag, but the return value is ignored. If the cache flush fails, the inode table is still marked as initialized, and a subsequent crash can leave the table containing stale data from the previous use of the disk, which may then be exposed to user space through newly allocated inodes. Check the return value of blkdev_issue_flush() and leave EXT4_BG_INODE_ZEROED unset if the cache flush fails, so that the inode table zeroing is retried on the next mount. Since a cache flush failure now aborts the lazy inode table initialization, also pass the barrier mount option down to ext4_init_inode_table(), consistent with the other cache flushes in ext4 and jbd2 which are issued only when the barrier option is enabled. This keeps file systems mounted with nobarrier working on devices with failing cache flushes. Fixes: a107e5a3a473a ("Merge branch 'next' into upstream-merge") Cc: stable@vger.kernel.org Signed-off-by: guolingxing --- fs/ext4/ialloc.c | 7 +++++-- fs/ext4/super.c | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index a5831fc536db..9abd7fb75b02 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1610,8 +1610,11 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group, ret = sb_issue_zeroout(sb, blk, num, GFP_NOFS); if (ret < 0) goto err_out; - if (barrier) - blkdev_issue_flush(sb->s_bdev); + if (barrier) { + ret = blkdev_issue_flush(sb->s_bdev); + if (ret) + goto err_out; + } skip_zeroout: ext4_lock_group(sb, group); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index d636b89090a2..941af6fd050c 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3793,7 +3793,8 @@ static int ext4_run_li_request(struct ext4_li_request *elr) if (!ret) { start_time = ktime_get_ns(); ret = ext4_init_inode_table(sb, group, - elr->lr_timeout ? 0 : 1); + !elr->lr_timeout && + test_opt(sb, BARRIER)); trace_ext4_lazy_itable_init(sb, group); if (elr->lr_timeout == 0) { elr->lr_timeout = nsecs_to_jiffies((ktime_get_ns() - start_time) * -- 2.34.1