From patchwork Sat Oct 22 07:19:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1104955wrr; Sat, 22 Oct 2022 01:33:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5F+bBmhizrplZv4Nojdmypxw8+/sOS7+u1aP2UqfxwPmkk/bDYJWo9R07sXtHSa9IzKOzG X-Received: by 2002:a17:907:2bec:b0:78d:8bd0:61ee with SMTP id gv44-20020a1709072bec00b0078d8bd061eemr19772789ejc.669.1666427626736; Sat, 22 Oct 2022 01:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427626; cv=none; d=google.com; s=arc-20160816; b=zAHGYiRsW96BIA/GRBFUsWu4VjbxSwHgyFn5Pb6NE6vuFuR1zO2PtbZoutgKWoFNYF eadxOCnCUgqpIfy47lRtRIScfblFEXiVR4ogX3QgXBcbIMfG6/VuoYHh+oQNsQ2CP0ap HLLq4INiyn+Uq0VwvatV8tVGsYfCQME13vmgsQY5ZQxlZyl+KXkyD9R+NB/JupXZRviC Lxc8V29a/0f6CDxDfIUBrZbV7wfZDfYWdYa/gd1Vlr0Ghv0r5VKDdUciRW77m1Bi5kk7 /XtrmZlhJeuNIUUb0VgRDS9r9eHg7D41eJXLnjoHolN9ud9CaTDctSPP4bZbhl2iC3m1 CSnQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RNagROcgDu/dojmhtOodwK0ZsOBRZMRPNP/q9GWLOQE=; b=ktHdrEHAef5ljSnOkwDQEwHvycPE5s+Nv5gu05VY4lK8pXcafL/ESqfmYRB71ZnWAs NzN257p+8zcRo5Omp47MPZvEJNAxJtBORrLOilMpYLjD3ZXntLYfrpPBDsihKjKXTAEJ mkLGARZpfL3ytUYejX/0D+pHTtqVwxKITTUjUPtHAYu08t/xh3tXYaiY1AYU3SoD/TUc ln6w8blJxq1sRRfVRVhkhFTfRLDlUHPsAtkmHveIXQwc0D/qhcbT8jqBeI3d4pGDigUu HfCuC1UGi4q6Ezg8LeI8wyhD9O9edZW6rZKNp5YhVK4ClL1UdwJa1N8QLpK/Mh+MixEc 04Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p2242QZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb22-20020a170907961600b0072fc714c92fsi23793233ejc.902.2022.10.22.01.33.16; Sat, 22 Oct 2022 01:33:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=p2242QZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230100AbiJVIR5 (ORCPT + 99 others); Sat, 22 Oct 2022 04:17:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234025AbiJVIP5 (ORCPT ); Sat, 22 Oct 2022 04:15:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B5622DA77C; Sat, 22 Oct 2022 00:56:41 -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 ams.source.kernel.org (Postfix) with ESMTPS id 94C4CB82DFF; Sat, 22 Oct 2022 07:39:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 065A4C433C1; Sat, 22 Oct 2022 07:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424367; bh=YyovKfh64J2vVKnjYCaTUDTLnH484OFH/4MnSywZ+Mo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p2242QZP4WJzOPLMT5AFAFHsbgA7MrV+TrPTlD6QFEYOicqW2DNKwJ6R0iBaZV6wy 0qO0qYJCSXTluvk+0aRNXNXtxb4i4iXryedgfkqAPDPBVBGqibu1kznTLG7TArrv1V R8gX6umqorGjdiwkCLe6JwCGY9RnhH0UkAan/qh8= 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 5.19 119/717] jbd2: fix potential buffer head reference count leak Date: Sat, 22 Oct 2022 09:19:58 +0200 Message-Id: <20221022072436.531163324@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747376015029135457?= X-GMAIL-MSGID: =?utf-8?q?1747376015029135457?= 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 ‘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. 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 @@ -928,8 +928,14 @@ int jbd2_fc_wait_bufs(journal_t *journal 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;