Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp654699iog; Thu, 30 Jun 2022 07:46:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1shMlZdj8aGrBGq8LRIXNDxZyG2za/C7q6J/ZRtogwF4UpQXwhp/tnfciBqnBQxYP+K6RiQ X-Received: by 2002:a05:6402:51d1:b0:437:a22c:60da with SMTP id r17-20020a05640251d100b00437a22c60damr12257895edd.28.1656600388389; Thu, 30 Jun 2022 07:46:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656600388; cv=none; d=google.com; s=arc-20160816; b=OLWXQK7VYW/CqV3f1VGs2UU93pbD2qGIw1TqJLpqCWhWo1yZ9gPR5dVxPMPS0vBRMV 2plOot2AUorg4Bm7o4Zhej3DaR0nbRfV3iPdAacdcCXCdnsIbPy3fecoMBd+LNalwzXa stR/iMHPdClEuzu9x1D7mIrX6ko6EQKCD2rKACm6VmKjcWIFkrCrhUCUE/zR9eWh2J1d QQPxkK/SMVf8BOTG+8gpIlAzPtUCTzpNIJPsutg73vvPuUmQ5dF7t2EFsPrLh1/FkSss x0t3u3f0iWcJHp45xL6QWgt/MGX0JiUGH7QF1DZ0z8aulLnRmfio93FmePInka+h9ctU xDyg== 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=VftugY/2OYtqVfFg73CVlcKPbjjJfcEBaBU6RoRojdY=; b=MylQVJqH4CuuC28Ollxp34ApVsyN195Agy9+gEDxOh7spdCKTUPzVJHtV3q1yjcoSU Z6uhy6amfh1dqnLuAcJlf/PmeJog+7RseGzVJcAPKp3ClSVbsuhE6cxZMe5ODgnmxtG6 RpV1yDiwHw4ow8RenUcpHXkDQkWDD4sm9TgdJUAUxHS4MM+DL07nCkyGnXldrlADWbBD OQ+UORgriTuJwakumUq5z7lJDamWJ8KDCJM7nLo8/LMpKm/LpG5OaTbqAdV0I7dRWKiH 1fsy0lTohsHY62RdSrqlb6NuXqBouqc/0deDz1kRbSbhCZX2ASiGDBlnts+sKuUAXNZN caEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SsmcFZZM; 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 t9-20020a056402524900b004357f301eedsi27824490edd.615.2022.06.30.07.46.03; Thu, 30 Jun 2022 07:46:28 -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=SsmcFZZM; 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 S236771AbiF3OJL (ORCPT + 99 others); Thu, 30 Jun 2022 10:09:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236547AbiF3OG4 (ORCPT ); Thu, 30 Jun 2022 10:06:56 -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 A5BB76F342; Thu, 30 Jun 2022 06:54:20 -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 5CA916211A; Thu, 30 Jun 2022 13:54:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6137BC34115; Thu, 30 Jun 2022 13:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656597259; bh=qiyJ6ZqStaVBXRF5MPGLLNG1dYk/bGu+j7tVjqJ/dcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SsmcFZZM25AZy3jTIuTi/H+924QLi2hKHfl2bKVr4kihMGUyZP3A6/VVEW5O8PwGt P5CR2rWt4IJB97iP/IfyqxkyObDRTbSDO/h/xBPB+SdfkodaM2LTdxC1bkKnv9YWZ1 1qhTWsmgepddvLHDvR8trKLa12kgdou0DPByRSvU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yang Xu , "Darrick J. Wong" , Amir Goldstein Subject: [PATCH 5.10 08/12] xfs: Fix the free logic of state in xfs_attr_node_hasname Date: Thu, 30 Jun 2022 15:47:13 +0200 Message-Id: <20220630133230.938024271@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220630133230.676254336@linuxfoundation.org> References: <20220630133230.676254336@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 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,T_SCC_BODY_TEXT_LINE 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: Yang Xu commit a1de97fe296c52eafc6590a3506f4bbd44ecb19a upstream. When testing xfstests xfs/126 on lastest upstream kernel, it will hang on some machine. Adding a getxattr operation after xattr corrupted, I can reproduce it 100%. The deadlock as below: [983.923403] task:setfattr state:D stack: 0 pid:17639 ppid: 14687 flags:0x00000080 [ 983.923405] Call Trace: [ 983.923410] __schedule+0x2c4/0x700 [ 983.923412] schedule+0x37/0xa0 [ 983.923414] schedule_timeout+0x274/0x300 [ 983.923416] __down+0x9b/0xf0 [ 983.923451] ? xfs_buf_find.isra.29+0x3c8/0x5f0 [xfs] [ 983.923453] down+0x3b/0x50 [ 983.923471] xfs_buf_lock+0x33/0xf0 [xfs] [ 983.923490] xfs_buf_find.isra.29+0x3c8/0x5f0 [xfs] [ 983.923508] xfs_buf_get_map+0x4c/0x320 [xfs] [ 983.923525] xfs_buf_read_map+0x53/0x310 [xfs] [ 983.923541] ? xfs_da_read_buf+0xcf/0x120 [xfs] [ 983.923560] xfs_trans_read_buf_map+0x1cf/0x360 [xfs] [ 983.923575] ? xfs_da_read_buf+0xcf/0x120 [xfs] [ 983.923590] xfs_da_read_buf+0xcf/0x120 [xfs] [ 983.923606] xfs_da3_node_read+0x1f/0x40 [xfs] [ 983.923621] xfs_da3_node_lookup_int+0x69/0x4a0 [xfs] [ 983.923624] ? kmem_cache_alloc+0x12e/0x270 [ 983.923637] xfs_attr_node_hasname+0x6e/0xa0 [xfs] [ 983.923651] xfs_has_attr+0x6e/0xd0 [xfs] [ 983.923664] xfs_attr_set+0x273/0x320 [xfs] [ 983.923683] xfs_xattr_set+0x87/0xd0 [xfs] [ 983.923686] __vfs_removexattr+0x4d/0x60 [ 983.923688] __vfs_removexattr_locked+0xac/0x130 [ 983.923689] vfs_removexattr+0x4e/0xf0 [ 983.923690] removexattr+0x4d/0x80 [ 983.923693] ? __check_object_size+0xa8/0x16b [ 983.923695] ? strncpy_from_user+0x47/0x1a0 [ 983.923696] ? getname_flags+0x6a/0x1e0 [ 983.923697] ? _cond_resched+0x15/0x30 [ 983.923699] ? __sb_start_write+0x1e/0x70 [ 983.923700] ? mnt_want_write+0x28/0x50 [ 983.923701] path_removexattr+0x9b/0xb0 [ 983.923702] __x64_sys_removexattr+0x17/0x20 [ 983.923704] do_syscall_64+0x5b/0x1a0 [ 983.923705] entry_SYSCALL_64_after_hwframe+0x65/0xca [ 983.923707] RIP: 0033:0x7f080f10ee1b When getxattr calls xfs_attr_node_get function, xfs_da3_node_lookup_int fails with EFSCORRUPTED in xfs_attr_node_hasname because we have use blocktrash to random it in xfs/126. So it free state in internal and xfs_attr_node_get doesn't do xfs_buf_trans release job. Then subsequent removexattr will hang because of it. This bug was introduced by kernel commit 07120f1abdff ("xfs: Add xfs_has_attr and subroutines"). It adds xfs_attr_node_hasname helper and said caller will be responsible for freeing the state in this case. But xfs_attr_node_hasname will free state itself instead of caller if xfs_da3_node_lookup_int fails. Fix this bug by moving the step of free state into caller. [amir: this text from original commit is not relevant for 5.10 backport: Also, use "goto error/out" instead of returning error directly in xfs_attr_node_addname_find_attr and xfs_attr_node_removename_setup function because we should free state ourselves. ] Fixes: 07120f1abdff ("xfs: Add xfs_has_attr and subroutines") Signed-off-by: Yang Xu Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Amir Goldstein Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman --- fs/xfs/libxfs/xfs_attr.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -876,21 +876,18 @@ xfs_attr_node_hasname( state = xfs_da_state_alloc(args); if (statep != NULL) - *statep = NULL; + *statep = state; /* * Search to see if name exists, and get back a pointer to it. */ error = xfs_da3_node_lookup_int(state, &retval); - if (error) { - xfs_da_state_free(state); - return error; - } + if (error) + retval = error; - if (statep != NULL) - *statep = state; - else + if (!statep) xfs_da_state_free(state); + return retval; }