]> git.ipfire.org Git - thirdparty/linux.git/commit
bpf: classify block device hooks appropriately
authorChristian Brauner <brauner@kernel.org>
Thu, 26 Mar 2026 16:09:14 +0000 (17:09 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 27 Mar 2026 16:05:13 +0000 (09:05 -0700)
commit46df585fcff7a0de75c3752becc451934927db29
tree8037a7b400ba481fba1164610496357fa63a08d5
parent01504da43e67f823fbd22f4ec9e4469236a34b5c
bpf: classify block device hooks appropriately

A bunch of new hooks for managing block devices were added a while ago
but they weren't actually appropriately classified.

* bpf_lsm_bdev_alloc() is called when the inode for the block
  device is allocated. This happens from a sleepable context so mark the
  function as sleepable. When this function is called the memory for the
  block device storage embedded into the inode is zeroed. That block
  device cannot be meaningfully reference or interacted with at this
  point. So mark it as untrusted for now.

* bpf_lsm_bdev_free() is called when the inode for the block
  device is freed. A bunch of memory associated with the block device
  has already been freed and there's dangling pointers in there. So mark
  it as untrusted. It cannot be meaningfully referenced or interacted
  with anymore. It is also called from sb->s_op->free_inode:: which
  means it runs in rcu context (most of the times). So leave it as
  non-sleepable.

* bpf_lsm_bdev_setintegrity() is called when a dm-verity device
  is instantiated (glossing over details for simplicity of the commit
  message). The block device is very much alive so it remains a trusted
  hook. It's also called with device mapper's suspend lock held and so
  the hook is able to sleep so mark it sleepable.

Signed-off-by: Christian Brauner <brauner@kernel.org>
Link: https://lore.kernel.org/r/20260326-work-bpf-bdev-v2-1-5e3c58963987@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/bpf_lsm.c