[PATCH v2 2/2] apparmor: mediate file-generated signals

From: Shi Lecun

Date: Mon Nov 23 2026 - 07:14:38 EST


File-generated SIGIO and SIGURG notifications use file_send_sigiotask
rather than task_kill. AppArmor does not implement that hook, so its
signal send and receive rules are not enforced on this path.

Implement file_send_sigiotask using the credentials of the task that
set the file owner. The VFS holds those credentials in fown->cred under
fown->lock, which is held during signal delivery. This also supplies the
sender identity when delivery runs in interrupt context.

Reuse the AppArmor signal permission check with the saved credentials
so it resolves both labels and enforces the send and receive rules.
Treat a zero signal argument as SIGIO, as specified by the hook.

Fixes: cd1dbf76b23d ("apparmor: add the ability to mediate signals")
Link: https://lore.kernel.org/all/20261120-unrentabel-bambus-genuss-0db3576a8f57@brauner/
Signed-off-by: Shi Lecun <shilc2025@xxxxxxxxxxxxxxxxxxx>
---
security/apparmor/lsm.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index eaebc3c60c5a..c5f4abc4eab8 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -1031,9 +1031,6 @@ static int apparmor_task_kill(struct task_struct *target, struct kernel_siginfo
tc = get_task_cred(target);
tl = aa_get_newest_cred_label(tc);
if (cred) {
- /*
- * Dealing with USB IO specific behavior
- */
cl = aa_get_newest_cred_label(cred);
error = aa_may_signal(cred, cl, tc, tl, sig);
aa_put_label(cl);
@@ -1048,6 +1045,13 @@ static int apparmor_task_kill(struct task_struct *target, struct kernel_siginfo
return error;
}

+static int apparmor_file_send_sigiotask(struct task_struct *target,
+ struct fown_struct *fown, int sig)
+{
+ lockdep_assert_held(&fown->lock);
+ return apparmor_task_kill(target, NULL, sig ? sig : SIGIO, fown->cred);
+}
+
static int apparmor_userns_create(const struct cred *cred)
{
struct aa_label *label;
@@ -1810,6 +1814,7 @@ static struct security_hook_list apparmor_hooks[] __ro_after_init = {
LSM_HOOK_INIT(file_permission, apparmor_file_permission),
LSM_HOOK_INIT(file_alloc_security, apparmor_file_alloc_security),
LSM_HOOK_INIT(file_free_security, apparmor_file_free_security),
+ LSM_HOOK_INIT(file_send_sigiotask, apparmor_file_send_sigiotask),
LSM_HOOK_INIT(mmap_file, apparmor_mmap_file),
LSM_HOOK_INIT(file_mprotect, apparmor_file_mprotect),
LSM_HOOK_INIT(file_lock, apparmor_file_lock),
--
2.56.1