All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Windsor" <dwindsor@gmail.com>
Cc: bpf@vger.kernel.org, paul@paul-moore.com
Subject: Re: [PATCH bpf-next v3 1/2] bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling
Date: Thu, 18 Jun 2026 20:43:34 +0000	[thread overview]
Message-ID: <20260618204335.1AD241F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260618203411.73917-2-dwindsor@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf_init_inode_xattr incorrectly uses GFP_KERNEL when allocating xattr_value inside the inode_init_security hook, which can trigger filesystem reclaim deadlocks.
--

commit 90409fcd43737306bcca3704874f44073960a65f
Author: David Windsor <dwindsor@gmail.com>

bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling

This commit adds the bpf_init_inode_xattr() kfunc for BPF LSM programs to
atomically set xattrs via the inode_init_security hook. It updates the hook
interface to use a single xattr_ctx context object rather than separate
arrays and counts.

Link: https://kernsec.org/pipermail/linux-security-module-archive/2022-October/034878.html [1]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6bcdfd2cac55 [2]

> diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
> index 768aca2dc0f03..7abc3f3d1a678 100644
> --- a/fs/bpf_fs_kfuncs.c
> +++ b/fs/bpf_fs_kfuncs.c
[ ... ]
> @@ -374,6 +375,97 @@ __bpf_kfunc struct inode *bpf_real_inode(struct dentry *dentry)
[ ... ]
> +static int __bpf_init_inode_xattr(struct xattr_ctx *xattr_ctx,
> +				  const char *name__str,
> +				  const struct bpf_dynptr *value_p)
> +{
[ ... ]
> +	value = __bpf_dynptr_data(value_ptr, value_len);
> +	if (!value)
> +		return -EINVAL;
> +
> +	/* Combine xattr value + name into one allocation. */
> +	xattr_value = kmalloc(value_len + name_len + 1, GFP_KERNEL);

[Severity: High]
Can this cause a filesystem transaction deadlock?

The inode_init_security hook is called during inode creation, which often
happens while filesystems like ext4 or btrfs hold critical filesystem locks
or an active journal transaction. 

If kmalloc is called with GFP_KERNEL here, the memory allocator can enter
direct reclaim. The reclaim path may re-enter the filesystem to write back
dirty pages or shrink caches, attempting to acquire the same locks that are
already held by the active file creation path.

Other LSMs and the core security framework explicitly use GFP_NOFS during
the inode_init_security hook to avoid these reclaim deadlocks. Should this
allocation use GFP_NOFS instead?

> +	if (!xattr_value)
> +		return -ENOMEM;
> +
> +	memcpy(xattr_value, value, value_len);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260618203411.73917-1-dwindsor@gmail.com?part=1

  reply	other threads:[~2026-06-18 20:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-18 20:34 [PATCH bpf-next v3 0/2] bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling David Windsor
2026-06-18 20:34 ` [PATCH bpf-next v3 1/2] " David Windsor
2026-06-18 20:43   ` sashiko-bot [this message]
2026-06-18 21:22   ` bot+bpf-ci
2026-06-18 22:50     ` David Windsor
2026-06-18 20:34 ` [PATCH bpf-next v3 2/2] selftests/bpf: add tests for bpf_init_inode_xattr kfunc David Windsor
2026-06-18 20:45   ` sashiko-bot

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=20260618204335.1AD241F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dwindsor@gmail.com \
    --cc=paul@paul-moore.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.