From patchwork Sat Oct 22 07:19:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7304 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1093199wrr; Sat, 22 Oct 2022 00:56:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM72HYz89rsIsTWuJMEZ7u7CIwz3J6QmlcLBdnU1mk+UMbVMQ1osu0vMefM53jgga/+Y5peY X-Received: by 2002:a65:6cce:0:b0:439:49b5:48b8 with SMTP id g14-20020a656cce000000b0043949b548b8mr19714761pgw.514.1666425382422; Sat, 22 Oct 2022 00:56:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425382; cv=none; d=google.com; s=arc-20160816; b=1JlnXBZFAKN6cG5q0bfLdx2QiZ4YKHZqsZKi2bTy467IHsB2oChr0vEy2iQaflB6pT xCsmMyNnogEyctEaK1n9Deoa4XxANg6xwNBnPCAFeTfVJ3bZR6zxib9Gt1M1i1r3qDcO HLgt0OCezg+TlrvYiQthZkcCRO+n2UfyKZVCCwk8fwLdf8vdZS5z3RRwyIMipJWQo5ka pLwnoVck1qCUiPEcRA+AN7yeu9244+Ub2HiivkKrEGDBpqifCOsH5/1ZC869bQUXhzpU jQXkjP11HabkK6HfvlqAWfJpGxWSfDsrGVNmMxSNsPF0bhZCKPZtuoJb0ph6sPybL/jB oCcg== 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=LmzziNrKWYOAxOxdGrFlM4VUdGsJoAaaP7lHN+IzUuY=; b=YC5JN310q+0iJznuBjliXQaYU67A0BNmCbhphGBgyeJwJnCcwS7gMM477WWtKMVBUQ EACoi4z8Ky3u6sd6Z4MBAjb6QStqkQnsvo3pa6n0Jl767k9gJo+kt8FvQwmXoxj1RMM+ SC6ZzWLZa11+NKbOEdhtj2QCMtyp9IqrGsF2sfCU7qGXEpVrO/PCOnV/SJj7V8D81ncM f88HuXWI6pacL1VJxhoQAXFDzlU4LpCR+/HjdmXCFDw5TwpskYEvNvzDpmJ53Wn5Nx3q sybGXDWpwQWQLIXiQx3KJ5f/N47875ctan+8+IefntWRb64e6VK8/5fVNisyk/mFat8x /0Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1R+QU5Ql; 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 rm3-20020a17090b3ec300b0020dbb8f3695si2252718pjb.172.2022.10.22.00.56.10; Sat, 22 Oct 2022 00:56:22 -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=1R+QU5Ql; 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 S232180AbiJVHzx (ORCPT + 99 others); Sat, 22 Oct 2022 03:55:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231706AbiJVHwi (ORCPT ); Sat, 22 Oct 2022 03:52:38 -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 17560AC297; Sat, 22 Oct 2022 00:46:38 -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 6790FB82DF6; Sat, 22 Oct 2022 07:39:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A54DCC433D7; Sat, 22 Oct 2022 07:39:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424343; bh=51YjOXF7uUIpZAbLElBdbO797UG/6ZCUOY1Q/ovFfzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1R+QU5QlqQOdXaZlu3FqBCt0jAZPRtqQCDAqLYlkj2L+x9V/Li6IZQqGEZRASguKL W94tfRELVzXeAF2BpoWy4wfsIcQWQfdaRXEIPLRpZwjxwbWWdm1Pc9cigjN85fnFU9 dWSPmxEKKkneFjNS2/LeSrCf4QN2cEUYYdRgl8qs= 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.19 111/717] btrfs: set generation before calling btrfs_clean_tree_block in btrfs_init_new_buffer Date: Sat, 22 Oct 2022 09:19:50 +0200 Message-Id: <20221022072435.073175744@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?1747373662037942040?= X-GMAIL-MSGID: =?utf-8?q?1747373662037942040?= 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 @@ -4904,6 +4904,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