From patchwork Mon Oct 24 11:29:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8679 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp422292wru; Mon, 24 Oct 2022 05:22:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4tb+ku/39WtiiKJY4GrE3X42Vsqt/u47aH8wlTOKlcS55R4xF4qzYYUQD78Kywqe7B314j X-Received: by 2002:a17:907:dac:b0:78e:17a0:d1cb with SMTP id go44-20020a1709070dac00b0078e17a0d1cbmr27631042ejc.618.1666614138386; Mon, 24 Oct 2022 05:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666614138; cv=none; d=google.com; s=arc-20160816; b=f5HXQa+jSs+/SaS1DtyCyh3cotmXYthEVHi6+QwBDCvn6p1ljM21nLW1JmlUqdOVUd fm3CIj6bcICJ3Lbooi/Bqog3d1ZhpY+7oLHWBq2ws+ekbZZMSu54dEHg4WqXp0xc+TQT 2N0nVBL0Rzk+UfEqwY7Q7XQakldaFIkedRAjSLudsNPsLLfqLL2eGZY1m6kXFx9W7MVx C3r8GwuSCClFHiT+A4DLpB5eWl4uBcBNZ2spikKXp69969wF8c+EXF/YoXW5aoVk7fSh 0U7gWPZu5ohxOvHwzlDANYShWcrnPdfnhP/qVNKoCpeSjd+CLBqHbs4ftuthQ2D7vvr1 Lqqw== 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=EURmE7Jt8EFxoL5a72GyLyPsGn9krOzI85LjGPzJs8M=; b=GsYkCx/byP9GFDQLvtZPnWPjz9vh5hTnm8ifzzV4dn/2o6bxL4u7WBhteUrVuVIOSr U8SNC2HfDA6LwtZB0b8IRoYKWfQ4csQxS/mMYL3VdgaJ+AVlfO2rYMKWKjLilRZ/4CFT bJYZQ//LUDaKJ+7Dlhc04Kk4A7gtc/7SSvZ0xXVq2pFcTVKDI8NxEghPeJb/qMIXYSU9 98Pe9Sbz89nqn/20Z6QzcgPibUuLmtNoygHhkYfRRohQc4C/9LLjLRXKoRZV9wd1i+q2 NuyPDjOxIjquwygwUTdBCi40jTCatM3WSwmNvIlw9jrLMsvbeAGNmzMoQed2aetNUZgk Rj8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YMQHgf8C; 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 mp36-20020a1709071b2400b0078e2828052asi28908833ejc.638.2022.10.24.05.21.53; Mon, 24 Oct 2022 05:22: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=YMQHgf8C; 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 S233195AbiJXMUN (ORCPT + 99 others); Mon, 24 Oct 2022 08:20:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233277AbiJXMTF (ORCPT ); Mon, 24 Oct 2022 08:19:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CF80816B8; Mon, 24 Oct 2022 04:57:33 -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 219B0612D2; Mon, 24 Oct 2022 11:57:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34518C433D6; Mon, 24 Oct 2022 11:57:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612627; bh=anviEcYHuKsLQZfCwdgo3hZTRU8BjjWQ5XXrx9ZPAn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YMQHgf8C/Qupb4xXVdiRdV2QDx6GXF2OQyBEJmpXgfqjfQPHtVU+hkvDwkD92o1t4 gjw3T3EoTEWUmrV6bUQaLJU03+q3/+hyMRXmumZqoTxH8bp1ghvYrD3NYB/DFZTTu0 X643Sahl119KA6QQGEQXO8seO/2hsYkZ/WchCFBo= 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 4.19 059/229] ext4: fix null-ptr-deref in ext4_write_info Date: Mon, 24 Oct 2022 13:29:38 +0200 Message-Id: <20221024113000.998337697@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747571587266999398?= X-GMAIL-MSGID: =?utf-8?q?1747571587266999398?= 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 @@ -5721,7 +5721,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);