From nobody Sat Oct 18 02:23:57 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14889C43219 for ; Wed, 19 Oct 2022 08:46:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230121AbiJSIqc (ORCPT ); Wed, 19 Oct 2022 04:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231310AbiJSIo5 (ORCPT ); Wed, 19 Oct 2022 04:44:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48D0B89831; Wed, 19 Oct 2022 01:43:47 -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 D30AB61808; Wed, 19 Oct 2022 08:43:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC937C433D6; Wed, 19 Oct 2022 08:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169020; bh=UglnOpSZq1r0SanQA9k9gKkp/CJxtHsfjA+Q6Eod9qg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qDNeQbmKKIum8sHJRd0vxVEL6V836ZW8TNuFxFb9KUqbMJZQK/Aj+HpDEZ2Pl3h02 g4MMO5AJc9SF/trqJz0vf/DwjeNqDHYNlHdyahmnlasQ2SPGgf1y7g8MeOPmx/zSgX vdH//FlgVLxISsmQk1XFbIBpbwrqWS4kcDk+E3v0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Ye Bin , Jan Kara , Theodore Tso Subject: [PATCH 6.0 131/862] jbd2: fix potential buffer head reference count leak Date: Wed, 19 Oct 2022 10:23:38 +0200 Message-Id: <20221019083255.772010170@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ye Bin commit e0d5fc7a6d80ac2406c7dfc6bb625201d0250a8a upstream. 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 =E2=80=98j_fc_off - 1=E2=80=99 if 'bh' is NULL will terminal release w= hich will lead to buffer head buffer head reference count leak. To solve above issue, update 'journal->j_fc_off' before return -EIO. Cc: stable@kernel.org Signed-off-by: Ye Bin Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220914100812.1414768-2-yebin10@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/jbd2/journal.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -925,8 +925,14 @@ int jbd2_fc_wait_bufs(journal_t *journal wait_on_buffer(bh); put_bh(bh); journal->j_fc_wbuf[i] =3D 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 =3D i; return -EIO; + } } =20 return 0;