Skip to content
  1. Aug 29, 2023
    • Christian Brauner's avatar
      super: ensure valid info · dc3216b1
      Christian Brauner authored
      For keyed filesystems that recycle superblocks based on s_fs_info or
      information contained therein s_fs_info must be kept as long as the
      superblock is on the filesystem type super list. This isn't guaranteed
      as s_fs_info will be freed latest in sb->kill_sb().
      
      The fix is simply to perform notification and list removal in
      kill_anon_super(). Any filesystem needs to free s_fs_info after they
      call the kill_*() helpers. If they don't they risk use-after-free right
      now so fixing it here is guaranteed that s_fs_info remain valid.
      
      For block backed filesystems notifying in pass sb->kill_sb() in
      deactivate_locked_super() remains unproblematic and is required because
      multiple other block devices can be shut down after kill_block_super()
      has been called from a filesystem's sb->kill_sb() handler. For example,
      ext4 and xfs close additional devices. Block based filesystems don't
      depend on s_fs_info (btrfs does use s_fs_info but also uses
      kill_anon_super() and not kill_block_super().).
      
      Sorry for that braino. Goal should be to unify this behavior during this
      cycle obviously. But let's please do a simple bugfix now.
      
      Fixes: 2c18a63b
      
       ("super: wait until we passed kill super")
      Fixes: syzbot+5b64180f8d9e39d3f061@syzkaller.appspotmail.com
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Reported-by: default avatar <syzbot+5b64180f8d9e39d3f061@syzkaller.appspotmail.com>
      Message-Id: <20230828-vfs-super-fixes-v1-2-b37a4a04a88f@kernel.org>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      dc3216b1
    • Christian Brauner's avatar
      super: move lockdep assert · 345a5c4a
      Christian Brauner authored
      Fix braino and move the lockdep assertion after put_super() otherwise we
      risk a use-after-free.
      
      Fixes: 2c18a63b
      
       ("super: wait until we passed kill super")
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Message-Id: <20230828-vfs-super-fixes-v1-1-b37a4a04a88f@kernel.org>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      345a5c4a
  2. Aug 23, 2023
  3. Aug 22, 2023
    • Christian Brauner's avatar
      super: use higher-level helper for {freeze,thaw} · 051178c3
      Christian Brauner authored
      
      
      It's not necessary to use low-level locking helpers here. Use the
      higher-level locking helpers and log if the superblock is dying. Since
      the caller is assumed to already hold an active reference it isn't
      possible to observe a dying superblock.
      
      Suggested-by: default avatarJan Kara <jack@suse.cz>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      051178c3
    • Christian Brauner's avatar
      super: wait until we passed kill super · 2c18a63b
      Christian Brauner authored
      
      
      Recent rework moved block device closing out of sb->put_super() and into
      sb->kill_sb() to avoid deadlocks as s_umount is held in put_super() and
      blkdev_put() can end up taking s_umount again.
      
      That means we need to move the removal of the superblock from @fs_supers
      out of generic_shutdown_super() and into deactivate_locked_super() to
      ensure that concurrent mounters don't fail to open block devices that
      are still in use because blkdev_put() in sb->kill_sb() hasn't been
      called yet.
      
      We can now do this as we can make iterators through @fs_super and
      @super_blocks wait without holding s_umount. Concurrent mounts will wait
      until a dying superblock is fully dead so until sb->kill_sb() has been
      called and SB_DEAD been set. Concurrent iterators can already discard
      any SB_DYING superblock.
      
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Message-Id: <20230818-vfs-super-fixes-v3-v3-4-9f0b1876e46b@kernel.org>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      2c18a63b
    • Christian Brauner's avatar
      super: wait for nascent superblocks · 5e874914
      Christian Brauner authored
      Recent patches experiment with making it possible to allocate a new
      superblock before opening the relevant block device. Naturally this has
      intricate side-effects that we get to learn about while developing this.
      
      Superblock allocators such as sget{_fc}() return with s_umount of the
      new superblock held and lock ordering currently requires that block
      level locks such as bdev_lock and open_mutex rank above s_umount.
      
      Before aca740ce ("fs: open block device after superblock creation")
      ordering was guaranteed to be correct as block devices were opened prior
      to superblock allocation and thus s_umount wasn't held. But now s_umount
      must be dropped before opening block devices to avoid locking
      violations.
      
      This has consequences. The main one being that iterators over
      @super_blocks and @fs_supers that grab a temporary reference to the
      superblock can now also grab s_umount before the caller has managed to
      open block devices and called fill_super(). So whereas before such
      iterators or concurrent mounts would have simply slept on s_umount until
      SB_BORN was set or the superblock was discard due to initalization
      failure they can now needlessly spin through sget{_fc}().
      
      If the caller is sleeping on bdev_lock or open_mutex one caller waiting
      on SB_BORN will always spin somewhere and potentially this can go on for
      quite a while.
      
      It should be possible to drop s_umount while allowing iterators to wait
      on a nascent superblock to either be born or discarded. This patch
      implements a wait_var_event() mechanism allowing iterators to sleep
      until they are woken when the superblock is born or discarded.
      
      This also allows us to avoid relooping through @fs_supers and
      @super_blocks if a superblock isn't yet born or dying.
      
      Link: aca740ce
      
       ("fs: open block device after superblock creation")
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Message-Id: <20230818-vfs-super-fixes-v3-v3-3-9f0b1876e46b@kernel.org>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      5e874914
  4. Aug 21, 2023
  5. Aug 11, 2023
  6. Aug 10, 2023