linux-stable/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_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_attr_leaf.c xfs: rename _zone variables to _cache 2021-10-22 16:04:20 -07:00
xfs_attr_leaf.h
xfs_attr_remote.c
xfs_attr_remote.h
xfs_attr_sf.h
xfs_bit.c
xfs_bit.h
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_btree_staging.h
xfs_cksum.h
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_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_dir2.h
xfs_dir2_block.c
xfs_dir2_data.c
xfs_dir2_leaf.c
xfs_dir2_node.c
xfs_dir2_priv.h
xfs_dir2_sf.c
xfs_dquot_buf.c
xfs_errortag.h
xfs_format.h
xfs_fs.h xfs: compute absolute maximum nlevels for each btree type 2021-10-19 11:45:16 -07:00
xfs_health.h
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_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_inode_buf.c
xfs_inode_buf.h
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_log_recover.h
xfs_log_rlimit.c
xfs_quota_defs.h
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_sb.c
xfs_sb.h
xfs_shared.h
xfs_symlink_remote.c
xfs_trans_inode.c
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_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_types.h