git: 9b6ea599c955 - main - rtprio*: Add capability mode checks

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Thu, 12 Nov 2026 15:13:09 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=9b6ea599c955cfdffac0a5e0204f57a72e6f7cda

commit 9b6ea599c955cfdffac0a5e0204f57a72e6f7cda
Author:     Osvaldo Janeri Filho <ojanerif@amd.com>
AuthorDate: 2026-11-12 15:05:10 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2026-11-12 15:12:49 +0000

    rtprio*: Add capability mode checks
    
    These syscalls are allowed in capability mode but accept an arbitrary
    pid or lwpid.  Restrict them to the calling process in capability mode.
    
    In capability mode rtprio_thread(2) only looks up threads of the
    calling process, and returns ECAPMODE for any other lwpid, including
    one that does not exist.
    
    Sponsored by: Advanced Micro Devices, Inc.
    Signed-off-by: Osvaldo Janeri Filho <ojanerif@amd.com>
    Reviewed by:    olce
---
 sys/kern/kern_resource.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index cd3929ac8ea4..10f9e2e68480 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -336,6 +336,11 @@ kern_rtprio_thread(struct thread *td, int function, lwpid_t lwpid,
 		p = td->td_proc;
 		td1 = td;
 		PROC_LOCK(p);
+	} else if (IN_CAPABILITY_MODE(td)) {
+		td1 = tdfind(lwpid, td->td_proc->p_pid);
+		if (td1 == NULL)
+			return (ECAPMODE);
+		p = td1->td_proc;
 	} else {
 		td1 = tdfind(lwpid, -1);
 		if (td1 == NULL)
@@ -423,6 +428,8 @@ kern_rtprio(struct thread *td, int function, pid_t pid, struct rtprio *urtp)
 		p = td->td_proc;
 		PROC_LOCK(p);
 	} else {
+		if (IN_CAPABILITY_MODE(td) && pid != td->td_proc->p_pid)
+			return (ECAPMODE);
 		p = pfind(pid);
 		if (p == NULL)
 			return (ESRCH);