1. 16 6月, 2022 1 次提交
    • D
      xfs: fix TOCTOU race involving the new logged xattrs control knob · f4288f01
      Darrick J. Wong 提交于
      I found a race involving the larp control knob, aka the debugging knob
      that lets developers enable logging of extended attribute updates:
      
      Thread 1			Thread 2
      
      echo 0 > /sys/fs/xfs/debug/larp
      				setxattr(REPLACE)
      				xfs_has_larp (returns false)
      				xfs_attr_set
      
      echo 1 > /sys/fs/xfs/debug/larp
      
      				xfs_attr_defer_replace
      				xfs_attr_init_replace_state
      				xfs_has_larp (returns true)
      				xfs_attr_init_remove_state
      
      				<oops, wrong DAS state!>
      
      This isn't a particularly severe problem right now because xattr logging
      is only enabled when CONFIG_XFS_DEBUG=y, and developers *should* know
      what they're doing.
      
      However, the eventual intent is that callers should be able to ask for
      the assistance of the log in persisting xattr updates.  This capability
      might not be required for /all/ callers, which means that dynamic
      control must work correctly.  Once an xattr update has decided whether
      or not to use logged xattrs, it needs to stay in that mode until the end
      of the operation regardless of what subsequent parallel operations might
      do.
      
      Therefore, it is an error to continue sampling xfs_globals.larp once
      xfs_attr_change has made a decision about larp, and it was not correct
      for me to have told Allison that ->create_intent functions can sample
      the global log incompat feature bitfield to decide to elide a log item.
      
      Instead, create a new op flag for the xfs_da_args structure, and convert
      all other callers of xfs_has_larp and xfs_sb_version_haslogxattrs within
      the attr update state machine to look for the operations flag.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NAllison Henderson <allison.henderson@oracle.com>
      f4288f01
  2. 27 5月, 2022 2 次提交
  3. 23 5月, 2022 1 次提交
  4. 22 5月, 2022 6 次提交
  5. 20 5月, 2022 2 次提交
    • D
      xfs: don't leak the retained da state when doing a leaf to node conversion · a618acab
      Darrick J. Wong 提交于
      If a setxattr operation finds an xattr structure in leaf format, adding
      the attr can fail due to lack of space and hence requires an upgrade to
      node format.  After this happens, we'll roll the transaction and
      re-enter the state machine, at which time we need to perform a second
      lookup of the attribute name to find its new location.  This lookup
      attaches a new da state structure to the xfs_attr_item but doesn't free
      the old one (from the leaf lookup) and leaks it.  Fix that.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NAllison Henderson <allison.henderson@oracle.com>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      a618acab
    • D
      xfs: don't leak da state when freeing the attr intent item · 309001c2
      Darrick J. Wong 提交于
      kmemleak reported that we lost an xfs_da_state while removing xattrs in
      generic/020:
      
      unreferenced object 0xffff88801c0e4b40 (size 480):
        comm "attr", pid 30515, jiffies 4294931061 (age 5.960s)
        hex dump (first 32 bytes):
          78 bc 65 07 00 c9 ff ff 00 30 60 1c 80 88 ff ff  x.e......0`.....
          02 00 00 00 00 00 00 00 80 18 83 4e 80 88 ff ff  ...........N....
        backtrace:
          [<ffffffffa023ef4a>] xfs_da_state_alloc+0x1a/0x30 [xfs]
          [<ffffffffa021b6f3>] xfs_attr_node_hasname+0x23/0x90 [xfs]
          [<ffffffffa021c6f1>] xfs_attr_set_iter+0x441/0xa30 [xfs]
          [<ffffffffa02b5104>] xfs_xattri_finish_update+0x44/0x80 [xfs]
          [<ffffffffa02b515e>] xfs_attr_finish_item+0x1e/0x40 [xfs]
          [<ffffffffa0244744>] xfs_defer_finish_noroll+0x184/0x740 [xfs]
          [<ffffffffa02a6473>] __xfs_trans_commit+0x153/0x3e0 [xfs]
          [<ffffffffa021d149>] xfs_attr_set+0x469/0x7e0 [xfs]
          [<ffffffffa02a78d9>] xfs_xattr_set+0x89/0xd0 [xfs]
          [<ffffffff812e6512>] __vfs_removexattr+0x52/0x70
          [<ffffffff812e6a08>] __vfs_removexattr_locked+0xb8/0x150
          [<ffffffff812e6af6>] vfs_removexattr+0x56/0x100
          [<ffffffff812e6bf8>] removexattr+0x58/0x90
          [<ffffffff812e6cce>] path_removexattr+0x9e/0xc0
          [<ffffffff812e6d44>] __x64_sys_lremovexattr+0x14/0x20
          [<ffffffff81786b35>] do_syscall_64+0x35/0x80
      
      I think this is a consequence of xfs_attr_node_removename_setup
      attaching a new da(btree) state to xfs_attr_item and never freeing it.
      I /think/ it's the case that the remove paths could detach the da state
      earlier in the remove state machine since nothing else accesses the
      state.  However, let's future-proof the new xattr code by adding a
      catch-all when we free the xfs_attr_item to make sure we never leak the
      da state.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NAllison Henderson <allison.henderson@oracle.com>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      309001c2
  6. 12 5月, 2022 13 次提交
    • D
      xfs: ATTR_REPLACE algorithm with LARP enabled needs rework · fdaf1bb3
      Dave Chinner 提交于
      We can't use the same algorithm for replacing an existing attribute
      when logging attributes. The existing algorithm is essentially:
      
      1. create new attr w/ INCOMPLETE
      2. atomically flip INCOMPLETE flags between old + new attribute
      3. remove old attr which is marked w/ INCOMPLETE
      
      This algorithm guarantees that we see either the old or new
      attribute, and if we fail after the atomic flag flip, we don't have
      to recover the removal of the old attr because we never see
      INCOMPLETE attributes in lookups.
      
      For logged attributes, however, this does not work. The logged
      attribute intents do not track the work that has been done as the
      transaction rolls, and hence the only recovery mechanism we have is
      "run the replace operation from scratch".
      
      This is further exacerbated by the attempt to avoid needing the
      INCOMPLETE flag to create an atomic swap. This means we can create
      a second active attribute of the same name before we remove the
      original. If we fail at any point after the create but before the
      removal has completed, we end up with duplicate attributes in
      the attr btree and recovery only tries to replace one of them.
      
      There are several other failure modes where we can leave partially
      allocated remote attributes that expose stale data, partially free
      remote attributes that enable UAF based stale data exposure, etc.
      
      TO fix this, we need a different algorithm for replace operations
      when LARP is enabled. Luckily, it's not that complex if we take the
      right first step. That is, the first thing we log is the attri
      intent with the new name/value pair and mark the old attr as
      INCOMPLETE in the same transaction.
      
      From there, we then remove the old attr and keep relogging the
      new name/value in the intent, such that we always know that we have
      to create the new attr in recovery. Once the old attr is removed,
      we then run a normal ATTR_CREATE operation relogging the intent as
      we go. If the new attr is local, then it gets created in a single
      atomic transaction that also logs the final intent done. If the new
      attr is remote, the we set INCOMPLETE on the new attr while we
      allocate and set the remote value, and then we clear the INCOMPLETE
      flag at in the last transaction taht logs the final intent done.
      
      If we fail at any point in this algorithm, log recovery will always
      see the same state on disk: the new name/value in the intent, and
      either an INCOMPLETE attr or no attr in the attr btree. If we find
      an INCOMPLETE attr, we run the full replace starting with removing
      the INCOMPLETE attr. If we don't find it, then we simply create the
      new attr.
      
      Notably, recovery of a failed create that has an INCOMPLETE flag set
      is now the same - we start with the lookup of the INCOMPLETE attr,
      and if that exists then we do the full replace recovery process,
      otherwise we just create the new attr.
      
      Hence changing the way we do the replace operation when LARP is
      enabled allows us to use the same log recovery algorithm for both
      the ATTR_CREATE and ATTR_REPLACE operations. This is also the same
      algorithm we use for runtime ATTR_REPLACE operations (except for the
      step setting up the initial conditions).
      
      The result is that:
      
      - ATTR_CREATE uses the same algorithm regardless of whether LARP is
        enabled or not
      - ATTR_REPLACE with larp=0 is identical to the old algorithm
      - ATTR_REPLACE with larp=1 runs an unmodified attr removal algorithm
        from the larp=0 code and then runs the unmodified ATTR_CREATE
        code.
      - log recovery when larp=1 runs the same ATTR_REPLACE algorithm as
        it uses at runtime.
      
      Because the state machine is now quite clean, changing the algorithm
      is really just a case of changing the initial state and how the
      states link together for the ATTR_REPLACE case. Hence it's not a
      huge amount of code for what is a fairly substantial rework
      of the attr logging and recovery algorithm....
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: NAllison Henderson <allison.henderson@oracle.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      fdaf1bb3
    • D
      xfs: use XFS_DA_OP flags in deferred attr ops · e7f358de
      Dave Chinner 提交于
      We currently store the high level attr operation in
      args->attr_flags. This field contains what the VFS is telling us to
      do, but don't necessarily match what we are doing in the low level
      modification state machine. e.g. XATTR_REPLACE implies both
      XFS_DA_OP_ADDNAME and XFS_DA_OP_RENAME because it is doing both a
      remove and adding a new attr.
      
      However, deep in the individual state machine operations, we check
      errors against this high level VFS op flags, not the low level
      XFS_DA_OP flags. Indeed, we don't even have a low level flag for
      a REMOVE operation, so the only way we know we are doing a remove
      is the complete absence of XATTR_REPLACE, XATTR_CREATE,
      XFS_DA_OP_ADDNAME and XFS_DA_OP_RENAME. And because there are other
      flags in these fields, this is a pain to check if we need to.
      
      As the XFS_DA_OP flags are only needed once the deferred operations
      are set up, set these flags appropriately when we set the initial
      operation state. We also introduce a XFS_DA_OP_REMOVE flag to make
      it easy to know that we are doing a remove operation.
      
      With these, we can remove the use of XATTR_REPLACE and XATTR_CREATE
      in low level lookup operations, and manipulate the low level flags
      according to the low level context that is operating. e.g. log
      recovery does not have a VFS xattr operation state to copy into
      args->attr_flags, and the low level state machine ops we do for
      recovery do not match the high level VFS operations that were in
      progress when the system failed...
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NAllison Henderson <allison.henderson@oracle.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      e7f358de
    • D
      xfs: remove xfs_attri_remove_iter · 59782a23
      Dave Chinner 提交于
      xfs_attri_remove_iter is not used anymore, so remove it and all the
      infrastructure it uses and is needed to drive it. THe
      xfs_attr_refillstate() function now throws an unused warning, so
      isolate the xfs_attr_fillstate()/xfs_attr_refillstate() code pair
      with an #if 0 and a comment explaining why we want to keep this code
      and restore the optimisation it provides in the near future.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: Allison Henderson<allison.henderson@oracle.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      59782a23
    • D
      xfs: switch attr remove to xfs_attri_set_iter · 4b9879b1
      Dave Chinner 提交于
      Now that xfs_attri_set_iter() has initial states for removing
      attributes, switch the pure attribute removal code over to using it.
      This requires attrs being removed to always be marked as INCOMPLETE
      before we start the removal due to the fact we look up the attr to
      remove again in xfs_attr_node_remove_attr().
      
      Note: this drops the fillstate/refillstate optimisations from
      the remove path that avoid having to look up the path again after
      setting the incomplete flag and removing remote attrs. Restoring
      that optimisation to this path is future Dave's problem.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: NAllison Henderson <allison.henderson@oracle.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      4b9879b1
    • D
      xfs: introduce attr remove initial states into xfs_attr_set_iter · e5d5596a
      Dave Chinner 提交于
      We need to merge the add and remove code paths to enable safe
      recovery of replace operations. Hoist the initial remove states from
      xfs_attr_remove_iter into xfs_attr_set_iter. We will make use of
      them in the next patches.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: Allison Henderson<allison.henderson@oracle.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      e5d5596a
    • D
      xfs: xfs_attr_set_iter() does not need to return EAGAIN · 4e3d96a5
      Dave Chinner 提交于
      Now that the full xfs_attr_set_iter() state machine always
      terminates with either the state being XFS_DAS_DONE on success or
      an error on failure, we can get rid of the need for it to return
      -EAGAIN whenever it needs to roll the transaction before running
      the next state.
      
      That is, we don't need to spray -EAGAIN return states everywhere,
      the caller just check the state machine state for completion to
      determine what action should be taken next. This greatly simplifies
      the code within the state machine implementation as it now only has
      to handle 0 for success or -errno for error and it doesn't need to
      tell the caller to retry.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: Allison Henderson<allison.henderson@oracle.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      4e3d96a5
    • D
      xfs: clean up final attr removal in xfs_attr_set_iter · b11fa61b
      Dave Chinner 提交于
      Clean up the final leaf/node states in xfs_attr_set_iter() to
      further simplify the high level state machine and to set the
      completion state correctly. As we are adding a separate state
      for node format removal, we need to ensure that node formats
      are collapsed back to shortform or empty correctly.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: Allison Henderson<allison.henderson@oracle.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      b11fa61b
    • D
      xfs: remote xattr removal in xfs_attr_set_iter() is conditional · 2e7ef218
      Dave Chinner 提交于
      We may not have a remote value for the old xattr we have to remove,
      so skip over the remote value removal states and go straight to
      the xattr name removal in the leaf/node block.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: Allison Henderson<allison.henderson@oracle.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      2e7ef218
    • D
      xfs: XFS_DAS_LEAF_REPLACE state only needed if !LARP · 411b434a
      Dave Chinner 提交于
      We can skip the REPLACE state when LARP is enabled, but that means
      the XFS_DAS_FLIP_LFLAG state is now poorly named - it indicates
      something that has been done rather than what the state is going to
      do. Rename it to "REMOVE_OLD" to indicate that we are now going to
      perform removal of the old attr.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: Allison Henderson<allison.henderson@oracle.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      411b434a
    • D
      xfs: split remote attr setting out from replace path · 7d035336
      Dave Chinner 提交于
      When we set a new xattr, we have three exit paths:
      
      	1. nothing else to do
      	2. allocate and set the remote xattr value
      	3. perform the rest of a replace operation
      
      Currently we push both 2 and 3 into the same state, regardless of
      whether we just set a remote attribute or not. Once we've set the
      remote xattr, we have two exit states:
      
      	1. nothing else to do
      	2. perform the rest of a replace operation
      
      Hence we can split the remote xattr allocation and setting into
      their own states and factor it out of xfs_attr_set_iter() to further
      clean up the state machine and the implementation of the state
      machine.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: Allison Henderson<allison.henderson@oracle.com>
      Reviewed-by: NDave Chinner <david@fromorbit.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      7d035336
    • D
      xfs: consolidate leaf/node states in xfs_attr_set_iter · 251b29c8
      Dave Chinner 提交于
      The operations performed from XFS_DAS_FOUND_LBLK through to
      XFS_DAS_RM_LBLK are now identical to XFS_DAS_FOUND_NBLK through to
      XFS_DAS_RM_NBLK. We can collapse these down into a single set of
      code.
      
      To do this, define the states that leaf and node run through as
      separate sets of sequential states. Then as we move to the next
      state, we can use increments rather than specific state assignments
      to move through the states. This means the state progression is set
      by the initial state that enters the series and we don't need to
      duplicate the code anymore.
      
      At the exit point of the series we need to select the correct leaf
      or node state, but that can also be done by state increment rather
      than assignment.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: Allison Henderson<allison.henderson@oracle.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      251b29c8
    • D
      xfs: kill XFS_DAC_LEAF_ADDNAME_INIT · 2157d169
      Dave Chinner 提交于
      We re-enter the XFS_DAS_FOUND_LBLK state when we have to allocate
      multiple extents for a remote xattr. We currently have a flag
      called XFS_DAC_LEAF_ADDNAME_INIT to avoid running the remote attr
      hole finding code more than once.
      
      However, for the node format tree, we have a separate state for this
      so we never reenter the state machine at XFS_DAS_FOUND_NBLK and so
      it does not need a special flag to skip over the remote attr hold
      finding code.
      
      Convert the leaf block code to use the same state machine as the
      node blocks and kill the  XFS_DAC_LEAF_ADDNAME_INIT flag.
      
      This further points out that this "ALLOC" state is only traversed
      if we have remote xattrs or we are doing a rename operation. Rename
      both the leaf and node alloc states to _ALLOC_RMT to indicate they
      are iterating to do allocation of remote xattr blocks.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: Allison Henderson<allison.henderson@oracle.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      2157d169
    • D
      xfs: separate out initial attr_set states · e0c41089
      Dave Chinner 提交于
      We current use XFS_DAS_UNINIT for several steps in the attr_set
      state machine. We use it for setting shortform xattrs, converting
      from shortform to leaf, leaf add, leaf-to-node and leaf add. All of
      these things are essentially known before we start the state machine
      iterating, so we really should separate them out:
      
      XFS_DAS_SF_ADD:
      	- tries to do a shortform add
      	- on success -> done
      	- on ENOSPC converts to leaf, -> XFS_DAS_LEAF_ADD
      	- on error, dies.
      
      XFS_DAS_LEAF_ADD:
      	- tries to do leaf add
      	- on success:
      		- inline attr -> done
      		- remote xattr || REPLACE -> XFS_DAS_FOUND_LBLK
      	- on ENOSPC converts to node, -> XFS_DAS_NODE_ADD
      	- on error, dies
      
      XFS_DAS_NODE_ADD:
      	- tries to do node add
      	- on success:
      		- inline attr -> done
      		- remote xattr || REPLACE -> XFS_DAS_FOUND_NBLK
      	- on error, dies
      
      This makes it easier to understand how the state machine starts
      up and sets us up on the path to further state machine
      simplifications.
      
      This also converts the DAS state tracepoints to use strings rather
      than numbers, as converting between enums and numbers requires
      manual counting rather than just reading the name.
      
      This also introduces a XFS_DAS_DONE state so that we can trace
      successful operation completions easily.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: Allison Henderson<allison.henderson@oracle.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      e0c41089
  7. 11 5月, 2022 8 次提交
  8. 09 5月, 2022 1 次提交
  9. 04 5月, 2022 2 次提交
    • A
      xfs: Set up infrastructure for log attribute replay · fd920008
      Allison Henderson 提交于
      Currently attributes are modified directly across one or more
      transactions. But they are not logged or replayed in the event of an
      error. The goal of log attr replay is to enable logging and replaying
      of attribute operations using the existing delayed operations
      infrastructure.  This will later enable the attributes to become part of
      larger multi part operations that also must first be recorded to the
      log.  This is mostly of interest in the scheme of parent pointers which
      would need to maintain an attribute containing parent inode information
      any time an inode is moved, created, or removed.  Parent pointers would
      then be of interest to any feature that would need to quickly derive an
      inode path from the mount point. Online scrub, nfs lookups and fs grow
      or shrink operations are all features that could take advantage of this.
      
      This patch adds two new log item types for setting or removing
      attributes as deferred operations.  The xfs_attri_log_item will log an
      intent to set or remove an attribute.  The corresponding
      xfs_attrd_log_item holds a reference to the xfs_attri_log_item and is
      freed once the transaction is done.  Both log items use a generic
      xfs_attr_log_format structure that contains the attribute name, value,
      flags, inode, and an op_flag that indicates if the operations is a set
      or remove.
      
      [dchinner: added extra little bits needed for intent whiteouts]
      Signed-off-by: NAllison Henderson <allison.henderson@oracle.com>
      Reviewed-by: NChandan Babu R <chandanrlinux@gmail.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      fd920008
    • A
      xfs: Return from xfs_attr_set_iter if there are no more rmtblks to process · 9a39cdab
      Allison Henderson 提交于
      During an attr rename operation, blocks are saved for later removal
      as rmtblkno2. The rmtblkno is used in the case of needing to alloc
      more blocks if not enough were available.  However, in the case
      that no further blocks need to be added or removed, we can return as soon
      as xfs_attr_node_addname completes, rather than rolling the transaction
      with an -EAGAIN return.  This extra loop does not hurt anything right
      now, but it will be a problem later when we get into log items because
      we end up with an empty log transaction.  So, add a simple check to
      cut out the unneeded iteration.
      Signed-off-by: NAllison Henderson <allison.henderson@oracle.com>
      Reviewed-by: NChandan Babu R <chandanrlinux@gmail.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      9a39cdab
  10. 13 4月, 2022 1 次提交
  11. 25 11月, 2021 1 次提交
    • Y
      xfs: Fix the free logic of state in xfs_attr_node_hasname · a1de97fe
      Yang Xu 提交于
      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 07120f1a ("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: 07120f1a ("xfs: Add xfs_has_attr and subroutines")
      Signed-off-by: NYang Xu <xuyang2018.jy@fujitsu.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      a1de97fe
  12. 20 8月, 2021 2 次提交