Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1199928rwb; Thu, 19 Jan 2023 07:46:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXukciHnNOsBABhcsyvMAzPyjeuUNXS1ktHfZ838W7BiiDQ9T40eOo1WAyJNPYbTn+EUc+Yi X-Received: by 2002:a05:6402:2b8c:b0:48f:a9a2:29fa with SMTP id fj12-20020a0564022b8c00b0048fa9a229famr12032327edb.2.1674143201667; Thu, 19 Jan 2023 07:46:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674143201; cv=none; d=google.com; s=arc-20160816; b=z5gxDhQuUtM+/NbPKty0eMJXcMupBK0DSr4X3t9R7cWqUXsqlYJ/c8WuVb2RgW5BXV viOXpEuKOTyp+yjeBAm/FklKq387wPu+C4xqDGOwd+q1gPrJreDaY79kB5hqzObq548J e9El0rqXVgHbEQGtZDIu2IyhVuYsbFMmWvNBHMHjnBEitzdDheby8K1JHtKMY7QMH/Av hMPGKMwIHvYFge//568MCapwIWaP1XUlJ6nahO8PvttOVhmj1puyrAJaiErkiV1dnxCV bblP660dGL+fAi7fXsT9MJCSqlR+VmUcQUfpMIpuf18dq2WSSDXnVIzer5hcC9BEcZhj YGdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=bgoU10Jpwp3Wcue7Yi3vYVywPMli7wY4wRcHZx3PSzk=; b=nZtLb53qVoIzCi77XhnhJKA+2mU32an4SW34DVFTMukSXAD6OCISQSA0qECcJgoFZL QLx98cOVpp4oZ4zGQWXvfohC2xnWJC4DPBYzFtTVCTh90wtO5TsT+nZ9ydClE8PlSyWC 1V0UWQyvVx+quO1Epy2YWlzASyb88bS6+x4f3AHeOyt1QrRDj3WwxV2gwOgYmeBOsmmz p623ubxwLbtBZtl8LWyx29r/UHSqnLCpG8YGXGNQy27nr7RsvDHbQl1wzwiA7A+0ul1i Z30WLmoNYzA8dbrdPzjItkKlxrEuyJjGWPIdSrOevFk4vbjCoy8mWSHxRPkTxHphDkUw feaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=G13FrqbK; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m10-20020aa7c2ca000000b0049d3f8672a7si18112939edp.193.2023.01.19.07.46.16; Thu, 19 Jan 2023 07:46:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-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=@suse.cz header.s=susede2_rsa header.b=G13FrqbK; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230491AbjASPfr (ORCPT + 99 others); Thu, 19 Jan 2023 10:35:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231178AbjASPfn (ORCPT ); Thu, 19 Jan 2023 10:35:43 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21FE08455D; Thu, 19 Jan 2023 07:35:35 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BE06F5CF34; Thu, 19 Jan 2023 15:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674142533; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bgoU10Jpwp3Wcue7Yi3vYVywPMli7wY4wRcHZx3PSzk=; b=G13FrqbK4qEtDHNCacmQIkOHhLPK+f7yD61hzIgnUVOPS+dyNlbt/eKbW8xUVMAznsTzUF +zLOuho/JhCVr4aIZnx5Y4H/OSbzmS4+MCiNjv0RnAMtglAviNYjlJEG38gzy0sYP0dzdN arKqFM4mG6/HntouaKxHRxYSrPumdoI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674142533; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bgoU10Jpwp3Wcue7Yi3vYVywPMli7wY4wRcHZx3PSzk=; b=fjURUhO6yVIpkK+w7jZZ1QZQ3Y8dSTDa/+tKq0j1cPHAKYaV/RgyytpUhKJFtcsmzuXJFH KRzf2DHurwdAt3Dg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 952F0134F5; Thu, 19 Jan 2023 15:35:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id RyNJJEVjyWMnSwAAMHmgww (envelope-from ); Thu, 19 Jan 2023 15:35:33 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 28627A06B2; Thu, 19 Jan 2023 16:35:32 +0100 (CET) Date: Thu, 19 Jan 2023 16:35:32 +0100 From: Jan Kara To: Ye Bin Cc: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: Re: [PATCH] ext4: init error handle resource before init group descriptors Message-ID: <20230119153532.ws3knxxjy6sjxnuz@quack3> References: <20230119013711.86680-1-yebin@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230119013711.86680-1-yebin@huaweicloud.com> X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL 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-ext4@vger.kernel.org On Thu 19-01-23 09:37:11, Ye Bin wrote: > From: Ye Bin > > Now, 's_err_report' timer is init after ext4_group_desc_init() when fill > super. Theoretically, ext4_group_desc_init() may access to error handle > as follows: > __ext4_fill_super > ext4_group_desc_init > ext4_check_descriptors > ext4_get_group_desc > ext4_error > ext4_handle_error > ext4_commit_super > ext4_update_super > if (!es->s_error_count) > mod_timer(&sbi->s_err_report, jiffies + 24*60*60*HZ); > --> Accessing Uninitialized Variables > timer_setup(&sbi->s_err_report, print_daily_error_info, 0); > > Maybe above issue is just theoretical, as ext4_check_descriptors() didn't > judge 'gpd' which get from ext4_get_group_desc(), if access to error handle > ext4_get_group_desc() will return NULL, then will trigger null-ptr-deref in > ext4_check_descriptors(). > However, from the perspective of pure code, it is better to initialize > resource that may need to be used first. Looks good to me. Feel free to add: Reviewed-by: Jan Kara Honza > fs/ext4/super.c | 19 +++++++------------ > 1 file changed, 7 insertions(+), 12 deletions(-) > > diff --git a/fs/ext4/super.c b/fs/ext4/super.c > index b31db521d6bf..dc3907dff13a 100644 > --- a/fs/ext4/super.c > +++ b/fs/ext4/super.c > @@ -4738,7 +4738,6 @@ static int ext4_group_desc_init(struct super_block *sb, > struct ext4_sb_info *sbi = EXT4_SB(sb); > unsigned int db_count; > ext4_fsblk_t block; > - int ret; > int i; > > db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) / > @@ -4778,8 +4777,7 @@ static int ext4_group_desc_init(struct super_block *sb, > ext4_msg(sb, KERN_ERR, > "can't read group descriptor %d", i); > sbi->s_gdb_count = i; > - ret = PTR_ERR(bh); > - goto out; > + return PTR_ERR(bh); > } > rcu_read_lock(); > rcu_dereference(sbi->s_group_desc)[i] = bh; > @@ -4788,13 +4786,10 @@ static int ext4_group_desc_init(struct super_block *sb, > sbi->s_gdb_count = db_count; > if (!ext4_check_descriptors(sb, logical_sb_block, first_not_zeroed)) { > ext4_msg(sb, KERN_ERR, "group descriptors corrupted!"); > - ret = -EFSCORRUPTED; > - goto out; > + return -EFSCORRUPTED; > } > + > return 0; > -out: > - ext4_group_desc_free(sbi); > - return ret; > } > > static int ext4_load_and_init_journal(struct super_block *sb, > @@ -5220,14 +5215,14 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) > if (ext4_geometry_check(sb, es)) > goto failed_mount; > > - err = ext4_group_desc_init(sb, es, logical_sb_block, &first_not_zeroed); > - if (err) > - goto failed_mount; > - > timer_setup(&sbi->s_err_report, print_daily_error_info, 0); > spin_lock_init(&sbi->s_error_lock); > INIT_WORK(&sbi->s_error_work, flush_stashed_error_work); > > + err = ext4_group_desc_init(sb, es, logical_sb_block, &first_not_zeroed); > + if (err) > + goto failed_mount3; > + > /* Register extent status tree shrinker */ > if (ext4_es_register_shrinker(sbi)) > goto failed_mount3; > -- > 2.31.1 > -- Jan Kara SUSE Labs, CR