Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3881920rwi; Sat, 22 Oct 2022 01:29:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Fbqa2biXq1maJDUyxgVuLRbSGCdhR5Px1TZXo9Vo6ApZKkDPm6LHxeU1JiYgzaaTzKAs6 X-Received: by 2002:a17:906:8a55:b0:78d:b6db:a2d4 with SMTP id gx21-20020a1709068a5500b0078db6dba2d4mr19124988ejc.82.1666427351939; Sat, 22 Oct 2022 01:29:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427351; cv=none; d=google.com; s=arc-20160816; b=bsG77xbGbYq0wrkrPIMMpcfG4uP0Irie+YsQkaZzm2wdwnP5VeCJZXO14vsSpsyvKt e1YaZsDHjlqAflHLf1Y10z4x/H/L7owLVSuvMQLhb1ev8D7TYULojiyrdcllWJnt3B9w h6BTwEm0G4242Y2wDHQplXwblorQ+oNNOGBdwPM+Fvy+iKDOW6q/PCrCpNlo6Nl5gMt9 mkML3NI1USmKG1dm+HaJd19UWlFp8Fmz/5rDqUTAqDrV5nSJe6yUm4OdJOK60aNb4O8B XJoMCR030a8GZNJJ6M3JCUYsmnHo2+ZqB1IJHogzS60sGoBMS3007Da5qtyX8KWnVklF 7ZbQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a50ab03000000b00443e3fe60a0si18760074edc.622.2022.10.22.01.28.46; Sat, 22 Oct 2022 01:29:11 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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