From patchwork Wed Oct 19 08:23:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4587 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp206005wrs; Wed, 19 Oct 2022 01:51:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Vyv5WM1rZsrswjJErMYczB4wRskfq12axyimYwKw68UrCDTKyHLOZDVUQxBb7/XdyAR9B X-Received: by 2002:a17:90b:1b51:b0:20d:8594:bd5f with SMTP id nv17-20020a17090b1b5100b0020d8594bd5fmr43273749pjb.125.1666169473678; Wed, 19 Oct 2022 01:51:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169473; cv=none; d=google.com; s=arc-20160816; b=dvSMaSsKNne5G+SgUbaoEIdtCFolJym6y45J9ImHoVv1PNtTqb0jBzQ/B5Xhjqhs4x O7pruVw+zZBgYQBCE19ViEUGBhaiKEegcNZewk6z7YZ1+JmSvLBAKx1FAIEDQ1nEvGP/ 2eX5GTdJJzM9uW1FiIk+8ifgQ8eAC5JT88jBB0KDpiwXe6CbNSTY1m1rZws9WxiEd7t+ rsaBtS76kLA2ffIeQWrrcaHKI8V3WmVYlAVP87omNiDfnyEIf42KNPrtG1qoXPq3HrtD FQhbZ/gXR2ngEvHeNWYdZ92cX8Dp2dlO6KAEg+4tpWurg9ow0JjSpo3KnCR5CQp4WI/I 61CA== 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=7/ZrJfrYDOzMLpvxbP//NZ843+/0tZH0bNPHEYE8mLI=; b=upryy47pSB4ZTbWj3h+Y6jkYlwgoHOKKd7OR+XaA1PSJKEaQwyBKUafUSlbXb19De0 iDNI42exQRjY2JeFywiMH5Vb+t879+98tPpPJG9ZNRxlmzi4TSmM0fgRT9ZsllzNqO5L Spc0tmWT1CFGkzHE7bbZXpRdLTH23+ThyJPjMlUgsX6PwO3gxMlftzzYBil4F01OIw39 YfcDS3LFj4HpsbdDS6I52dGjQCKXRD4feT6dYGFjXxK7hRPJFccVJ3eltywWtreT7RKg 8U8pO6+23Zh72ObmxgeTUUWPU+3VpQ87K0yDCtIhpd8JFMAv0AltRDFhRiJHlSp+2oWu ynZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kzKM3bfk; 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 g20-20020a056a000b9400b00541505b05dbsi19054751pfj.31.2022.10.19.01.51.00; Wed, 19 Oct 2022 01:51:13 -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=kzKM3bfk; 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 S231481AbiJSIus (ORCPT + 99 others); Wed, 19 Oct 2022 04:50:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231477AbiJSIsq (ORCPT ); Wed, 19 Oct 2022 04:48:46 -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 8F1EC83F0E; Wed, 19 Oct 2022 01:46:41 -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 812E7B822F0; Wed, 19 Oct 2022 08:43:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC762C433D6; Wed, 19 Oct 2022 08:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168990; bh=sWV6aA1ibKl9WZX924pVaH+AyI1RL2R7xKvocaqtYYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kzKM3bfkdYBZOOrFH9BeTCUj7WbRpm+IEe1L39Awpqaat8muZCmcnO1ilKUJcpvNn PWXtPKH1kCYU9wudPvMly9jqKVHvR1qBl7kMkIg6mAmjVLWhyTe7DhB55CxuInxWon 6KiEPnl7cMGWA8KOlVEJUQ9V4xWmCfFSSYCbhxig= 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 6.0 122/862] btrfs: set generation before calling btrfs_clean_tree_block in btrfs_init_new_buffer Date: Wed, 19 Oct 2022 10:23:29 +0200 Message-Id: <20221019083255.348705972@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747105321887532562?= X-GMAIL-MSGID: =?utf-8?q?1747105321887532562?= 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 @@ -4888,6 +4888,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