Skip to content
Snippets Groups Projects
  1. Sep 17, 2024
  2. Aug 20, 2024
    • Deven Bowers's avatar
      block,lsm: add LSM blob and new LSM hooks for block devices · b55d26bd
      Deven Bowers authored
      
      This patch introduces a new LSM blob to the block_device structure,
      enabling the security subsystem to store security-sensitive data related
      to block devices. Currently, for a device mapper's mapped device containing
      a dm-verity target, critical security information such as the roothash and
      its signing state are not readily accessible. Specifically, while the
      dm-verity volume creation process passes the dm-verity roothash and its
      signature from userspace to the kernel, the roothash is stored privately
      within the dm-verity target, and its signature is discarded
      post-verification. This makes it extremely hard for the security subsystem
      to utilize these data.
      
      With the addition of the LSM blob to the block_device structure, the
      security subsystem can now retain and manage important security metadata
      such as the roothash and the signing state of a dm-verity by storing them
      inside the blob. Access decisions can then be based on these stored data.
      
      The implementation follows the same approach used for security blobs in
      other structures like struct file, struct inode, and struct superblock.
      The initialization of the security blob occurs after the creation of the
      struct block_device, performed by the security subsystem. Similarly, the
      security blob is freed by the security subsystem before the struct
      block_device is deallocated or freed.
      
      This patch also introduces a new hook security_bdev_setintegrity() to save
      block device's integrity data to the new LSM blob. For example, for
      dm-verity, it can use this hook to expose its roothash and signing state
      to LSMs, then LSMs can save these data into the LSM blob.
      
      Please note that the new hook should be invoked every time the security
      information is updated to keep these data current. For example, in
      dm-verity, if the mapping table is reloaded and configured to use a
      different dm-verity target with a new roothash and signing information,
      the previously stored data in the LSM blob will become obsolete. It is
      crucial to re-invoke the hook to refresh these data and ensure they are up
      to date. This necessity arises from the design of device-mapper, where a
      device-mapper device is first created, and then targets are subsequently
      loaded into it. These targets can be modified multiple times during the
      device's lifetime. Therefore, while the LSM blob is allocated during the
      creation of the block device, its actual contents are not initialized at
      this stage and can change substantially over time. This includes
      alterations from data that the LSM 'trusts' to those it does not, making
      it essential to handle these changes correctly. Failure to address this
      dynamic aspect could potentially allow for bypassing LSM checks.
      
      Signed-off-by: default avatarDeven Bowers <deven.desai@linux.microsoft.com>
      Signed-off-by: default avatarFan Wu <wufan@linux.microsoft.com>
      [PM: merge fuzz, subject line tweaks]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      b55d26bd
  3. Jun 20, 2024
  4. Jun 16, 2024
  5. May 03, 2024
  6. May 02, 2024
  7. Apr 18, 2024
  8. Apr 11, 2024
  9. Apr 07, 2024
    • Christian Brauner's avatar
      fs: claw back a few FMODE_* bits · 210a03c9
      Christian Brauner authored
      There's a bunch of flags that are purely based on what the file
      operations support while also never being conditionally set or unset.
      IOW, they're not subject to change for individual files. Imho, such
      flags don't need to live in f_mode they might as well live in the fops
      structs itself. And the fops struct already has that lonely
      mmap_supported_flags member. We might as well turn that into a generic
      fop_flags member and move a few flags from FMODE_* space into FOP_*
      space. That gets us four FMODE_* bits back and the ability for new
      static flags that are about file ops to not have to live in FMODE_*
      space but in their own FOP_* space. It's not the most beautiful thing
      ever but it gets the job done. Yes, there'll be an additional pointer
      chase but hopefully that won't matter for these flags.
      
      I suspect there's a few more we can move into there and that we can also
      redirect a bunch of new flag suggestions that follow this pattern into
      the fop_flags field instead of f_mode.
      
      Link: https://lore.kernel.org/r/20240328-gewendet-spargel-aa60a030ef74@brauner
      
      
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Reviewed-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      210a03c9
  10. Mar 27, 2024
    • Christian Brauner's avatar
      fs,block: yield devices early · 22650a99
      Christian Brauner authored
      Currently a device is only really released once the umount returns to
      userspace due to how file closing works. That ultimately could cause
      an old umount assumption to be violated that concurrent umount and mount
      don't fail. So an exclusively held device with a temporary holder should
      be yielded before the filesystem is gone. Add a helper that allows
      callers to do that. This also allows us to remove the two holder ops
      that Linus wasn't excited about.
      
      Link: https://lore.kernel.org/r/20240326-vfs-bdev-end_holder-v1-1-20af85202918@kernel.org
      
      
      Fixes: f3a60882 ("bdev: open block device as files") # mainline only
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Suggested-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      22650a99
    • Christian Brauner's avatar
      block: count BLK_OPEN_RESTRICT_WRITES openers · 3ff56e28
      Christian Brauner authored
      The original changes in v6.8 do allow for a block device to be reopened
      with BLK_OPEN_RESTRICT_WRITES provided the same holder is used as per
      bdev_may_open(). I think this has a bug.
      
      The first opener @f1 of that block device will set bdev->bd_writers to
      -1. The second opener @f2 using the same holder will pass the check in
      bdev_may_open() that bdev->bd_writers must not be greater than zero.
      
      The first opener @f1 now closes the block device and in bdev_release()
      will end up calling bdev_yield_write_access() which calls
      bdev_writes_blocked() and sets bdev->bd_writers to 0 again.
      
      Now @f2 holds a file to that block device which was opened with
      exclusive write access but bdev->bd_writers has been reset to 0.
      
      So now @f3 comes along and succeeds in opening the block device with
      BLK_OPEN_WRITE betraying @f2's request to have exclusive write access.
      
      This isn't a practical issue yet because afaict there's no codepath
      inside the kernel that reopenes the same block device with
      BLK_OPEN_RESTRICT_WRITES but it will be if there is.
      
      Fix this by counting the number of BLK_OPEN_RESTRICT_WRITES openers. So
      we only allow writes again once all BLK_OPEN_RESTRICT_WRITES openers are
      done.
      
      Link: https://lore.kernel.org/r/20240323-abtauchen-klauen-c2953810082d@brauner
      
      
      Fixes: ed5cc702 ("block: Add config option to not allow writing to mounted devices")
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      3ff56e28
    • Christian Brauner's avatar
      block: handle BLK_OPEN_RESTRICT_WRITES correctly · ddd65e19
      Christian Brauner authored
      Last kernel release we introduce CONFIG_BLK_DEV_WRITE_MOUNTED. By
      default this option is set. When it is set the long-standing behavior
      of being able to write to mounted block devices is enabled.
      
      But in order to guard against unintended corruption by writing to the
      block device buffer cache CONFIG_BLK_DEV_WRITE_MOUNTED can be turned
      off. In that case it isn't possible to write to mounted block devices
      anymore.
      
      A filesystem may open its block devices with BLK_OPEN_RESTRICT_WRITES
      which disallows concurrent BLK_OPEN_WRITE access. When we still had the
      bdev handle around we could recognize BLK_OPEN_RESTRICT_WRITES because
      the mode was passed around. Since we managed to get rid of the bdev
      handle we changed that logic to recognize BLK_OPEN_RESTRICT_WRITES based
      on whether the file was opened writable and writes to that block device
      are blocked. That logic doesn't work because we do allow
      BLK_OPEN_RESTRICT_WRITES to be specified without BLK_OPEN_WRITE.
      
      Fix the detection logic and use an FMODE_* bit. We could've also abused
      O_EXCL as an indicator that BLK_OPEN_RESTRICT_WRITES has been requested.
      For userspace open paths O_EXCL will never be retained but for internal
      opens where we open files that are never installed into a file
      descriptor table this is fine. But it would be a gamble that this
      doesn't cause bugs. Note that BLK_OPEN_RESTRICT_WRITES is an internal
      only flag that cannot directly be raised by userspace. It is implicitly
      raised during mounting.
      
      Passes xftests and blktests with CONFIG_BLK_DEV_WRITE_MOUNTED set and
      unset.
      
      Link: https://lore.kernel.org/r/ZfyyEwu9Uq5Pgb94@casper.infradead.org
      Link: https://lore.kernel.org/r/20240323-zielbereich-mittragen-6fdf14876c3e@brauner
      
      
      Fixes: 321de651 ("block: don't rely on BLK_OPEN_RESTRICT_WRITES when yielding write access")
      Reviewed-by: default avatarYu Kuai <yukuai3@huawei.com>
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Reported-by: default avatarMatthew Wilcox <willy@infradead.org>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      ddd65e19
  11. Mar 18, 2024
  12. Feb 25, 2024
  13. Feb 24, 2024
  14. Dec 28, 2023
  15. Nov 20, 2023
  16. Nov 18, 2023
  17. Oct 28, 2023
Loading