From patchwork Wed Oct 19 08:23:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5373 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp300804wrs; Wed, 19 Oct 2022 05:35:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7zaz/lGareI+0fd0JQsS29oidRKRj8uIFQdguiR+4l1nhvzChVBZYm2TU1Jo4hWxFnWdQo X-Received: by 2002:a17:907:6d0d:b0:78d:f5a9:fe81 with SMTP id sa13-20020a1709076d0d00b0078df5a9fe81mr6551542ejc.628.1666182907033; Wed, 19 Oct 2022 05:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666182907; cv=none; d=google.com; s=arc-20160816; b=UnSipBoNYx8675nyMWXaHyUyjaaYxzKaG4T1DqN/Ak/VIwMB4pL/IDvliP33qOtMeJ iGRm+knXmeieR0rhVtcM1JJGNXyOQpHYZzL9/TbD45K0WsJx2WlZOyuTupmJB6ugmmzd 0BEec+uyu1vno3eGKVBPSbTtoJvxPssV1tN6qy7J1/3ve2ukeegliuftRGth6ZmBW+YU JfGvnhr6pPNC2h2jUzqe/Yo9HACOuAs+RCiNkLs5qacKDxGAzYKXqrXfrlh4J8h/wP/7 bYZWF3NWKfCz8BRjmlbAEtMRtT3OU2VA6PCh139ldunVsD2sjxT0V+gYmLbxgFCU+AeP krbw== 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=YLt3YcoiNK1k+Qh0bxEW2wzhN0zgJoG3OUWXiiLqoAQ=; b=J7wSpJdMgU/Xsy4Qr9QLKnmu7PsrwxUb+bFP/pmAqMRkj0Fkn8D1Vmm95McpYXZ+bT knzjeCEsnQCkEJ+qVJ3WwYwjhrWGawmaFqI+ZJMIXRb1wJ4BEFHVWZBwIJdkuN6U51HM //vpxNnKWi0eEPkxPSUL9MNUu2xQs4XQUSUme1cfBl3r3oHEnQBjnLkQHWdS47ag/RJL b/prt4wrKvjcc/VK0WP+ApRTPSiBOtBbIjmCfjuGJKBylCdXlJwLYJkhK5U5imcH1V1h sDkzMpbSlt0lI9Bovg2ctcr0YaAwwTfbX2kAniQOFGAv0JPeqFGWut7u2h3FzD8Hir6i kFvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=abzndfw2; 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 r17-20020a170906a21100b0077547abf08fsi14329435ejy.169.2022.10.19.05.34.37; Wed, 19 Oct 2022 05:35:07 -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=abzndfw2; 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 S231361AbiJSMV2 (ORCPT + 99 others); Wed, 19 Oct 2022 08:21:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232933AbiJSMUU (ORCPT ); Wed, 19 Oct 2022 08:20:20 -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 1DCBA17D85B; Wed, 19 Oct 2022 04:55:37 -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 683C3B822F1; Wed, 19 Oct 2022 08:43:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD6B8C433D6; Wed, 19 Oct 2022 08:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169023; bh=pcrYp1tEOB1siR5JTPtu4gKz+NhgtlicHrG+H9C3vQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=abzndfw2GbhjON9K5ONmisf2nU3fG87HywNVvQPSmfUtfR+8Mdf3UFBSlONELUIs+ 2spg9qIosSrhhFVrC8xd8agzHoYny/yKbkinK/aTOPYKBVtnCvwEsKSzNUxbQg8mBa LqWpkJtN32qtAzp52e2C053M0Zq+O8o4sJQkXUPI= 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 132/862] jbd2: fix potential use-after-free in jbd2_fc_wait_bufs Date: Wed, 19 Oct 2022 10:23:39 +0200 Message-Id: <20221019083255.811132767@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 X-Spam-Status: No, score=-7.4 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?1747119407918307861?= X-GMAIL-MSGID: =?utf-8?q?1747119407918307861?= From: Ye Bin commit 243d1a5d505d0b0460c9af0ad56ed4a56ef0bebd upstream. In 'jbd2_fc_wait_bufs' use 'bh' after put buffer head reference count which may lead to use-after-free. So judge buffer if uptodate before put buffer head reference count. Cc: stable@kernel.org Signed-off-by: Ye Bin Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220914100812.1414768-3-yebin10@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/jbd2/journal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -923,16 +923,16 @@ int jbd2_fc_wait_bufs(journal_t *journal for (i = j_fc_off - 1; i >= j_fc_off - num_blks; i--) { bh = journal->j_fc_wbuf[i]; wait_on_buffer(bh); - put_bh(bh); - journal->j_fc_wbuf[i] = NULL; /* * Update j_fc_off so jbd2_fc_release_bufs can release remain * buffer head. */ if (unlikely(!buffer_uptodate(bh))) { - journal->j_fc_off = i; + journal->j_fc_off = i + 1; return -EIO; } + put_bh(bh); + journal->j_fc_wbuf[i] = NULL; } return 0;