From: bot+bpf-ci@kernel.org
To: a.s.protopopov@gmail.com,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,kpsingh@kernel.org,matt@bobrowski.net,viro@zeniv.linux.org.uk,brauner@kernel.org,jack@suse.cz,zohar@linux.ibm.com,roberto.sassu@huawei.com,bpf@vger.kernel.org,linux-integrity@vger.kernel.org,linux-fsdevel@vger.kernel.org,linux-kernel@vger.kernel.org
Cc: a.s.protopopov@gmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH v2 bpf-next 3/6] bpf: Don't allow the IMA hash helpers on hooks with the inode locked
Date: Fri, 4 Dec 2026 16:15:36 +0000 (UTC) [thread overview]
Message-ID: <182aad0008425e31fe08c4e1f68117ac89af5ab75db88ed83148037b23bccc2f@mail.kernel.org> (raw)
In-Reply-To: <20261204155438.1413411-4-a.s.protopopov@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3148 bytes --]
> 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
next prev parent reply other threads:[~2026-12-04 16:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 15:54 [PATCH v2 bpf-next 0/6] bpf: Use the xattr kfuncs on six more inode hooks Anton Protopopov
2026-12-04 15:54 ` [PATCH v2 bpf-next 1/6] bpf: Add path_chmod and path_chown to d_inode_locked_hooks Anton Protopopov
2026-12-04 15:54 ` [PATCH v2 bpf-next 2/6] bpf: Don't allow the IMA helpers on inode_getxattr and inode_getattr Anton Protopopov
2026-12-04 16:15 ` bot+bpf-ci
2026-12-04 15:54 ` [PATCH v2 bpf-next 3/6] bpf: Don't allow the IMA hash helpers on hooks with the inode locked Anton Protopopov
2026-12-04 16:15 ` bot+bpf-ci [this message]
2026-12-04 15:54 ` [PATCH v2 bpf-next 4/6] bpf: Let sleepable LSM programs attach to six more inode hooks Anton Protopopov
2026-12-04 15:54 ` [PATCH v2 bpf-next 5/6] bpf: Add a bpf_get_inode_xattr kfunc Anton Protopopov
2026-12-04 15:54 ` [PATCH v2 bpf-next 6/6] selftests/bpf: Test xattr kfuncs on the new sleepable inode hooks Anton Protopopov
2026-12-04 19:48 ` [PATCH v2 bpf-next 0/6] bpf: Use the xattr kfuncs on six more " Alexei Starovoitov
2026-12-04 19:59 ` Anton Protopopov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=182aad0008425e31fe08c4e1f68117ac89af5ab75db88ed83148037b23bccc2f@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=a.s.protopopov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jack@suse.cz \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=matt@bobrowski.net \
--cc=memxor@gmail.com \
--cc=roberto.sassu@huawei.com \
--cc=song@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=yonghong.song@linux.dev \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®