From patchwork Wed Oct 19 08:23:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4668 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp212799wrs; Wed, 19 Oct 2022 02:08:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4uftftr4rXlbEeDDgpwqZ5t/5wgumVh5hCBpNWqbL6eFGVHmx7//X9u3eqTXVomh49CgdB X-Received: by 2002:a17:906:5dce:b0:78d:e71a:6e0 with SMTP id p14-20020a1709065dce00b0078de71a06e0mr5889453ejv.360.1666170498643; Wed, 19 Oct 2022 02:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666170498; cv=none; d=google.com; s=arc-20160816; b=sydtf9CSay23D+eLcd1BglPY2rLH5OyV6eGwuTNNcEaYrMzwgWtuv5fAQzDtAY8KBs eX87VEpcZ1rgBobkPzw9hRjvbHgkFO163nE0d1fGzd+VAXK1cUrXYjJK7Ikml0Xy8nCM 3SSDsCU7FRd6v6Hw9uKqMO+DlB6mNGbcwIh21ud7AczCkHznApT/lJ7ygWJJTOMR6ROm oUgrnwlCkFZPO/u2gC9PhDWF0kVCny2QKtjRAjrCl14ZAJFoGLpO+s4+34hrGbohhK88 CD2z6+PgXh43Pwrk2WA0T9YFSXNpsnZ+hYTLP3perYEuJTSeEDHYdAj1Bh27GM9V50om auEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3RBOMA4KSOs7ciltZZ4vn7q9XF7MlRafMfQc4czrQv8=; b=eMlV9cwxTVsHQd4X+jQN7kL44J13fVZcVkdyaBoQQ0A8/ZTbZIrleiXxgvQgIIHXZ7 6rW0hFvk3J8bKSZ4VpoojUU+S+gElsD+hXw/Xs4Ch1pjMI0QwcHSqFuPoi6vJT2zvfaV 7zTVq4WFPbWCsVJBp1cn0mT+pCNhyDlP69V4TrOF3ExJ4w5oMZJVNdVh6+j+WhXugbq/ VBtkWoV1TTRcrG9m03DK29Fq8AXQFlaaPXpvRlKrvCKxxIzvsaCoNJr+p1sAvaUp1PWP K+xqaCNPgKT+TWTzb65NUib3uts9U1HdqJdmy6en1DHaoc95BKz1w17MR14PqtfJdiM8 vTZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SUxBeqoM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bq3-20020a056402214300b0044f2eb2de9asi12029807edb.444.2022.10.19.02.07.41; Wed, 19 Oct 2022 02:08:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SUxBeqoM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232160AbiJSJAi (ORCPT + 99 others); Wed, 19 Oct 2022 05:00:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231987AbiJSI6v (ORCPT ); Wed, 19 Oct 2022 04:58:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A45849DD89; Wed, 19 Oct 2022 01:53:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 45AD2617D1; Wed, 19 Oct 2022 08:43:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54E03C433C1; Wed, 19 Oct 2022 08:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169034; bh=F/hirolBpGxpu/uc2JCMoWzXNNZUj+88U+p3ETdyMeE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SUxBeqoMiO8KYKEh7JW+bUgMx+i017e2rlsG8RaEHgXN6mDVJpFhRjodFRyihoHmz PHrYs8r31pEKFqBvkghMRmd8c1MgVJkomIK6cFBGmYnzpdRFj+tJX2CRYCBWtbc3P9 j6hhiJaTg/VysFouI17+3pB1FAZhPD90WkkirtRQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Baokun Li , Jan Kara , Theodore Tso Subject: [PATCH 6.0 136/862] ext4: fix null-ptr-deref in ext4_write_info Date: Wed, 19 Oct 2022 10:23:43 +0200 Message-Id: <20221019083255.990667040@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747106396884928688?= X-GMAIL-MSGID: =?utf-8?q?1747106396884928688?= From: Baokun Li commit f9c1f248607d5546075d3f731e7607d5571f2b60 upstream. I caught a null-ptr-deref bug as follows: ================================================================== KASAN: null-ptr-deref in range [0x0000000000000068-0x000000000000006f] CPU: 1 PID: 1589 Comm: umount Not tainted 5.10.0-02219-dirty #339 RIP: 0010:ext4_write_info+0x53/0x1b0 [...] Call Trace: dquot_writeback_dquots+0x341/0x9a0 ext4_sync_fs+0x19e/0x800 __sync_filesystem+0x83/0x100 sync_filesystem+0x89/0xf0 generic_shutdown_super+0x79/0x3e0 kill_block_super+0xa1/0x110 deactivate_locked_super+0xac/0x130 deactivate_super+0xb6/0xd0 cleanup_mnt+0x289/0x400 __cleanup_mnt+0x16/0x20 task_work_run+0x11c/0x1c0 exit_to_user_mode_prepare+0x203/0x210 syscall_exit_to_user_mode+0x5b/0x3a0 do_syscall_64+0x59/0x70 entry_SYSCALL_64_after_hwframe+0x44/0xa9 ================================================================== Above issue may happen as follows: ------------------------------------- exit_to_user_mode_prepare task_work_run __cleanup_mnt cleanup_mnt deactivate_super deactivate_locked_super kill_block_super generic_shutdown_super shrink_dcache_for_umount dentry = sb->s_root sb->s_root = NULL <--- Here set NULL sync_filesystem __sync_filesystem sb->s_op->sync_fs > ext4_sync_fs dquot_writeback_dquots sb->dq_op->write_info > ext4_write_info ext4_journal_start(d_inode(sb->s_root), EXT4_HT_QUOTA, 2) d_inode(sb->s_root) s_root->d_inode <--- Null pointer dereference To solve this problem, we use ext4_journal_start_sb directly to avoid s_root being used. Cc: stable@kernel.org Signed-off-by: Baokun Li Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220805123947.565152-1-libaokun1@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -6653,7 +6653,7 @@ static int ext4_write_info(struct super_ handle_t *handle; /* Data block + inode block */ - handle = ext4_journal_start(d_inode(sb->s_root), EXT4_HT_QUOTA, 2); + handle = ext4_journal_start_sb(sb, EXT4_HT_QUOTA, 2); if (IS_ERR(handle)) return PTR_ERR(handle); ret = dquot_commit_info(sb, type);