Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp535137pxb; Thu, 21 Jan 2021 13:12:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzFtO0MH8U6K7WoqRXii3QrtVFWgAS57Fv6RBymETMaoo6IZfDWM7dg99xdkWz35nhOy0z1 X-Received: by 2002:a17:906:4159:: with SMTP id l25mr853436ejk.311.1611263529656; Thu, 21 Jan 2021 13:12:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611263529; cv=none; d=google.com; s=arc-20160816; b=pZc+eBWbEFetekLov14KvCQbk+uhhKAxFIgr/9KitN1MXowZ/NwfkLq8QB3/OFBiyf n3XS8ftMLBPIeYrin7xnSCIMuRNMvR890RFi439MBuDo2Cg03lvLQ/AVk8GWdo73Fct0 sZYvK8qUg3YiPbxYDY3j1XMXq6a27FZ3Z9lv4Tfd7RIkiNtGktGwnVrAg56bMtCJS322 ja/YmpSXDuFTT9HThgMON9YQvkra884nOLKAGY80mLa8n57+wmuPcFxHxAQ/E4ClUeJ7 tN0kMOihxhi49sfo3vO/ricKmgzGJRVBzd3yScmrG1tt/JX0fndnwQp10ASBiXmwGbAE rM6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=YnyyTvOOB7ZN3wILVYFe4pSpVR58IjL1rePsBXW0uSo=; b=VudORz2AFjhXf4uO8k6zJwdMJX5vhzdWvh1CNsN4OOMBGNWrJXUsplU3Y59n9sAePY KfkCDmLWIV9p6CBT7pxoeZxEH7k9XtQyNeU823vsE1PLjPXhw3TqlY7h7jc/tUPy2ank +oh1iU76wyMr23tytt5FqSdfUWhhdJQSx5XBWbGkUZle8fvk2dGgvO/jKudBeBGkw1XP LQ+n3hhcKvM8LGcPHVuoz3hI9zWbyl2OnJLJCUCmhYOTg+rnNc+J8AazCmqKT/UFxvi8 i/Y//w3TNdXxC5HAh/rhts0dLDU8bTCfnkyM/1yHomK+NqiCQUu4M99OoF79rMEHHHoH AMQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs10si2149432ejb.494.2021.01.21.13.11.41; Thu, 21 Jan 2021 13:12:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727726AbhAUVLA (ORCPT + 99 others); Thu, 21 Jan 2021 16:11:00 -0500 Received: from mx2.suse.de ([195.135.220.15]:37604 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727717AbhAUVKb (ORCPT ); Thu, 21 Jan 2021 16:10:31 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0B180AC8F; Thu, 21 Jan 2021 21:09:50 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id B2F221E0816; Thu, 21 Jan 2021 22:09:49 +0100 (CET) Date: Thu, 21 Jan 2021 22:09:49 +0100 From: Jan Kara To: Theodore Ts'o Cc: Murphy Zhou , Jan Kara , linux-ext4@vger.kernel.org Subject: Re: ext4 regression panic Message-ID: <20210121210949.GH24063@quack2.suse.cz> References: <20210121101547.fwh35hov3hshogbz@xzhoux.usersys.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu 21-01-21 12:40:56, Theodore Ts'o wrote: > On Thu, Jan 21, 2021 at 06:15:47PM +0800, Murphy Zhou wrote: > > Hi Jack, > > > > A panic was introduced by this commit. It's easy and reliable to > > reproduce. > > > > commit 2d01ddc86606564fb08c56e3bc93a0693895f710 > > Author: Jan Kara > > Date: Wed Dec 16 11:18:40 2020 +0100 > > > > ext4: save error info to sb through journal if available > > Hi Murphy, > > Thanks for the bug report. What's happening is that we haven't yet > initialized mballoc yet --- that happens in line 4943 of > fs/ext4/super.c, in ext4_fill_super(). > > But in line 4903 (in the case of the BZ #199275 reproducer), we > attempt to fetch the root inode, which is fails because it is > unallocated. That then triggers a call to ext4_error(), which now > results in a journalled change, since the journal is initialized > starting in line 4793, and in line 4838, we set up the > j_commit_callback, which is what ends up calling > ext4_process_freed_data(), but since the multiblock allocator hasn't > been set up yet, that causes the NULL pointer dereference. > > So what we need to do is to *not* set up the callback until after the > call to ext4_mb_init(). > > We should probably create an ext4-specific test in xfstests which > tries mounting a small, deliberately corrupted file system, to make > sure we handle this case correctly in the future. > > - Ted Thanks for looking into this. You beat me to my fix (which was slightly different - I moved ext4_mb_init() somewhat earlier during mount). But this should work fine as well. So feel free to add: Reviewed-by: Jan Kara Honza > > commit 6c2f9a8247273cf1108ff71c99680b7457f48318 > Author: Theodore Ts'o > Date: Thu Jan 21 12:33:20 2021 -0500 > > ext4: don't try to processed freed blocks until mballoc is initialized > > If we try to make any changes via the journal between when the journal > is initialized, but before the multi-block allocated is initialized, > we will end up deferencing a NULL pointer when the journal commit > callback function calls ext4_process_freed_data(). > > The proximate cause of this failure was commit 2d01ddc86606 ("ext4: > save error info to sb through journal if available") since file system > corruption problems detected before the call to ext4_mb_init() would > result in a journal commit before we aborted the mount of the file > system.... and we would then trigger the NULL pointer deref. > > Cc: Jan Kara > Reported by: Murphy Zhou > Signed-off-by: Theodore Ts'o > > diff --git a/fs/ext4/super.c b/fs/ext4/super.c > index 0f0db49031dc..802ef55f0a55 100644 > --- a/fs/ext4/super.c > +++ b/fs/ext4/super.c > @@ -4876,7 +4876,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) > > set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); > > - sbi->s_journal->j_commit_callback = ext4_journal_commit_callback; > sbi->s_journal->j_submit_inode_data_buffers = > ext4_journal_submit_inode_data_buffers; > sbi->s_journal->j_finish_inode_data_buffers = > @@ -4993,6 +4992,14 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) > goto failed_mount5; > } > > + /* > + * We can only set up the journal commit callback once > + * mballoc is initialized > + */ > + if (sbi->s_journal) > + sbi->s_journal->j_commit_callback = > + ext4_journal_commit_callback; > + > block = ext4_count_free_clusters(sb); > ext4_free_blocks_count_set(sbi->s_es, > EXT4_C2B(sbi, block)); -- Jan Kara SUSE Labs, CR