Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp8010760rwn; Wed, 14 Sep 2022 07:43:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4sdVOPUCv5HSjxJGvqHygfTDtbsSZ/5vxnTUfu7sqXFkxM6lqedVdnh7sm8VCaIVt5mgi+ X-Received: by 2002:a05:6a00:198d:b0:548:bd77:69b1 with SMTP id d13-20020a056a00198d00b00548bd7769b1mr627723pfl.20.1663166594940; Wed, 14 Sep 2022 07:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663166594; cv=none; d=google.com; s=arc-20160816; b=tvHtueMI6uf5CI5r3hyWgDdwrcaLdc6/4+uAmJ4OrhkTAPj6tWSkeFmh9fO3XLpl8b jQu1LRv5UldXdDE+UvAEUC4akRT6T2FB8h2WmsbDYxLaxagl/dcdtwyJAgA+TCjc77xE RsvQqCTKmRuEvxrRjU+CWU09ecSsf95tq4WaBt3uVLOB1kB7Ku+Wc0cLPMUpBF8pnydo RC5Zn7YmRK4PLfBYifru8cBjqlyXUfzEkkS2lU07lVQXgkM00elN31/2HOdUjwOURwgk Qf8oO/Ip8eXSS0oIFy05fKinJEP+Wx7QUIB7QBLe+5gJovDP2THo7l9dHHJZdM8hCFs5 l+hg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature; bh=EcKFFNOXpymxwv8o+pvzoP8IcYNUQYJkgNRkyvMjD40=; b=raIPCCtThLUJ7ik7UIxhrJlX+d/Hlub3CSLEvDJKuYWxLB5UYypv18VZXL5SmnMjWE d3tR/fA7E5Lt8hhx3qozplMyySkoCUtPkvzEljpF4agFz0E0YhkHrZuqL7f1xCLqc5eR UN/h7QS/9LawKjBRpgZep+wpR5LlA2S4VZFr7GQ5+hxaQQ0CcJRgxsWFuTs78umH4jbb pb7eTJImjy5y6p08GLJRBXAjtPYFUyx8hmPfPQWnqtk5qdc2JibZKCZorO2saHAR8I/7 H9W+21LDPU5tU1unF/8PKoaIgG2NdjpkyBMg7O/zGiznbeUDYbi0rKkesxfgIr7laPV+ fR8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=G1GhRhSn; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=Gudm51E5; 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 qe5-20020a17090b4f8500b001fe123e7d53si16810714pjb.6.2022.09.14.07.42.53; Wed, 14 Sep 2022 07:43:14 -0700 (PDT) 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=G1GhRhSn; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=Gudm51E5; 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 S230126AbiINOgk (ORCPT + 99 others); Wed, 14 Sep 2022 10:36:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbiINOg3 (ORCPT ); Wed, 14 Sep 2022 10:36:29 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E86475721E; Wed, 14 Sep 2022 07:36:28 -0700 (PDT) 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-out1.suse.de (Postfix) with ESMTPS id 63966338DF; Wed, 14 Sep 2022 14:36:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1663166187; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EcKFFNOXpymxwv8o+pvzoP8IcYNUQYJkgNRkyvMjD40=; b=G1GhRhSnTMNSetoHStSUHA8hxFmnY4Vs9n9HFMHkqoCi2BYPteUhGO2kIdoBtT1Db6C+Mp 037B6NnLWgyqXzbI6yRG7bHNm9/3qPjsG6n0ysSM490zECG5EMzi4lzZOnwxAJ1QsBc4dC LsxnpBI9Bx2o/wNytiRO/7tCmbrdybw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1663166187; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EcKFFNOXpymxwv8o+pvzoP8IcYNUQYJkgNRkyvMjD40=; b=Gudm51E509PRvna+wt36JZR8YSuasRr39N6d+A0jiDv+eYLqOayVioIFJ8eBtpbFAQYlIQ wOIhgLGOIUvjDPBw== 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 53FC2134B3; Wed, 14 Sep 2022 14:36:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 9KFyFOvmIWMOOQAAMHmgww (envelope-from ); Wed, 14 Sep 2022 14:36:27 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id DEB49A0680; Wed, 14 Sep 2022 16:36:26 +0200 (CEST) Date: Wed, 14 Sep 2022 16:36:26 +0200 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 Subject: Re: [PATCH -next 1/2] jbd2: fix potential buffer head reference count leak Message-ID: <20220914143626.gq7vpbibihcn6jng@quack3> References: <20220914100812.1414768-1-yebin10@huawei.com> <20220914100812.1414768-2-yebin10@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220914100812.1414768-2-yebin10@huawei.com> X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_SOFTFAIL, T_SCC_BODY_TEXT_LINE autolearn=no 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 Wed 14-09-22 18:08:11, Ye Bin wrote: > As in 'jbd2_fc_wait_bufs' if buffer isn't uptodate, will return -EIO without > update 'journal->j_fc_off'. But 'jbd2_fc_release_bufs' will release buffer head > from ‘j_fc_off - 1’ if 'bh' is NULL will terminal release which will lead to > buffer head buffer head reference count leak. > To solve above issue, update 'journal->j_fc_off' before return -EIO. > > Signed-off-by: Ye Bin Looks good. Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/jbd2/journal.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c > index 140b070471c0..1c833d8cb0fe 100644 > --- a/fs/jbd2/journal.c > +++ b/fs/jbd2/journal.c > @@ -925,8 +925,14 @@ int jbd2_fc_wait_bufs(journal_t *journal, int num_blks) > wait_on_buffer(bh); > put_bh(bh); > journal->j_fc_wbuf[i] = NULL; > - if (unlikely(!buffer_uptodate(bh))) > + /* > + * Update j_fc_off so jbd2_fc_release_bufs can release remain > + * buffer head. > + */ > + if (unlikely(!buffer_uptodate(bh))) { > + journal->j_fc_off = i; > return -EIO; > + } > } > > return 0; > -- > 2.31.1 > -- Jan Kara SUSE Labs, CR