1. 07 7月, 2022 8 次提交
  2. 29 6月, 2022 2 次提交
    • D
      xfs: don't hold xattr leaf buffers across transaction rolls · e53bcffa
      Darrick J. Wong 提交于
      Now that we've established (again!) that empty xattr leaf buffers are
      ok, we no longer need to bhold them to transactions when we're creating
      new leaf blocks.  Get rid of the entire mechanism, which should simplify
      the xattr code quite a bit.
      
      The original justification for using bhold here was to prevent the AIL
      from trying to write the empty leaf block into the fs during the brief
      time that we release the buffer lock.  The reason for /that/ was to
      prevent recovery from tripping over the empty ondisk block.
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      e53bcffa
    • D
      xfs: empty xattr leaf header blocks are not corruption · 7be3bd88
      Darrick J. Wong 提交于
      TLDR: Revert commit 51e6104f ("xfs: detect empty attr leaf blocks in
      xfs_attr3_leaf_verify") because it was wrong.
      
      Every now and then we get a corruption report from the kernel or
      xfs_repair about empty leaf blocks in the extended attribute structure.
      We've long thought that these shouldn't be possible, but prior to 5.18
      one would shake loose in the recoveryloop fstests about once a month.
      
      A new addition to the xattr leaf block verifier in 5.19-rc1 makes this
      happen every 7 minutes on my testing cloud.  I added a ton of logging to
      detect any time we set the header count on an xattr leaf block to zero.
      This produced the following dmesg output on generic/388:
      
      XFS (sda4): ino 0x21fcbaf leaf 0x129bf78 hdcount==0!
      Call Trace:
       <TASK>
       dump_stack_lvl+0x34/0x44
       xfs_attr3_leaf_create+0x187/0x230
       xfs_attr_shortform_to_leaf+0xd1/0x2f0
       xfs_attr_set_iter+0x73e/0xa90
       xfs_xattri_finish_update+0x45/0x80
       xfs_attr_finish_item+0x1b/0xd0
       xfs_defer_finish_noroll+0x19c/0x770
       __xfs_trans_commit+0x153/0x3e0
       xfs_attr_set+0x36b/0x740
       xfs_xattr_set+0x89/0xd0
       __vfs_setxattr+0x67/0x80
       __vfs_setxattr_noperm+0x6e/0x120
       vfs_setxattr+0x97/0x180
       setxattr+0x88/0xa0
       path_setxattr+0xc3/0xe0
       __x64_sys_setxattr+0x27/0x30
       do_syscall_64+0x35/0x80
       entry_SYSCALL_64_after_hwframe+0x46/0xb0
      
      So now we know that someone is creating empty xattr leaf blocks as part
      of converting a sf xattr structure into a leaf xattr structure.  The
      conversion routine logs any existing sf attributes in the same
      transaction that creates the leaf block, so we know this is a setxattr
      to a file that has no attributes at all.
      
      Next, g/388 calls the shutdown ioctl and cycles the mount to trigger log
      recovery.  I also augmented buffer item recovery to call ->verify_struct
      on any attr leaf blocks and complain if it finds a failure:
      
      XFS (sda4): Unmounting Filesystem
      XFS (sda4): Mounting V5 Filesystem
      XFS (sda4): Starting recovery (logdev: internal)
      XFS (sda4): xattr leaf daddr 0x129bf78 hdrcount == 0!
      Call Trace:
       <TASK>
       dump_stack_lvl+0x34/0x44
       xfs_attr3_leaf_verify+0x3b8/0x420
       xlog_recover_buf_commit_pass2+0x60a/0x6c0
       xlog_recover_items_pass2+0x4e/0xc0
       xlog_recover_commit_trans+0x33c/0x350
       xlog_recovery_process_trans+0xa5/0xe0
       xlog_recover_process_data+0x8d/0x140
       xlog_do_recovery_pass+0x19b/0x720
       xlog_do_log_recovery+0x62/0xc0
       xlog_do_recover+0x33/0x1d0
       xlog_recover+0xda/0x190
       xfs_log_mount+0x14c/0x360
       xfs_mountfs+0x517/0xa60
       xfs_fs_fill_super+0x6bc/0x950
       get_tree_bdev+0x175/0x280
       vfs_get_tree+0x1a/0x80
       path_mount+0x6f5/0xaa0
       __x64_sys_mount+0x103/0x140
       do_syscall_64+0x35/0x80
       entry_SYSCALL_64_after_hwframe+0x46/0xb0
      RIP: 0033:0x7fc61e241eae
      
      And a moment later, the _delwri_submit of the recovered buffers trips
      the same verifier and recovery fails:
      
      XFS (sda4): Metadata corruption detected at xfs_attr3_leaf_verify+0x393/0x420 [xfs], xfs_attr3_leaf block 0x129bf78
      XFS (sda4): Unmount and run xfs_repair
      XFS (sda4): First 128 bytes of corrupted metadata buffer:
      00000000: 00 00 00 00 00 00 00 00 3b ee 00 00 00 00 00 00  ........;.......
      00000010: 00 00 00 00 01 29 bf 78 00 00 00 00 00 00 00 00  .....).x........
      00000020: a5 1b d0 02 b2 9a 49 df 8e 9c fb 8d f8 31 3e 9d  ......I......1>.
      00000030: 00 00 00 00 02 1f cb af 00 00 00 00 10 00 00 00  ................
      00000040: 00 50 0f b0 00 00 00 00 00 00 00 00 00 00 00 00  .P..............
      00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
      00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
      00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
      XFS (sda4): Corruption of in-memory data (0x8) detected at _xfs_buf_ioapply+0x37f/0x3b0 [xfs] (fs/xfs/xfs_buf.c:1518).  Shutting down filesystem.
      XFS (sda4): Please unmount the filesystem and rectify the problem(s)
      XFS (sda4): log mount/recovery failed: error -117
      XFS (sda4): log mount failed
      
      I think I see what's going on here -- setxattr is racing with something
      that shuts down the filesystem:
      
      Thread 1				Thread 2
      --------				--------
      xfs_attr_sf_addname
      xfs_attr_shortform_to_leaf
      <create empty leaf>
      xfs_trans_bhold(leaf)
      xattri_dela_state = XFS_DAS_LEAF_ADD
      <roll transaction>
      					<flush log>
      					<shut down filesystem>
      xfs_trans_bhold_release(leaf)
      <discover fs is dead, bail>
      
      Thread 3
      --------
      <cycle mount, start recovery>
      xlog_recover_buf_commit_pass2
      xlog_recover_do_reg_buffer
      <replay empty leaf buffer from recovered buf item>
      xfs_buf_delwri_queue(leaf)
      xfs_buf_delwri_submit
      _xfs_buf_ioapply(leaf)
      xfs_attr3_leaf_write_verify
      <trip over empty leaf buffer>
      <fail recovery>
      
      As you can see, the bhold keeps the leaf buffer locked and thus prevents
      the *AIL* from tripping over the ichdr.count==0 check in the write
      verifier.  Unfortunately, it doesn't prevent the log from getting
      flushed to disk, which sets up log recovery to fail.
      
      So.  It's clear that the kernel has always had the ability to persist
      attr leaf blocks with ichdr.count==0, which means that it's part of the
      ondisk format now.
      
      Unfortunately, this check has been added and removed multiple times
      throughout history.  It first appeared in[1] kernel 3.10 as part of the
      early V5 format patches.  The check was later discovered to break log
      recovery and hence disabled[2] during log recovery in kernel 4.10.
      Simultaneously, the check was added[3] to xfs_repair 4.9.0 to try to
      weed out the empty leaf blocks.  This was still not correct because log
      recovery would recover an empty attr leaf block successfully only for
      regular xattr operations to trip over the empty block during of the
      block during regular operation.  Therefore, the check was removed
      entirely[4] in kernel 5.7 but removal of the xfs_repair check was
      forgotten.  The continued complaints from xfs_repair lead to us
      mistakenly re-adding[5] the verifier check for kernel 5.19.  Remove it
      once again.
      
      [1] 517c2220 ("xfs: add CRCs to attr leaf blocks")
      [2] 2e1d2337 ("xfs: ignore leaf attr ichdr.count in verifier
                         during log replay")
      [3] f7140161 ("xfs_repair: junk leaf attribute if count == 0")
      [4] f28cef9e ("xfs: don't fail verifier on empty attr3 leaf
                         block")
      [5] 51e6104f ("xfs: detect empty attr leaf blocks in
                         xfs_attr3_leaf_verify")
      
      Looking at the rest of the xattr code, it seems that files with empty
      leaf blocks behave as expected -- listxattr reports no attributes;
      getxattr on any xattr returns nothing as expected; removexattr does
      nothing; and setxattr can add attributes just fine.
      
      Original-bug: 517c2220 ("xfs: add CRCs to attr leaf blocks")
      Still-not-fixed-by: 2e1d2337 ("xfs: ignore leaf attr ichdr.count in verifier during log replay")
      Removed-in: f28cef9e ("xfs: don't fail verifier on empty attr3 leaf block")
      Fixes: 51e6104f ("xfs: detect empty attr leaf blocks in xfs_attr3_leaf_verify")
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      7be3bd88
  3. 16 6月, 2022 2 次提交
    • D
      xfs: fix variable state usage · 10930b25
      Darrick J. Wong 提交于
      The variable @args is fed to a tracepoint, and that's the only place
      it's used.  This is fine for the kernel, but for userspace, tracepoints
      are #define'd out of existence, which results in this warning on gcc
      11.2:
      
      xfs_attr.c: In function ‘xfs_attr_node_try_addname’:
      xfs_attr.c:1440:42: warning: unused variable ‘args’ [-Wunused-variable]
       1440 |         struct xfs_da_args              *args = attr->xattri_da_args;
            |                                          ^~~~
      
      Clean this up.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: NAllison Henderson <allison.henderson@oracle.com>
      10930b25
    • 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
  4. 27 5月, 2022 8 次提交
    • D
      xfs: move xfs_attr_use_log_assist usage out of libxfs · efc2efeb
      Darrick J. Wong 提交于
      The LARP patchset added an awkward coupling point between libxfs and
      what would be libxlog, if the XFS log were actually its own library.
      Move the code that sets up logged xattr updates out of libxfs and into
      xfs_xattr.c so that libxfs no longer has to know about xlog_* functions.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      efc2efeb
    • D
      xfs: move xfs_attr_use_log_assist out of xfs_log.c · d9c61ccb
      Darrick J. Wong 提交于
      The LARP patchset added an awkward coupling point between libxfs and
      what would be libxlog, if the XFS log were actually its own library.
      Move the code that enables logged xattr updates out of "lib"xlog and into
      xfs_xattr.c so that it no longer has to know about xlog_* functions.
      
      While we're at it, give xfs_xattr.c its own header file.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      d9c61ccb
    • D
      xfs: convert buf_cancel_table allocation to kmalloc_array · 910bbdf2
      Darrick J. Wong 提交于
      While we're messing around with how recovery allocates and frees the
      buffer cancellation table, convert the allocation to use kmalloc_array
      instead of the old kmem_alloc APIs, and make it handle a null return,
      even though that's not likely.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      910bbdf2
    • D
      xfs: refactor buffer cancellation table allocation · 27232349
      Darrick J. Wong 提交于
      Move the code that allocates and frees the buffer cancellation tables
      used by log recovery into the file that actually uses the tables.  This
      is a precursor to some cleanups and a memory leak fix.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      27232349
    • D
      xfs: don't leak btree cursor when insrec fails after a split · a54f78de
      Darrick J. Wong 提交于
      The recent patch to improve btree cycle checking caused a regression
      when I rebased the in-memory btree branch atop the 5.19 for-next branch,
      because in-memory short-pointer btrees do not have AG numbers.  This
      produced the following complaint from kmemleak:
      
      unreferenced object 0xffff88803d47dde8 (size 264):
        comm "xfs_io", pid 4889, jiffies 4294906764 (age 24.072s)
        hex dump (first 32 bytes):
          90 4d 0b 0f 80 88 ff ff 00 a0 bd 05 80 88 ff ff  .M..............
          e0 44 3a a0 ff ff ff ff 00 df 08 06 80 88 ff ff  .D:.............
        backtrace:
          [<ffffffffa0388059>] xfbtree_dup_cursor+0x49/0xc0 [xfs]
          [<ffffffffa029887b>] xfs_btree_dup_cursor+0x3b/0x200 [xfs]
          [<ffffffffa029af5d>] __xfs_btree_split+0x6ad/0x820 [xfs]
          [<ffffffffa029b130>] xfs_btree_split+0x60/0x110 [xfs]
          [<ffffffffa029f6da>] xfs_btree_make_block_unfull+0x19a/0x1f0 [xfs]
          [<ffffffffa029fada>] xfs_btree_insrec+0x3aa/0x810 [xfs]
          [<ffffffffa029fff3>] xfs_btree_insert+0xb3/0x240 [xfs]
          [<ffffffffa02cb729>] xfs_rmap_insert+0x99/0x200 [xfs]
          [<ffffffffa02cf142>] xfs_rmap_map_shared+0x192/0x5f0 [xfs]
          [<ffffffffa02cf60b>] xfs_rmap_map_raw+0x6b/0x90 [xfs]
          [<ffffffffa0384a85>] xrep_rmap_stash+0xd5/0x1d0 [xfs]
          [<ffffffffa0384dc0>] xrep_rmap_visit_bmbt+0xa0/0xf0 [xfs]
          [<ffffffffa0384fb6>] xrep_rmap_scan_iext+0x56/0xa0 [xfs]
          [<ffffffffa03850d8>] xrep_rmap_scan_ifork+0xd8/0x160 [xfs]
          [<ffffffffa0385195>] xrep_rmap_scan_inode+0x35/0x80 [xfs]
          [<ffffffffa03852ee>] xrep_rmap_find_rmaps+0x10e/0x270 [xfs]
      
      I noticed that xfs_btree_insrec has a bunch of debug code that return
      out of the function immediately, without freeing the "new" btree cursor
      that can be returned when _make_block_unfull calls xfs_btree_split.  Fix
      the error return in this function to free the btree cursor.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      a54f78de
    • D
      xfs: assert in xfs_btree_del_cursor should take into account error · 56486f30
      Dave Chinner 提交于
      xfs/538 on a 1kB block filesystem failed with this assert:
      
      XFS: Assertion failed: cur->bc_btnum != XFS_BTNUM_BMAP || cur->bc_ino.allocated == 0 || xfs_is_shutdown(cur->bc_mp), file: fs/xfs/libxfs/xfs_btree.c, line: 448
      
      The problem was that an allocation failed unexpectedly in
      xfs_bmbt_alloc_block() after roughly 150,000 minlen allocation error
      injections, resulting in an EFSCORRUPTED error being returned to
      xfs_bmapi_write(). The error occurred on extent-to-btree format
      conversion allocating the new root block:
      
       RIP: 0010:xfs_bmbt_alloc_block+0x177/0x210
       Call Trace:
        <TASK>
        xfs_btree_new_iroot+0xdf/0x520
        xfs_btree_make_block_unfull+0x10d/0x1c0
        xfs_btree_insrec+0x364/0x790
        xfs_btree_insert+0xaa/0x210
        xfs_bmap_add_extent_hole_real+0x1fe/0x9a0
        xfs_bmapi_allocate+0x34c/0x420
        xfs_bmapi_write+0x53c/0x9c0
        xfs_alloc_file_space+0xee/0x320
        xfs_file_fallocate+0x36b/0x450
        vfs_fallocate+0x148/0x340
        __x64_sys_fallocate+0x3c/0x70
        do_syscall_64+0x35/0x80
        entry_SYSCALL_64_after_hwframe+0x44/0xa
      
      Why the allocation failed at this point is unknown, but is likely
      that we ran the transaction out of reserved space and filesystem out
      of space with bmbt blocks because of all the minlen allocations
      being done causing worst case fragmentation of a large allocation.
      
      Regardless of the cause, we've then called xfs_bmapi_finish() which
      calls xfs_btree_del_cursor(cur, error) to tear down the cursor.
      
      So we have a failed operation, error != 0, cur->bc_ino.allocated > 0
      and the filesystem is still up. The assert fails to take into
      account that allocation can fail with an error and the transaction
      teardown will shut the filesystem down if necessary. i.e. the
      assert needs to check "|| error != 0" as well, because at this point
      shutdown is pending because the current transaction is dirty....
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      56486f30
    • D
      xfs: don't assert fail on perag references on teardown · 5b55cbc2
      Dave Chinner 提交于
      Not fatal, the assert is there to catch developer attention. I'm
      seeing this occasionally during recoveryloop testing after a
      shutdown, and I don't want this to stop an overnight recoveryloop
      run as it is currently doing.
      
      Convert the ASSERT to a XFS_IS_CORRUPT() check so it will dump a
      corruption report into the log and cause a test failure that way,
      but it won't stop the machine dead.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      5b55cbc2
    • D
      xfs: avoid unnecessary runtime sibling pointer endian conversions · 5672225e
      Dave Chinner 提交于
      Commit dc04db2a has caused a small aim7 regression, showing a
      small increase in CPU usage in __xfs_btree_check_sblock() as a
      result of the extra checking.
      
      This is likely due to the endian conversion of the sibling poitners
      being unconditional instead of relying on the compiler to endian
      convert the NULL pointer at compile time and avoiding the runtime
      conversion for this common case.
      
      Rework the checks so that endian conversion of the sibling pointers
      is only done if they are not null as the original code did.
      
      .... and these need to be "inline" because the compiler completely
      fails to inline them automatically like it should be doing.
      
      $ size fs/xfs/libxfs/xfs_btree.o*
         text	   data	    bss	    dec	    hex	filename
        51874	    240	      0	  52114	   cb92 fs/xfs/libxfs/xfs_btree.o.orig
        51562	    240	      0	  51802	   ca5a fs/xfs/libxfs/xfs_btree.o.inline
      
      Just when you think the tools have advanced sufficiently we don't
      have to care about stuff like this anymore, along comes a reminder
      that *our tools still suck*.
      
      Fixes: dc04db2a ("xfs: detect self referencing btree sibling pointers")
      Reported-by: Nkernel test robot <oliver.sang@intel.com>
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      5672225e
  5. 23 5月, 2022 2 次提交
    • D
      xfs: share xattr name and value buffers when logging xattr updates · 4183e4f2
      Darrick J. Wong 提交于
      While running xfs/297 and generic/642, I noticed a crash in
      xfs_attri_item_relog when it tries to copy the attr name to the new
      xattri log item.  I think what happened here was that we called
      ->iop_commit on the old attri item (which nulls out the pointers) as
      part of a log force at the same time that a chained attr operation was
      ongoing.  The system was busy enough that at some later point, the defer
      ops operation decided it was necessary to relog the attri log item, but
      as we've detached the name buffer from the old attri log item, we can't
      copy it to the new one, and kaboom.
      
      I think there's a broader refcounting problem with LARP mode -- the
      setxattr code can return to userspace before the CIL actually formats
      and commits the log item, which results in a UAF bug.  Therefore, the
      xattr log item needs to be able to retain a reference to the name and
      value buffers until the log items have completely cleared the log.
      Furthermore, each time we create an intent log item, we allocate new
      memory and (re)copy the contents; sharing here would be very useful.
      
      Solve the UAF and the unnecessary memory allocations by having the log
      code create a single refcounted buffer to contain the name and value
      contents.  This buffer can be passed from old to new during a relog
      operation, and the logging code can (optionally) attach it to the
      xfs_attr_item for reuse when LARP mode is enabled.
      
      This also fixes a problem where the xfs_attri_log_item objects weren't
      being freed back to the same cache where they came from.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      4183e4f2
    • D
      xfs: do not use logged xattr updates on V4 filesystems · 22a68ba7
      Darrick J. Wong 提交于
      V4 superblocks do not contain the log_incompat feature bit, which means
      that we cannot protect xattr log items against kernels that are too old
      to know how to recover them.  Turn off the log items for such
      filesystems and adjust the "delayed" name to reflect what it's really
      controlling.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      22a68ba7
  6. 22 5月, 2022 8 次提交
  7. 20 5月, 2022 3 次提交
    • D
      xfs: reject unknown xattri log item filter flags during recovery · 85d76aec
      Darrick J. Wong 提交于
      Make sure we screen the "attr flags" field of recovered xattr intent log
      items to reject flag bits that we don't know about.  This is really the
      attr *filter* field from xfs_da_args, so rename the field and create
      a mask to make checking for invalid bits easier.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NDave Chinner <dchinner@redhat.com>
      Reviewed-by: NAllison Henderson <allison.henderson@oracle.com>
      Signed-off-by: NDave Chinner <david@fromorbit.com>
      85d76aec
    • 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
  8. 12 5月, 2022 7 次提交
    • D
      xfs: detect empty attr leaf blocks in xfs_attr3_leaf_verify · 51e6104f
      Dave Chinner 提交于
      xfs_repair flags these as a corruption error, so the verifier should
      catch software bugs that result in empty leaf blocks being written
      to disk, too.
      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>
      51e6104f
    • 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