Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp994490rwi; Wed, 19 Oct 2022 05:35:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5MAJzC5e/7a4XtLflAyjJUNZkAzXi26+MiGBKgZYPjdPWm6U/sd7VeQjznYcZtLeSj1nud X-Received: by 2002:a05:6402:1c1c:b0:45c:35b2:2a98 with SMTP id ck28-20020a0564021c1c00b0045c35b22a98mr7432042edb.182.1666182958488; Wed, 19 Oct 2022 05:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666182958; cv=none; d=google.com; s=arc-20160816; b=SXmzJ28Ute621BxGwq/2coSL5ZvmMsVsjfqjM0NHU5QqbASEO1C/hBnLd1NSrcjdkM nJ7QtFal/95leZoJr/r+avFTv7Vmr3Ge0wO82DOnvNueX8xv1Lak4HmxJstaFGzFq9Mk IAviQPOCSFJnYClfPS0emhxCR8ztBFiybK+RpJlSoAWsu2pbTMIdH7W1O6EYdR4VOxPI faFMNgdYEoPL8aGYxlN651YYPkp6TOv8Ok6DkDJboIFHbvAAgLBCmXhA5hp5DOJd1yyG UocJdgGHHu3lobX4HAFWMQmkaWoRvEFid8G0Nm+GdqkTywUQiRxXMsL2zf7i1Mt10v4q QBFQ== 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 Return-Path: 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.35.32; Wed, 19 Oct 2022 05:35:58 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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;