From: sashiko-bot@kernel.org
To: "HARIHARA SUDHAN. R" <harisudhan@armoriq.io>,
bpf@vger.kernel.org, linux-mm@kvack.org,
linux-security-module@vger.kernel.org
Cc: "Liam R. Howlett" <liam@infradead.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Ben Segall" <bsegall@google.com>,
"David Hildenbrand" <david@kernel.org>,
"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
"Ingo Molnar" <mingo@redhat.com>,
"James Morris" <jmorris@namei.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Juri Lelli" <juri.lelli@redhat.com>,
"K Prateek Nayak" <kprateek.nayak@amd.com>,
"Kees Cook" <kees@kernel.org>,
"Ketan Bhardwaj" <ketan@armoriq.io>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Mel Gorman" <mgorman@suse.de>, "Michal Hocko" <mhocko@suse.com>,
"Mike Rapoport" <rppt@kernel.org>,
"Paul Moore" <paul@paul-moore.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Valentin Schneider" <vschneid@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Vlastimil Babka" <vbabka@kernel.org>
Subject: Re: [RFC PATCH v4 4/6] security: kap: add the securityfs control plane
Date: Mon, 23 Nov 2026 12:03:53 +0000 [thread overview]
Message-ID: <sashiko-outbox-229180@kernel.org> (raw)
In-Reply-To: <20261123114308.8103-5-harisudhan@armoriq.io>
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [Medium] security: kap: dentry reference leak on child files in
kapfs_mkdir()
- [Medium] security: kap: unattached kapfs_mnt resolves as root-relative
in d_path()
- [Medium] security: kap: data race on kap_task_state in
kap_bind_pid_locked()
- [Medium] security: kap: race between kap_bind_pid_locked() and
copy_process()
- [Medium] security: kap: kap_authority_prepare() bounds predicates by
next kind not '}'
- [Medium] security: kap: unbounded igroup->pids growth in kapfs_write()
- [Low] security: kap: kapfs_write() silently succeeds on newline-only
writes
- [Low] security: kap: order-5 allocation and locked strlen() in
kapfs_write()
--
commit 9e7e1166b9d68fb071806f2526682914d4f5f018
Author: HARIHARA SUDHAN. R <harisudhan@armoriq.io>
security: kap: add the securityfs control plane
This commit adds the securityfs control plane under /sys/kernel/security/kap
and mounts an internal kapfs filesystem for creating and configuring igroups.
> diff --git a/security/kap/kapfs.c b/security/kap/kapfs.c
> new file mode 100644
> index 0000000000000..c9f03c2d8c0ac
> --- /dev/null
> +++ b/security/kap/kapfs.c
[ ... ]
> @@ -0,0 +1,530 @@
> +static int kapfs_show(struct seq_file *m, void *v)
> +{
> + struct kap_file_ctx *ctx = m->private;
> + struct kap_igroup *igroup = ctx->igroup;
> + struct kap_bound_pid *entry;
> +
> + spin_lock(&kap_lock);
> + switch (ctx->kind) {
> + case KAP_FILE_PROCS:
> + list_for_each_entry(entry, &igroup->pids, node)
> + seq_printf(m, "%d\n", entry->pid);
> + break;
[Severity: Medium]
Does igroup->pids grow without bound over the lifetime of an igroup?
Every new PID written to kap.procs allocates a struct kap_bound_pid in
kapfs_write() and appends it to igroup->pids in kap_bind_pid_locked(),
but entries are never removed or freed when a task exits in
kap_task_free() or when a task is rebound to another igroup. As
processes are spawned, bound and exit, igroup->pids leaks memory, reports
dead PIDs on kap.procs reads, and linearly walks an ever-growing list
under the global kap_lock spinlock in both kap_pid_in_igroup_locked() and
kapfs_show().
[ ... ]
> +static ssize_t kapfs_write(struct file *file, const char __user *buf, size_t len, loff_t *ppos)
> +{
[ ... ]
> + if (len == 0)
> + return 0;
> + if (len > (ctx->kind == KAP_FILE_INSTALL ? KAP_MAX_INSTALL_BYTES
> + : KAP_MAX_PREDICATE_BYTES))
> + return -EINVAL;
> + if (ctx->kind == KAP_FILE_EVENTS || ctx->kind == KAP_FILE_IGFD)
> + return -EINVAL;
> +
> + tmp = memdup_user_nul(buf, len);
> + if (IS_ERR(tmp))
> + return PTR_ERR(tmp);
> + kap_trim_newline(tmp);
> + if (!tmp[0]) {
> + kfree(tmp);
> + return len;
> + }
[Severity: Low]
Should kapfs_write() silently succeed when the buffer is empty after
stripping trailing newlines?
Writing a newline-only string (such as echo "" > kap.procs or kap.mode)
returns len without validating the input or updating any state, and also
makes it impossible to clear kap.lineage_root via a single-file write
even though kap.install accepts an empty lineage_root= value.
> +
> + /* Parse, allocate and compile first: kap_lock is a spinlock. */
> + switch (ctx->kind) {
[ ... ]
> + case KAP_FILE_INSTALL:
> + rc = kap_install_parse(tmp, &req);
> + if (!rc)
> + rc = kap_authority_prepare(req.authority, &compiled);
> + break;
> + case KAP_FILE_AUTHORITY:
> + rc = kap_authority_prepare(tmp, &compiled);
> + break;
[Severity: Medium]
Can kap_authority_prepare() compile patterns from the next predicate into
an earlier predicate when JSON keys precede "kind"?
Both kap_validate_authority_payload() and kap_compile_kind_array() walk
backward from "kind" to '{' to find predicate_start, but bound
predicate_end by the next "kind" rather than the current object's closing
'}':
security/kap/igroup.c:kap_compile_kind_array() {
...
while ((predicate = kap_next_predicate(predicate, end, kind_name))) {
const char *next = strstr(predicate + 1, "\"kind\":");
const char *predicate_start = predicate;
const char *predicate_end = next && next < end ? next : end;
int rc;
while (predicate_start > auth && *predicate_start != '{')
predicate_start--;
rc = kap_compile_array(compiled, set, predicate_start,
predicate_end, array_name);
...
}
If one predicate omits its "allow" or "deny" array and the following
predicate places "allow" or "deny" before "kind", those arrays fall
inside [predicate_start, predicate_end) of the earlier predicate.
kap_validate_authority_payload() then accepts the malformed predicate and
kap_compile_kind_array() compiles the next predicate's patterns under the
wrong hook kind.
[ ... ]
> + spin_lock(&kap_lock);
> + switch (ctx->kind) {
> + case KAP_FILE_PROCS:
> + rc = kap_bind_pid_locked(igroup, pid, &entry);
> + break;
[Severity: Medium]
Can kap_ptrace_target() observe torn or partially initialized task state
while kap_bind_pid_locked() updates a task?
kap_bind_pid_locked() sets state->active = true before writing
state->epoch and state->igroup_name, while kap_ptrace_target() reads
those fields without holding kap_lock:
CPU0 CPU1
kapfs_write()
spin_lock(&kap_lock)
kap_bind_pid_locked()
state->active = true
kap_ptrace_access_check()
kap_ptrace_target()
if (child_state->active)
strcmp(...,
child_state->igroup_name)
<-- reads empty or torn name
state->epoch = igroup->epoch
strscpy(state->igroup_name, ...)
A concurrent ptrace check can therefore misclassify same-igroup versus
cross-igroup ptrace operations and log a corrupted target string in
kap.events.
[Severity: Medium]
Can a thread or child being created in copy_process() miss the binding
when kap_bind_pid_locked() runs concurrently?
kap_task_alloc() copies the parent's kap_task_state during
security_task_alloc(), long before copy_process() links the new task onto
signal->thread_head under siglock:
CPU0 CPU1
copy_process()
security_task_alloc()
kap_task_alloc()
spin_lock(&kap_lock)
/* old->active is false */
spin_unlock(&kap_lock)
kapfs_write()
spin_lock(&kap_lock)
kap_bind_pid_locked()
for_each_thread(task, t)
state->active = true
spin_unlock(&kap_lock)
write_lock_irq(&tasklist_lock)
list_add_tail_rcu(&p->thread_node,
&p->signal->thread_head)
<-- new task runs with active == false
Because p is not yet on signal->thread_head when for_each_thread() walks
the process, p escapes the igroup binding even though writing to
kap.procs succeeded.
[ ... ]
> + case KAP_FILE_AUTHORITY: {
> + struct kap_compiled_authority *old = igroup->compiled;
> +
> + strscpy(igroup->authority, tmp, sizeof(igroup->authority));
> + igroup->authority_len = strlen(igroup->authority);
> + igroup->compiled = compiled;
> + compiled = old;
> + break;
> + }
[Severity: Low]
Could kapfs_write() avoid the order-5 physically contiguous allocation in
memdup_user_nul() and the extra strlen() pass under kap_lock?
For KAP_FILE_INSTALL and KAP_FILE_AUTHORITY, len can be up to 66,560
bytes, so memdup_user_nul() requests up to 66,561 physically contiguous
bytes (order 5 on 4 KB page kernels, above PAGE_ALLOC_COSTLY_ORDER),
which can stall in direct compaction or fail under fragmentation; using
vmemdup_user() or kvmalloc() would match kvzalloc_obj() in
kap_authority_prepare(). In addition, using the length returned by
strscpy() here (and in kap_install_locked()) avoids rescanning up to 64
KB with strlen() while holding the global kap_lock spinlock.
[ ... ]
> +static void kapfs_instantiate(struct dentry *dentry, struct inode *inode)
> +{
> + d_make_persistent(dentry, inode);
> +}
[ ... ]
> +/* Returns NULL on success: the passed dentry is the one instantiated. */
> +static struct dentry *kapfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
> + struct dentry *dentry, umode_t mode)
> +{
[ ... ]
> + for (i = 0; i < KAP_FILE_COUNT; i++) {
> + files[i] = d_alloc_name(dentry, kap_file_names[i]);
> + inodes[i] = kapfs_make_inode(dir->i_sb, S_IFREG | kap_file_modes[i]);
> + if (!files[i] || !inodes[i]) {
> + rc = -ENOMEM;
> + goto err;
> + }
> + igroup->files[i].kind = i;
> + igroup->files[i].igroup = igroup;
> + inodes[i]->i_fop = &kapfs_fops;
> + inodes[i]->i_private = &igroup->files[i];
> + }
[ ... ]
> + /* Lookups in the new directory wait until its files are all there. */
> + inode_lock(inode);
> + kapfs_instantiate(dentry, inode);
> + igroup->dentry = dentry;
> + for (i = 0; i < KAP_FILE_COUNT; i++)
> + kapfs_instantiate(files[i], inodes[i]);
> + inode_unlock(inode);
> + return NULL;
[Severity: Medium]
Does kapfs_mkdir() leak a dentry reference on every child file in
files[]?
d_alloc_name() returns each files[i] with a reference count of 1, and
kapfs_instantiate() -> d_make_persistent() takes an additional reference
via dget_dlock(). Unlike the directory dentry passed into kapfs_mkdir(),
whose creation reference is dropped by the VFS caller, files[i] is never
passed to dput() after kapfs_instantiate(), leaving each child file with
a reference count of 2 instead of 1.
[ ... ]
> +static const char *kap_igroups_get_link(struct dentry *dentry,
> + struct inode *inode,
> + struct delayed_call *done)
> +{
> + struct path path;
> + int rc;
> +
> + if (!dentry)
> + return ERR_PTR(-ECHILD);
> + path.mnt = mntget(kapfs_mnt);
> + path.dentry = dget(kapfs_mnt->mnt_root);
> + rc = nd_jump_link(&path);
> + return ERR_PTR(rc);
> +}
[ ... ]
> +int __init kap_securityfs_init(void)
> +{
> + struct dentry *dent;
> + int rc;
> +
> + if (!READ_ONCE(kap_lsm_active))
> + return 0;
> +
> + kapfs_mnt = kern_mount(&kapfs_type);
[Severity: Medium]
When a task crosses the igroups symlink via nd_jump_link() onto the
internal kern_mount() vfsmount, won't d_path() resolve files under
/sys/kernel/security/kap/igroups as /<igroup>/<file>?
Because kapfs_mnt is an unattached internal mount with no parent
mountpoint, d_path() in kap_file_target(), kap_lsm_file_path_alloc() and
kap_lsm_check_dir_entry() stops at kapfs_mnt->mnt_root and formats paths
without the /sys/kernel/security/kap/igroups prefix. File policies
written for /sys or /sys/kernel/security/kap will therefore fail to match
accesses under igroups/ (and an igroup named "proc" will be misclassified
as procfs by kap_path_is_procfs()), while kap.events logs root-relative
paths.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123114308.8103-1-harisudhan@armoriq.io?part=4
next prev parent reply other threads:[~2026-11-23 12:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 11:43 [RFC PATCH v4 0/6] security: introduce Kernel Assurance Plane HARIHARA SUDHAN. R
2026-11-23 11:43 ` [RFC PATCH v4 1/6] docs: security: Describe the Kernel Assurance Plane design HARIHARA SUDHAN. R
2026-11-23 11:43 ` [RFC PATCH v4 2/6] security: kap: add the LSM ID and internal headers HARIHARA SUDHAN. R
2026-11-23 11:43 ` [RFC PATCH v4 3/6] security: add the Kernel Assurance Plane LSM HARIHARA SUDHAN. R
2026-11-23 12:08 ` sashiko-bot
2026-11-23 11:43 ` [RFC PATCH v4 4/6] security: kap: add the securityfs control plane HARIHARA SUDHAN. R
2026-11-23 12:03 ` sashiko-bot [this message]
2026-11-23 11:43 ` [RFC PATCH v4 5/6] kernel: add KAP checks for unshare and setns HARIHARA SUDHAN. R
2026-11-23 11:43 ` [RFC PATCH v4 6/6] MAINTAINERS: add an entry for the Kernel Assurance Plane HARIHARA SUDHAN. R
2026-11-23 12:08 ` [RFC PATCH v4 0/6] security: introduce " 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=sashiko-outbox-229180@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bpf@vger.kernel.org \
--cc=bsegall@google.com \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=harisudhan@armoriq.io \
--cc=jmorris@namei.org \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=ketan@armoriq.io \
--cc=kprateek.nayak@amd.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=paul@paul-moore.com \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=serge@hallyn.com \
--cc=skhan@linuxfoundation.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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