Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7703771rwn; Wed, 14 Sep 2022 03:11:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR5dwC+heVdoJB1d6BVbgGce4/PtxcSjcy39ctShmGGPAzWNWTIdj5ktEKFefLg+kFUd3SjQ X-Received: by 2002:a63:e4a:0:b0:434:dcca:cd63 with SMTP id 10-20020a630e4a000000b00434dccacd63mr30966092pgo.325.1663150279617; Wed, 14 Sep 2022 03:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663150279; cv=none; d=google.com; s=arc-20160816; b=e8yHDP1xjplG6UdBcGyPTgbvf9VzDYmLnl1EZxx9ycOFURPcIgTiTX3sqMo85rCITR 1jYN7stwrmmnSIHB553JupknCPslsAvgCyWLKSg5OpORdV1sALnUR6Egrx9Ou8u/iJ2n aGuafmZ/PiYeRnVq1k4Jttl82Xp5AHMyyLqwIohNbR8GyV5ZwY4QfhYNuvQhnfI2eSUW MJiwegZiDQ4TdHk5BoEETgoSZk3vGHMowNEIGGlNfEdF5F+lnuF0AUNGO8hF37XG34CQ NC3FGjdpZSHGLC83QTjQ2x6F27S4NzHFQNx1rVDPU4iFxQctOg+yi0XGHNCdG8ZEVHWk 9QEw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Y0qOt6xdyoa40YA6VEBhM6+zes8S7mjGLOerCQGUYfg=; b=FAcnHONbuWNYBENLV2/wK4IReTSqAJcWuw4FbAO2uVlhJNKQhqoQd08GH/n+UjYttB lCqN18utY0pSxLt5K20GDZsf0TY0W//rdO+aqwYj/kJ+YE62oGazdHVmHxnQn9er927D An+ewegI+hLRTAv8yQsPUBszRetOBM/+dNH3IzoCSyarYP/0u6iL4CdpZz7TP1EEcqQZ X3XFPzzQY3EKVTz80lZaPKNHPCrtQHiAyD9Gpj8PmfQUxMJTZ20rDmAu+oJldJF0IZ1+ i6sz6XWUymtTIPveL24UP1QByDUm8kml9I+9ujGJZhj7bq5QYQYr6Hwp2zONu5Fx54gT g36Q== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g2-20020a17090a7d0200b001fd7b0552b0si13963790pjl.37.2022.09.14.03.10.56; Wed, 14 Sep 2022 03:11:19 -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; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230244AbiINJ5g (ORCPT + 99 others); Wed, 14 Sep 2022 05:57:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbiINJ5Y (ORCPT ); Wed, 14 Sep 2022 05:57:24 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB7ED69F6A; Wed, 14 Sep 2022 02:57:19 -0700 (PDT) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MSFxj2yv8zNm7h; Wed, 14 Sep 2022 17:52:41 +0800 (CST) Received: from huawei.com (10.175.127.227) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 14 Sep 2022 17:57:16 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next 1/2] jbd2: fix potential buffer head reference count leak Date: Wed, 14 Sep 2022 18:08:11 +0800 Message-ID: <20220914100812.1414768-2-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220914100812.1414768-1-yebin10@huawei.com> References: <20220914100812.1414768-1-yebin10@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 --- 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