• zhangyi (F)'s avatar
    ext4, jbd2: ensure panic by fix a race between jbd2 abort and ext4 error handlers · 7b97d868
    zhangyi (F) authored
    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: 4327ba52 ("ext4, jbd2: ensure entering into panic after recording an error in superblock")
    Signed-off-by: default avatarzhangyi (F) <yi.zhang@huawei.com>
    Reviewed-by: default avatarJan Kara <jack@suse.cz>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20200609073540.3810702-1-yi.zhang@huawei.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
    7b97d868
super.c 178 KB