mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	KP Singh <kpsingh@kernel.org>,
	Matt Bobrowski <matt@bobrowski.net>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	Mimi Zohar <zohar@linux.ibm.com>,
	Roberto Sassu <roberto.sassu@huawei.com>,
	bpf@vger.kernel.org, linux-integrity@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Anton Protopopov <a.s.protopopov@gmail.com>
Subject: [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 15:54:33 +0000	[thread overview]
Message-ID: <20261204155438.1413411-4-a.s.protopopov@gmail.com> (raw)
In-Reply-To: <20261204155438.1413411-1-a.s.protopopov@gmail.com>

The bpf_ima_inode_hash() and bpf_ima_file_hash() helpers are allowed
on every sleepable LSM hook. Both take iint->mutex in
__ima_inode_hash(). IMA itself takes iint->mutex before the inode
lock: process_measurement() holds it and locks the inode to appraise
the file. IMA also holds it while it sets security.ima in
ima_fix_xattr() and ima_update_xattr().

So a program which calls the helpers on a hook called with the inode
locked can deadlock. On inode_setxattr, inode_removexattr,
inode_setattr, inode_unlink, path_chmod or path_chown it waits for
iint->mutex, while a concurrent open of the file holds it and waits
for the inode lock. On inode_post_setxattr it may wait for
iint->mutex which the task itself holds when IMA sets security.ima.

These hooks are in d_inode_locked_hooks. Don't allow the helpers
there.

Fixes: 27672f0d280a ("bpf: Add a BPF helper for getting the IMA hash of an inode")
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
 kernel/bpf/bpf_lsm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
index 608d188ffe0e..6c79d4786f67 100644
--- 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);
 }
-- 
2.43.0


  parent reply	other threads:[~2026-12-04 15:43 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 ` Anton Protopopov [this message]
2026-12-04 16:15   ` [PATCH v2 bpf-next 3/6] bpf: Don't allow the IMA hash helpers on hooks with the inode locked bot+bpf-ci
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=20261204155438.1413411-4-a.s.protopopov@gmail.com \
    --to=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@linux.dev \
    --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®