Skip to contentSkip to conversation

fcntl: recheck signal permissions before falling back to SIGIO

PATCH New Shi Lecun 2 participants 4 messages Nov 23 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

Shi Lecun

author
#1 lore raw

PATCH v2 1/2 fcntl: recheck signal permissions before falling back to SIGIO

In reply to a message not in the archive

F_SETSIG allows a file owner to request a signal other than SIGIO. send_sigio_to_task() checks permission for the configured signal, but if queuing fails, it falls back to SIGIO without checking permission for the fallback. An LSM can grant different permissions for the two signals.

Recheck permission before falling back from a different signal to SIGIO. Keep the existing behavior when SIGIO itself has already been checked.

---
 fs/fcntl.c | 3 +++
 1 file changed, 3 insertions(+)
fs/fcntl.c +3 -0
index 07fe32330bec..320cdb0c6780 100644
@@ -905,6 +905,9 @@ static void send_sigio_to_task(struct task_struct *p,
 			si.si_fd    = fd;
 			if (!do_send_sig_info(signum, &si, p, type))
 				break;
+			/* The fallback signal may have different permissions. */
+			if (signum != SIGIO && !sigio_perm(p, fown, SIGIO))
+				break;
 		}
 			fallthrough;	/* fall back on the old plain SIGIO signal */
 		case 0:
Signature · 1 line
2.56.1
author
#3 lore raw

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

In reply to a message not in the archive

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")
---
 security/apparmor/lsm.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
security/apparmor/lsm.c +8 -3
index eaebc3c60c5a..c5f4abc4eab8 100644
@@ -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),
Signature · 1 line
2.56.1
#4 lore raw

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

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] apparmor: nonexistent fown->cred access in apparmor_file_send_sigiotask() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] apparmor: nonexistent fown->cred access in apparmor_file_send_sigiotask()
--

commit adb1f63ac0d010cf15636cb43e53dd9299246228
Author: Shi Lecun <[email protected]>

apparmor: mediate file-generated signals

This commit adds a file_send_sigiotask hook to AppArmor to mediate file-generated SIGIO and SIGURG notifications.

Quoted 4 lines
security/apparmor/lsm.c +0 -0
index d502ad0ac26f5..1a6e49bd50311 100644

[ ... ]

security/apparmor/lsm.c static int apparmor_task_kill(struct task_struct *target, struct kernel_siginfo · line 1052

Quoted 10 lines
security/apparmor/lsm.c +6 -0
@@ -1047,6 +1044,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);
+}

[Severity: High]
Does this compile when CONFIG_SECURITY_APPARMOR is enabled?

struct fown_struct has no cred member; __f_setown() only records uid and euid on f_owner and calls security_file_set_fowner(filp) so LSMs can store the file owner context in their file security blob via fown->file.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/54EBCABD3ACBF0A5+9d780112081161e2f99fe501c2c38f1614a68a42.1795434950.git.shilc2025@mail.sustech.edu.cn?part=2
#2 lore raw
In reply to Shi Lecun
Sashiko has finished reviewing this 2-patch series:

Sashiko has finished reviewing this 2-patch series:

- Patch 1: no issues found.
- Patch 2 ("apparmor: mediate file-generated signals"): 1 potential issue (1 High)

A detailed review has been sent as a separate reply to patch 2.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/54EBCABD3ACBF0A5+9d780112081161e2f99fe501c2c38f1614a68a42.1795434950.git.shilc2025@mail.sustech.edu.cn