From patchwork Mon Oct 24 11:27:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9692 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp543876wru; Mon, 24 Oct 2022 09:30:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7lzDLmvoE7hEfUGWKufdU4FgEQvE2aPGSRYo2dB9lnWiyGa2oc1qFZJN0u7QfBXL2NFpqI X-Received: by 2002:aa7:d348:0:b0:45b:8ae3:ee3d with SMTP id m8-20020aa7d348000000b0045b8ae3ee3dmr31474745edr.428.1666629055456; Mon, 24 Oct 2022 09:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666629055; cv=none; d=google.com; s=arc-20160816; b=Fuq3TrgVDZ/M04qdZvTBMAmb57aSdhg+2lwpw9140WEB1nK5xgKJBIOCoYr7PxcWaV 7E3JZs/YlKwjBG6lsyT/sIZ5NfLfnEJqNW5LmTsENINLMLCz2c0TJO8dWv5iKil+Zeud gAHw+Y7KvaYTBjTBZA/jk8ifTaJeLa1kyCChv00DELI8KMZS1SVt7Xuf7odFtEzYRVpJ S7yNTaGA1u874B4vI+Svy3Mrfldx55Xyy+sL1kmgjhY7I+BpqircvbcjR9lLp6CxiZHE aDxVvVFYscVizyZykIUmwmx4XJyeoHHP0SLNvbOGYypnnoTLJ0FD7o6uSVcHG6Ad+tEu /5gw== 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=ZpBr4CKsIGRY7mj69SUu+FSlaC/44f14FZMEqLngs1Q=; b=yQw7euxGlbiWdcn8g4zsMOda+rd+blcbQoQ5PwwGT3HJN6+/poBHzXYnDnS8axUmce SXGZ5Fkead1Pv1PAqfd7K5XWct88Bam967mGhK974rwauDrhj0ZYuAOuMbVDBID9JfX8 +F6F7ubhRfXANIE91iLtCoT1bheBQueK/OBnk3Djve+RmczdgUBSzkKOdZcJFJKywqBY ndC7UCOnYIUXrFT3CNZJ+qDR/WLghNy8dZmwHTJcgvQdtf4R/ShalPrx7C/3ulNY+/ac /zFGIOd0dgwcEKx/0RPNSIJRc5jFtGTziRNiyQFYNn/7Y/OkEKO7QE3gAZOHtaWCQ4Mo JA7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MnQfBGzA; 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 g16-20020a50ee10000000b0045d3e06e4d5si127900eds.389.2022.10.24.09.30.32; Mon, 24 Oct 2022 09:30:55 -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=MnQfBGzA; 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 S234035AbiJXQQE (ORCPT + 99 others); Mon, 24 Oct 2022 12:16:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234271AbiJXQOb (ORCPT ); Mon, 24 Oct 2022 12:14:31 -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 AE29F127BEC; Mon, 24 Oct 2022 08:02:11 -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 76C36B81627; Mon, 24 Oct 2022 12:18:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAFF8C433D6; Mon, 24 Oct 2022 12:18:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613903; bh=RHgpOY34xrHo3qmUkhEOiFA/j5Y4V8+PQcbcKFKYUqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MnQfBGzA7jOq6+8f0iRoObSl/CnLHTAB8XDa+uERDZojAthdO8rG5IgFSdDIolylT 8ScLnzqA/Z2x6LOjE+hIF+tV2zp+lfVgrjRkk3980mOXm7N+Q2EPCR/JtPAF4YLxR4 rCjUUgNiBXIq9vs2DalK029JaEFMmJNWwC787bGI= 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.10 058/390] jbd2: fix potential use-after-free in jbd2_fc_wait_bufs Date: Mon, 24 Oct 2022 13:27:35 +0200 Message-Id: <20221024113025.110853995@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747587228449117629?= X-GMAIL-MSGID: =?utf-8?q?1747587228449117629?= 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 @@ -924,16 +924,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;