BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Anton Protopopov" <a.s.protopopov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH v2 bpf-next 4/6] bpf: Let sleepable LSM programs attach to six more inode hooks
Date: Fri, 04 Dec 2026 16:13:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-250168@kernel.org> (raw)
In-Reply-To: <20261204155438.1413411-5-a.s.protopopov@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] bpf: bpf_real_data_inode() can nest OVL_I()->lock on new
  sleepable LSM hooks
- [High] bpf: missing inode_mkdir and inode_link in
  bpf_ima_inode_hash_denied_hooks
--

commit 83267828169188f48079e5f449fe1b875d3553b4
Author: Anton Protopopov <a.s.protopopov@gmail.com>

bpf: Let sleepable LSM programs attach to six more inode hooks

This patch adds inode_mkdir, inode_link, inode_set_acl, inode_remove_acl,
inode_file_setattr, and inode_copy_up to sleepable_lsm_hooks, updates
d_inode_locked_hooks for the ACL and file_setattr hooks, and restricts
xattr setters and IMA hash helpers on inode_copy_up.

> diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
> index a512d449b54d9..6021e9f60ad28 100644
> --- a/fs/bpf_fs_kfuncs.c
> +++ b/fs/bpf_fs_kfuncs.c

[ ... ]

> @@ -539,8 +548,12 @@ static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id)
>  			return -EACCES;
>  		return 0;
>  	}
> -	if (prog->type == BPF_PROG_TYPE_LSM)
> +	if (prog->type == BPF_PROG_TYPE_LSM) {
> +		if (btf_id_set_contains(&bpf_fs_kfunc_lsm_only_ids, kfunc_id) &&
> +		    btf_id_set_contains(&bpf_xattr_read_only_hooks, prog->aux->attach_btf_id))
> +			return -EACCES;
>  		return 0;
> +	}
>  	if (prog->type != BPF_PROG_TYPE_STRUCT_OPS)
>  		return -EACCES;
>  	/* ->st_ops is unset during the cfg pass; enforced once it is set. */

[Severity: High]
Can sleepable LSM programs on bpf_lsm_inode_link and bpf_lsm_inode_copy_up
still call bpf_real_data_inode() and deadlock on OVL_I(inode)->lock?

bpf_fs_kfuncs_filter() only denies xattr setters on inode_copy_up, leaving
bpf_real_data_inode() allowed on both newly sleepable hooks.  On overlayfs
mounted with metacopy=on and verity=on, a metadata-only copy-up in
ovl_copy_up_tmpfile() or ovl_copy_up_workdir() sets OVL_HAS_DIGEST, clears
OVL_VERIFIED_DIGEST, and leaves OVL_UPPERDATA unset.

When a process executing such an fs-verity lower file calls link() on its
own executable, it self-deadlocks if a sleepable inode_link program calls
bpf_real_data_inode(bpf_get_task_exe_file(current)):

ovl_link()
  ovl_copy_up(old)        /* metacopy: clears OVL_VERIFIED_DIGEST */
  ovl_nlink_start(old)    /* locks OVL_I(inode)->lock */
  ovl_do_link() -> vfs_link() -> security_inode_link()
    bpf_real_data_inode(bpf_get_task_exe_file(current))
      ovl_d_real() -> ovl_maybe_validate_verity()
        ovl_inode_lock_interruptible(inode)  <-- self-deadlock

Two tasks concurrently linking each other's executables can also
ABBA-deadlock on their OVL_I()->lock mutexes.  On bpf_lsm_inode_copy_up,
ovl_copy_up_one() holds OVL_I()->lock of the target file across
security_inode_copy_up(), so calling bpf_real_data_inode() on a metacopied
executable nests another OVL_I()->lock of the same lockdep class and
triggers a recursive-locking violation.

Should bpf_fs_kfuncs_filter() also reject bpf_real_data_inode() on hooks
that can run under OVL_I()->lock?

[ ... ]

> diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
> index 6c79d4786f675..c4b626b0dbdac 100644
> --- a/kernel/bpf/bpf_lsm.c
> +++ b/kernel/bpf/bpf_lsm.c
> @@ -200,6 +200,7 @@ BPF_CALL_3(bpf_ima_inode_hash, struct inode *, inode, void *, dst, u32, size)
>  
>  /* Hooks which may be called with the inode locked or with iint->mutex held */
>  BTF_SET_START(bpf_ima_inode_hash_denied_hooks)
> +BTF_ID(func, bpf_lsm_inode_copy_up)
>  BTF_ID(func, bpf_lsm_inode_getattr)
>  BTF_ID(func, bpf_lsm_inode_getxattr)
>  BTF_SET_END(bpf_ima_inode_hash_denied_hooks)

[Severity: High]
Should bpf_lsm_inode_mkdir and bpf_lsm_inode_link also be added to
bpf_ima_inode_hash_denied_hooks?

Both hooks are added to sleepable_lsm_hooks without being in
d_inode_locked_hooks or bpf_ima_inode_hash_denied_hooks, so
bpf_ima_inode_hash_allowed() now permits bpf_ima_inode_hash() and
bpf_ima_file_hash() there.  However, the same IMA-triggered overlayfs
copy-up path holds iint->mutex into both hooks: ovl_copy_up_workdir() ->
ovl_create_real() -> vfs_mkdir() -> security_inode_mkdir() when copying up
lower-only ancestor directories, and ovl_copy_up_tmpfile() -> ovl_do_link()
-> vfs_link() -> security_inode_link() when linking the copied-up file.

With IMA or EVM appraisal in fix mode, a sleepable LSM program on either
hook that calls bpf_ima_file_hash() or bpf_ima_inode_hash() (for example on
bpf_get_task_exe_file(current)) causes an ABBA deadlock with the upper
directory's i_rwsem:

CPU0                              CPU1
----                              ----
lock(&iint->mutex)
                                  lock(&upperdir->i_rwsem)
lock(&upperdir->i_rwsem)
                                  lock(&iint->mutex)

 *** DEADLOCK ***

CPU0: process_measurement() -> ima_fix_xattr() -> ovl_copy_up()
      -> ovl_copy_up_tmpfile() -> ovl_do_link()
CPU1: ovl_link() -> ovl_start_creating_upper() -> vfs_link()
      -> security_inode_link() -> bpf_ima_file_hash()

It also self-deadlocks directly on iint->mutex when a task triggers
appraisal on its own lower-only overlayfs executable.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204155438.1413411-1-a.s.protopopov@gmail.com?part=4

  reply	other threads:[~2026-12-04 16:13 UTC|newest]

Thread overview: 14+ 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:07   ` sashiko-bot
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
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 16:13   ` sashiko-bot [this message]
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 16:09   ` sashiko-bot
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=sashiko-outbox-250168@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=a.s.protopopov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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