Re: [PATCH v2 bpf-next 3/6] bpf: Don't allow the IMA hash helpers on hooks with the inode locked
From: bot+bpf-ci
Date: Fri Dec 04 2026 - 11:16:08 EST
> bpf: Don't allow the IMA hash helpers on hooks with the inode locked
TL;DR: Possible self-deadlock on iint->mutex remains: a sleepable file_open
BPF LSM program calling the IMA hash helpers from IMA's own dentry_open() may
block, and file_open isn't denied by this patch.
> diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
> --- a/kernel/bpf/bpf_lsm.c
> +++ b/kernel/bpf/bpf_lsm.c
[ ... ]
> @@ -207,6 +207,7 @@ BTF_SET_END(bpf_ima_inode_hash_denied_hooks)
> static bool bpf_ima_inode_hash_allowed(const struct bpf_prog *prog)
> {
> return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id) &&
> + !bpf_lsm_has_d_inode_locked(prog) &&
> !btf_id_set_contains(&bpf_ima_inode_hash_denied_hooks,
> prog->aux->attach_btf_id);
> }
The commit message says inode_post_setxattr can wait for iint->mutex
"which the task itself holds when IMA sets security.ima". Is
inode_post_setxattr the only hook where that self-deadlock can happen?
While IMA holds iint->mutex in ima_update_xattr(), it calls
ima_collect_measurement() before ima_fix_xattr(), and for a writer without
FMODE_READ ima_calc_file_hash() opens a new file instance:
/* Open a new file instance in O_RDONLY if we cannot read */
if (!(file->f_mode & FMODE_READ)) {
...
f = dentry_open(&file->f_path, flags, file->f_cred);
dentry_open() reaches security_file_open() through vfs_open() and
do_dentry_open(), which runs a sleepable BPF LSM program attached to
file_open. file_open is not in d_inode_locked_hooks and is not in
bpf_ima_inode_hash_denied_hooks, so the helpers are still allowed there.
The helper then reaches __ima_inode_hash():
iint = ima_iint_find(inode);
if (iint)
mutex_lock(&iint->mutex);
which finds the iint whose mutex the task already holds:
__fput()
security_file_release()
ima_file_free()
ima_check_last_writer()
mutex_lock(&iint->mutex)
ima_update_xattr()
ima_collect_measurement()
ima_calc_file_hash()
dentry_open()
do_dentry_open()
security_file_open()
bpf_lsm_file_open
bpf_ima_file_hash()
__ima_inode_hash()
mutex_lock(&iint->mutex)
The same can happen from process_measurement(), which holds iint->mutex
and calls ima_collect_measurement(), for an O_WRONLY open matched by an
appraise rule with no mask, such as the fowner=0 rule of
ima_policy=appraise_tcb. In that case the mutex stays held, so later opens
of the file also block in process_measurement().
file_open was already sleepable when 27672f0d280a added the helper, and
the later commits in this series do not seem to cover it.
Could the changelog or the deny logic deal with file_open as well, for
example when the hook runs from IMA's own dentry_open() in
ima_calc_file_hash()?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47369735357