ext4, jbd2: ensure panic by fix a race between jbd2 abort and ext4 error handlers
authorzhangyi (F) <yi.zhang@huawei.com>
Tue, 9 Jun 2020 07:35:40 +0000 (15:35 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 12 Jun 2020 18:51:41 +0000 (14:51 -0400)
commit7b97d868b7ab2448859668de9222b8af43f76e78
tree976e49fc89eb8cd37e653d27192d9cb5289ed884
parent88ee9d571b6d8ed345f877e05f685814412e359b
ext4, jbd2: ensure panic by fix a race between jbd2 abort and ext4 error handlers

In the ext4 filesystem with errors=panic, if one process is recording
errno in the superblock when invoking jbd2_journal_abort() due to some
error cases, it could be raced by another __ext4_abort() which is
setting the SB_RDONLY flag but missing panic because errno has not been
recorded.

jbd2_journal_commit_transaction()
 jbd2_journal_abort()
  journal->j_flags |= JBD2_ABORT;
  jbd2_journal_update_sb_errno()
                                    | ext4_journal_check_start()
                                    |  __ext4_abort()
                                    |   sb->s_flags |= SB_RDONLY;
                                    |   if (!JBD2_REC_ERR)
                                    |        return;
  journal->j_flags |= JBD2_REC_ERR;

Finally, it will no longer trigger panic because the filesystem has
already been set read-only. Fix this by introduce j_abort_mutex to make
sure journal abort is completed before panic, and remove JBD2_REC_ERR
flag.

Fixes: 4327ba52afd03 ("ext4, jbd2: ensure entering into panic after recording an error in superblock")
Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20200609073540.3810702-1-yi.zhang@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/super.c
fs/jbd2/journal.c
include/linux/jbd2.h