From patchwork Mon Oct 24 11:27:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp480160wru; Mon, 24 Oct 2022 07:20:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6NM+sVXn5Fzp8Bi1MPfkykzECiuUs/NMSWCnmUWk4qzVvo+l9Xpgxdxu8rHQcQUrPCu1T2 X-Received: by 2002:a05:6402:3546:b0:461:e63f:e870 with SMTP id f6-20020a056402354600b00461e63fe870mr2433186edd.405.1666621231484; Mon, 24 Oct 2022 07:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666621231; cv=none; d=google.com; s=arc-20160816; b=B9OH/dCNF28aVFLG2+l5A73WuL7NriGNN0fClAWmd6m6XrwIHyP6xMkvyvyD4TjWQu BAf/Z/MjyGWqShF7sLcO/ivRXDr+bW3fDopc2TrU+eFBLTQE9gc3oJa6f3LhtuvYGxV+ ZEydGJW5bFyAfeX3g4aZc8fnLejH6nbs5sCoOEAQOEyRTzlfuP2XocQdf2xQ5H39zII2 11YR1ZDA1Kaw1VuWKJK1pO8xtViQSEy69oQ65w2Z4z7WzZV5FBoFZzno8Rpk90pftyYp a666ZYH0ad/m/IiriEdHpX7Cz4j478bl0gCpyxsKOJrhwNmNimJb+XxcKokPINABdoN/ qdEg== 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=NLpFtZjKh9xmM+NQVW+yoVmQEKausRcT9CFZvxbXg1o=; b=vbX/4RHGvakSEyJGw9JLCDkg0TPnlC+uPS8DBk+Y2FYdtjDqqdlVma+aLiumQiqCu/ Qglrwmby2KQ+L9oxpP6MyK9GMbQ7/r6U7ZbkODB0yUqDNWuOHdqTahIMrEOfqwXunHx5 02rIRX4JS/eYaPydh5fh4a4Ju6dg4qCbu3BblkQG96Y0hLr1m+ltUWHuZt13Iwp9umig 3nCFXwRpH8kHkFJd0DdnlNK57yTZsuAB3dQII3+BWQiSVwlB4KYcxxgbKjni2aWqTU8N IV/QFm6ZSd/HS3VLFTE8xo6vDWrBWx+hAq8qHsxexInNIA4d0PfrBjaqx8Lh+7Sgff0l PpOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2iCpit5e; 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 qa30-20020a170907869e00b007a3fbdb825asi5613181ejc.707.2022.10.24.07.20.00; Mon, 24 Oct 2022 07:20:31 -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=2iCpit5e; 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 S232607AbiJXOLA (ORCPT + 99 others); Mon, 24 Oct 2022 10:11:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237354AbiJXOFa (ORCPT ); Mon, 24 Oct 2022 10:05:30 -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 249EC4C613; Mon, 24 Oct 2022 05:50:15 -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 88B86B817AE; Mon, 24 Oct 2022 12:36:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7EAEC433C1; Mon, 24 Oct 2022 12:36:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614989; bh=7nqqaqGTUrIsPz62h/ncaUsMRToIZJpG97d1QSfoPfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2iCpit5egUFX5pqJmGCSLhfNz/E22ZWAPlnMZqGw75M+KsJ0K5rjQXVUGLJySEeUj kzi1AeGRvOlzAI4krTmJcTVlyOWHapJJUDAZlL6iudW/yw/1UeJo5HZPr34d3pjq9u ItE+jiOumfwSCRIRR12QWzTfTMcuNjbSlRphNnsQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Tetsuo Handa , David Sterba Subject: [PATCH 5.15 080/530] btrfs: set generation before calling btrfs_clean_tree_block in btrfs_init_new_buffer Date: Mon, 24 Oct 2022 13:27:04 +0200 Message-Id: <20221024113048.630379815@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@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?1747579024250745174?= X-GMAIL-MSGID: =?utf-8?q?1747579024250745174?= From: Tetsuo Handa commit cbddcc4fa3443fe8cfb2ff8e210deb1f6a0eea38 upstream. syzbot is reporting uninit-value in btrfs_clean_tree_block() [1], for commit bc877d285ca3dba2 ("btrfs: Deduplicate extent_buffer init code") missed that btrfs_set_header_generation() in btrfs_init_new_buffer() must not be moved to after clean_tree_block() because clean_tree_block() is calling btrfs_header_generation() since commit 55c69072d6bd5be1 ("Btrfs: Fix extent_buffer usage when nodesize != leafsize"). Since memzero_extent_buffer() will reset "struct btrfs_header" part, we can't move btrfs_set_header_generation() to before memzero_extent_buffer(). Just re-add btrfs_set_header_generation() before btrfs_clean_tree_block(). Link: https://syzkaller.appspot.com/bug?extid=fba8e2116a12609b6c59 [1] Reported-by: syzbot Fixes: bc877d285ca3dba2 ("btrfs: Deduplicate extent_buffer init code") CC: stable@vger.kernel.org # 4.19+ Signed-off-by: Tetsuo Handa Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/extent-tree.c | 3 +++ 1 file changed, 3 insertions(+) --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4802,6 +4802,9 @@ btrfs_init_new_buffer(struct btrfs_trans !test_bit(BTRFS_ROOT_RESET_LOCKDEP_CLASS, &root->state)) lockdep_owner = BTRFS_FS_TREE_OBJECTID; + /* btrfs_clean_tree_block() accesses generation field. */ + btrfs_set_header_generation(buf, trans->transid); + /* * This needs to stay, because we could allocate a freed block from an * old tree into a new tree, so we need to make sure this new block is