OpenCloudOS-Kernel/fs/xfs/libxfs
Yang Xu a1de97fe29 xfs: Fix the free logic of state in xfs_attr_node_hasname
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 07120f1abd ("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.

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: 07120f1abd ("xfs: Add xfs_has_attr and subroutines")
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2021-11-24 10:06:02 -08:00
..
xfs_ag.c xfs: #ifdef out perag code for userspace 2021-11-10 09:37:38 -08:00
xfs_ag.h xfs: #ifdef out perag code for userspace 2021-11-10 09:37:38 -08:00
xfs_ag_resv.c xfs: compute maximum AG btree height for critical reservation calculation 2021-10-19 11:45:15 -07:00
xfs_ag_resv.h xfs: move perag structure and setup to libxfs/xfs_ag.[ch] 2021-06-02 10:48:24 +10:00
xfs_alloc.c xfs: reduce the size of struct xfs_extent_free_item 2021-10-22 16:04:36 -07:00
xfs_alloc.h xfs: reduce the size of struct xfs_extent_free_item 2021-10-22 16:04:36 -07:00
xfs_alloc_btree.c xfs: remove kmem_zone typedef 2021-10-22 16:00:31 -07:00
xfs_alloc_btree.h xfs: use separate btree cursor cache for each btree type 2021-10-19 11:45:16 -07:00
xfs_attr.c xfs: Fix the free logic of state in xfs_attr_node_hasname 2021-11-24 10:06:02 -08:00
xfs_attr.h xfs: rename xfs_has_attr() 2021-08-19 10:07:11 -07:00
xfs_attr_leaf.c xfs: rename _zone variables to _cache 2021-10-22 16:04:20 -07:00
xfs_attr_leaf.h xfs: Make attr name schemes consistent 2021-06-09 09:34:05 -07:00
xfs_attr_remote.c xfs: convert bp->b_bn references to xfs_buf_daddr() 2021-08-19 10:07:15 -07:00
xfs_attr_remote.h xfs: Rename __xfs_attr_rmtval_remove 2021-08-11 09:12:45 -07:00
xfs_attr_sf.h xfs: Convert xfs_attr_sf macros to inline functions 2020-09-15 20:52:42 -07:00
xfs_bit.c xfs: fix missing header includes 2019-11-07 13:00:53 -08:00
xfs_bit.h xfs: Use the correct style for SPDX License Identifier 2020-05-13 15:32:45 -07:00
xfs_bmap.c xfs: rename xfs_bmap_add_free to xfs_free_extent_later 2021-10-22 16:04:36 -07:00
xfs_bmap.h xfs: rename xfs_bmap_add_free to xfs_free_extent_later 2021-10-22 16:04:36 -07:00
xfs_bmap_btree.c xfs: rename xfs_bmap_add_free to xfs_free_extent_later 2021-10-22 16:04:36 -07:00
xfs_bmap_btree.h xfs: use separate btree cursor cache for each btree type 2021-10-19 11:45:16 -07:00
xfs_btree.c xfs: sync xfs_btree_split macros with userspace libxfs 2021-11-11 09:13:39 -08:00
xfs_btree.h xfs: remove kmem_zone typedef 2021-10-22 16:00:31 -07:00
xfs_btree_staging.c xfs: encode the max btree height in the cursor 2021-10-19 11:45:15 -07:00
xfs_btree_staging.h xfs: xfs_btree_staging.h: delete duplicated words 2020-07-28 20:24:14 -07:00
xfs_cksum.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
xfs_da_btree.c xfs: use swap() to make dabtree code cleaner 2021-11-08 11:23:25 -08:00
xfs_da_btree.h xfs: rename _zone variables to _cache 2021-10-22 16:04:20 -07:00
xfs_da_format.h xfs: replace xfs_sb_version checks with feature flag checks 2021-08-19 10:07:12 -07:00
xfs_defer.c xfs: rename xfs_bmap_add_free to xfs_free_extent_later 2021-10-22 16:04:36 -07:00
xfs_defer.h xfs: create slab caches for frequently-used deferred items 2021-10-22 16:04:36 -07:00
xfs_dir2.c xfs: convert xfs_sb_version_has checks to use mount features 2021-08-19 10:07:14 -07:00
xfs_dir2.h xfs: fix an ABBA deadlock in xfs_rename 2021-01-22 16:54:43 -08:00
xfs_dir2_block.c xfs: convert bp->b_bn references to xfs_buf_daddr() 2021-08-19 10:07:15 -07:00
xfs_dir2_data.c xfs: convert bp->b_bn references to xfs_buf_daddr() 2021-08-19 10:07:15 -07:00
xfs_dir2_leaf.c xfs: convert bp->b_bn references to xfs_buf_daddr() 2021-08-19 10:07:15 -07:00
xfs_dir2_node.c xfs: convert bp->b_bn references to xfs_buf_daddr() 2021-08-19 10:07:15 -07:00
xfs_dir2_priv.h xfs: convert xfs_sb_version_has checks to use mount features 2021-08-19 10:07:14 -07:00
xfs_dir2_sf.c xfs: convert xfs_sb_version_has checks to use mount features 2021-08-19 10:07:14 -07:00
xfs_dquot_buf.c xfs: remove the xfs_dqblk_t typedef 2021-10-14 09:19:33 -07:00
xfs_errortag.h xfs: add error injection for per-AG resv failure 2021-03-25 16:47:53 -07:00
xfs_format.h xfs: remove the xfs_dqblk_t typedef 2021-10-14 09:19:33 -07:00
xfs_fs.h xfs: compute absolute maximum nlevels for each btree type 2021-10-19 11:45:16 -07:00
xfs_health.h xfs: Use the correct style for SPDX License Identifier 2020-05-13 15:32:45 -07:00
xfs_ialloc.c xfs: rename xfs_bmap_add_free to xfs_free_extent_later 2021-10-22 16:04:36 -07:00
xfs_ialloc.h xfs: make the record pointer passed to query_range functions const 2021-08-18 18:46:01 -07:00
xfs_ialloc_btree.c xfs: remove kmem_zone typedef 2021-10-22 16:00:31 -07:00
xfs_ialloc_btree.h xfs: use separate btree cursor cache for each btree type 2021-10-19 11:45:16 -07:00
xfs_iext_tree.c xfs: prevent metadata files from being inactivated 2021-03-25 16:47:50 -07:00
xfs_inode_buf.c xfs: remove the xfs_dinode_t typedef 2021-10-14 09:19:33 -07:00
xfs_inode_buf.h xfs: kill xfs_sb_version_has_v3inode() 2021-08-19 10:07:14 -07:00
xfs_inode_fork.c xfs: rename _zone variables to _cache 2021-10-22 16:04:20 -07:00
xfs_inode_fork.h xfs: rename _zone variables to _cache 2021-10-22 16:04:20 -07:00
xfs_log_format.h xfs: convert xfs_sb_version_has checks to use mount features 2021-08-19 10:07:14 -07:00
xfs_log_recover.h xfs: refactor xfs_iget calls from log intent recovery 2021-08-09 15:57:59 -07:00
xfs_log_rlimit.c xfs: replace xfs_sb_version checks with feature flag checks 2021-08-19 10:07:12 -07:00
xfs_quota_defs.h xfs: remove the active vs running quota differentiation 2021-08-06 11:05:37 -07:00
xfs_refcount.c xfs: remove unused parameter from refcount code 2021-10-22 16:04:36 -07:00
xfs_refcount.h xfs: create slab caches for frequently-used deferred items 2021-10-22 16:04:36 -07:00
xfs_refcount_btree.c xfs: remove kmem_zone typedef 2021-10-22 16:00:31 -07:00
xfs_refcount_btree.h xfs: use separate btree cursor cache for each btree type 2021-10-19 11:45:16 -07:00
xfs_rmap.c xfs: create slab caches for frequently-used deferred items 2021-10-22 16:04:36 -07:00
xfs_rmap.h xfs: create slab caches for frequently-used deferred items 2021-10-22 16:04:36 -07:00
xfs_rmap_btree.c xfs: remove kmem_zone typedef 2021-10-22 16:00:31 -07:00
xfs_rmap_btree.h xfs: use separate btree cursor cache for each btree type 2021-10-19 11:45:16 -07:00
xfs_rtbitmap.c xfs: make xfs_rtalloc_query_range input parameters const 2021-08-18 18:46:00 -07:00
xfs_sb.c xfs: remove the xfs_dsb_t typedef 2021-10-14 09:19:33 -07:00
xfs_sb.h xfs: open code sb verifier feature checks 2021-08-19 10:07:13 -07:00
xfs_shared.h xfs: sort variable alphabetically to avoid repeated declaration 2021-06-02 14:54:09 -07:00
xfs_symlink_remote.c xfs: convert bp->b_bn references to xfs_buf_daddr() 2021-08-19 10:07:15 -07:00
xfs_trans_inode.c xfs: convert xfs_sb_version_has checks to use mount features 2021-08-19 10:07:14 -07:00
xfs_trans_resv.c xfs: compute the maximum height of the rmap btree when reflink enabled 2021-10-19 11:45:16 -07:00
xfs_trans_resv.h xfs: remove support for disabling quota accounting on a mounted file system 2021-08-06 11:05:36 -07:00
xfs_trans_space.h xfs: compute the maximum height of the rmap btree when reflink enabled 2021-10-19 11:45:16 -07:00
xfs_types.c xfs: replace xfs_sb_version checks with feature flag checks 2021-08-19 10:07:12 -07:00
xfs_types.h xfs: resolve fork names in trace output 2021-08-19 10:07:10 -07:00