From patchwork Sat Oct 22 07:19:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7240 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1091230wrr; Sat, 22 Oct 2022 00:49:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM61hmE0IkiSIAHQSCXuBGxboUQzQvVhJgfOZvRnErTxMVui2YfQSvO0R7wW2M0h0X1KlBLc X-Received: by 2002:a05:6a00:1488:b0:563:9d96:660f with SMTP id v8-20020a056a00148800b005639d96660fmr23252247pfu.0.1666424994914; Sat, 22 Oct 2022 00:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424994; cv=none; d=google.com; s=arc-20160816; b=yT8q2xwqr5ugkkjzZ4d4D4l0G7jaNmYnDI1jL/H1RZAMSRCT0UXY4xGD+1kbeERmOz 3iLAeCcqzL3MvkZgwBVcOIjxED4XFYMEj/9AZfduUt0fjs8uyHq5+5ztKkjBo9GVj9i1 xl5BtaaKqKXbYlU2LFZ1CqSnxEaxPz73fIIJEecR359LuxV9zvDoEPBsFPgGTOSDIDOH Ljl3lq5RutTQLxOCQSnxjeRxi4QJG8Xu6lKkiR/UnMGlOhTHOe17trdrZnPjtFHw/YGj 3bvcPvUllM4DitHjbJSolQy8fB6UsLIYDf1Sqo10BevHYdjiZWqptxce/0ZaMVl9CkPb tiCg== 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=tiuMrmZuJFU9VY7nKf8ziLvyHCU1+6c2DpjDW1iAi/Q=; b=lZwbrjvY/WwTWzsOm8PxBYs9/2/9LRwZqpd11jhPw2Jnq/0jwMek4C+6Xvv7KRWrku gjRHwWV2VnHFg6MlpxkB67aOQ3eUSh9Qjdll6bZovViHUS4tHbKOF5h6oYAbq+rugetj 3NHUCXLiDeKzp7UjNPZYIirlQcH8lkCh0kO2QjkXq/W+yFWaZ8BEwHtN5jNn8v70rve1 X+RlQwm6QQ5APJAXXm4/fMv/lvKwqSmc73FSLL2XWkyp98IKctNm3ZWKhhxP/ZAi+g+8 ReqJ//VBokFCc4zjuwryRbiE9dNpzdSg3hY5uM7Fh5TcLVyltPfTGEQpksy1SZeSY3rm r0tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mjxEVSTR; 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 d8-20020a056a0024c800b005257035371bsi30023929pfv.108.2022.10.22.00.49.41; Sat, 22 Oct 2022 00:49:54 -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=mjxEVSTR; 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 S231633AbiJVHsr (ORCPT + 99 others); Sat, 22 Oct 2022 03:48:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231552AbiJVHsM (ORCPT ); Sat, 22 Oct 2022 03:48:12 -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 E7B8DCD5DC; Sat, 22 Oct 2022 00:45: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 dfw.source.kernel.org (Postfix) with ESMTPS id 9D8A560B24; Sat, 22 Oct 2022 07:39:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0037C433C1; Sat, 22 Oct 2022 07:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424370; bh=AEncgBZqnzHKq0T0S/CKCWLF1y28DmqfUPSmO+kiz2U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mjxEVSTRQcHRN8JzjYmchhqtLKaTUB8nE3DlzCBYXxtGQi/3tNY2hYgN/3uUR/m5l O6x4xKQoZzgHkTr50FFj7f1J/4fCP7X2M5cjZhJjzu3vBqihhsOyk2w6i/3t6FUeIc Fi0/Tnuh/vtLmbjzp2LMt8OKAHALFqN4yeszTZc0= 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 120/717] jbd2: fix potential use-after-free in jbd2_fc_wait_bufs Date: Sat, 22 Oct 2022 09:19:59 +0200 Message-Id: <20221022072436.737549980@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?1747373255487510343?= X-GMAIL-MSGID: =?utf-8?q?1747373255487510343?= 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 @@ -926,16 +926,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;