diff mbox series

[2/2] ext4: update s_journal_inum if it changes after journal replay

Message ID 20230106104706.2410740-3-libaokun1@huawei.com
State Superseded
Headers show
Series ext4: fix possible null pointer dereference in ext4_get_group_info | expand

Commit Message

Baokun Li Jan. 6, 2023, 10:47 a.m. UTC
When mounting a crafted ext4 image, s_journal_inum may change after journal
replay, which is obviously unreasonable because we have successfully loaded
and replayed the journal through the old s_journal_inum. And the new
s_journal_inum bypasses some of the checks in ext4_get_journal(), which
may trigger a null pointer dereference problem. So if s_journal_inum
changes after the journal replay, we ignore the change, and rewrite the
current journal_inum to the superblock.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=216541
Reported-by: Luís Henriques <lhenriques@suse.de>
Signed-off-by: Baokun Li <libaokun1@huawei.com>
---
 fs/ext4/super.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Jan Kara Jan. 6, 2023, 2:36 p.m. UTC | #1
On Fri 06-01-23 18:47:06, Baokun Li wrote:
> When mounting a crafted ext4 image, s_journal_inum may change after journal
> replay, which is obviously unreasonable because we have successfully loaded
> and replayed the journal through the old s_journal_inum. And the new
> s_journal_inum bypasses some of the checks in ext4_get_journal(), which
> may trigger a null pointer dereference problem. So if s_journal_inum
> changes after the journal replay, we ignore the change, and rewrite the
> current journal_inum to the superblock.
> 
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216541
> Reported-by: Luís Henriques <lhenriques@suse.de>
> Signed-off-by: Baokun Li <libaokun1@huawei.com>
> ---
>  fs/ext4/super.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza


> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 260c1b3e3ef2..3fe9dc19ff9c 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -5953,8 +5953,11 @@ static int ext4_load_journal(struct super_block *sb,
>  	if (!really_read_only && journal_devnum &&
>  	    journal_devnum != le32_to_cpu(es->s_journal_dev)) {
>  		es->s_journal_dev = cpu_to_le32(journal_devnum);
> -
> -		/* Make sure we flush the recovery flag to disk. */
> +		ext4_commit_super(sb);
> +	}
> +	if (!really_read_only && journal_inum &&
> +	    journal_inum != le32_to_cpu(es->s_journal_inum)) {
> +		es->s_journal_inum = cpu_to_le32(journal_inum);
>  		ext4_commit_super(sb);
>  	}
>  
> -- 
> 2.31.1
>
diff mbox series

Patch

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 260c1b3e3ef2..3fe9dc19ff9c 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5953,8 +5953,11 @@  static int ext4_load_journal(struct super_block *sb,
 	if (!really_read_only && journal_devnum &&
 	    journal_devnum != le32_to_cpu(es->s_journal_dev)) {
 		es->s_journal_dev = cpu_to_le32(journal_devnum);
-
-		/* Make sure we flush the recovery flag to disk. */
+		ext4_commit_super(sb);
+	}
+	if (!really_read_only && journal_inum &&
+	    journal_inum != le32_to_cpu(es->s_journal_inum)) {
+		es->s_journal_inum = cpu_to_le32(journal_inum);
 		ext4_commit_super(sb);
 	}