From nobody Tue Sep 16 05:49:14 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 675A5C54E76 for ; Fri, 6 Jan 2023 10:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233594AbjAFKWm (ORCPT ); Fri, 6 Jan 2023 05:22:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231511AbjAFKWh (ORCPT ); Fri, 6 Jan 2023 05:22:37 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC429551CB; Fri, 6 Jan 2023 02:22:36 -0800 (PST) Received: from dggpeml500021.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NpK9v0ZTtz16MMd; Fri, 6 Jan 2023 18:21:07 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpeml500021.china.huawei.com (7.185.36.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 6 Jan 2023 18:22:34 +0800 From: Baokun Li To: CC: , , , , , , , , =?UTF-8?q?Lu=C3=ADs=20Henriques?= Subject: [PATCH 2/2] ext4: update s_journal_inum if it changes after journal replay Date: Fri, 6 Jan 2023 18:47:06 +0800 Message-ID: <20230106104706.2410740-3-libaokun1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230106104706.2410740-1-libaokun1@huawei.com> References: <20230106104706.2410740-1-libaokun1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500021.china.huawei.com (7.185.36.21) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=3D216541 Reported-by: Lu=C3=ADs Henriques Signed-off-by: Baokun Li Reviewed-by: Jan Kara --- fs/ext4/super.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 !=3D le32_to_cpu(es->s_journal_dev)) { es->s_journal_dev =3D 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 !=3D le32_to_cpu(es->s_journal_inum)) { + es->s_journal_inum =3D cpu_to_le32(journal_inum); ext4_commit_super(sb); } =20 --=20 2.31.1