git: 1947932d6f4f - main - capsicum: Add tests for sched_* and rtprio*

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

URL: https://cgit.FreeBSD.org/src/commit/?id=1947932d6f4f7afa678c3e2369e6a6ee919702e1

commit 1947932d6f4f7afa678c3e2369e6a6ee919702e1
Author:     Osvaldo Janeri Filho <ojanerif@amd.com>
AuthorDate: 2026-11-12 15:16:29 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2026-11-13 15:51:30 +0000

    capsicum: Add tests for sched_* and rtprio*
    
    Commit 70d08c69f4d0 ("p1003_1b: Add capability mode checks") added
    missing capability mode checks to sched_* syscalls, and commit
    9b6ea599c955 ("rtprio*: Add capability mode checks") added them to
    rtprio*.
    
    Reviewed by: olce, emaste
    Sponsored by: Advanced Micro Devices, Inc.
    Signed-off-by: Osvaldo Janeri Filho <ojanerif@amd.com>
    Differential Revision: https://reviews.freebsd.org/D61412
---
 tests/sys/capsicum/capmode.cc | 45 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/tests/sys/capsicum/capmode.cc b/tests/sys/capsicum/capmode.cc
index 4cf6f24420e3..d19477e956e5 100644
--- a/tests/sys/capsicum/capmode.cc
+++ b/tests/sys/capsicum/capmode.cc
@@ -10,6 +10,8 @@
 #include <sys/wait.h>
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <sys/rtprio.h>
+#include <sys/thr.h>
 #include <sys/ptrace.h>
 #include <dirent.h>
 #include <net/if.h>
@@ -732,3 +734,46 @@ FORK_TEST(Capmode, SelfKill) {
 
   signal(SIGUSR1, original);
 }
+
+FORK_TEST(Capmode, SelfSched) {
+  pid_t me = getpid();
+  long my_tid, child_tid;
+  int pipefds[2];
+
+  EXPECT_OK(thr_self(&my_tid));
+  EXPECT_OK(pipe(pipefds));
+  pid_t child = fork();
+  if (child == 0) {
+    // Child: report thread ID, sleep and exit
+    thr_self(&child_tid);
+    write(pipefds[1], &child_tid, sizeof(child_tid));
+    sleep(1);
+    exit(0);
+  }
+  EXPECT_EQ((ssize_t)sizeof(child_tid),
+            read(pipefds[0], &child_tid, sizeof(child_tid)));
+
+  EXPECT_OK(cap_enter());  // Enter capability mode.
+
+  // Can only query or modify scheduling parameters of own pid.
+  struct sched_param sp;
+  EXPECT_CAPMODE(sched_getparam(child, &sp));
+  EXPECT_OK(sched_getparam(me, &sp));
+  EXPECT_CAPMODE(sched_setparam(child, &sp));
+  EXPECT_CAPMODE(sched_getscheduler(child));
+  int policy = sched_getscheduler(me);
+  EXPECT_OK(policy);
+  EXPECT_CAPMODE(sched_setscheduler(child, policy, &sp));
+  struct timespec ts;
+  EXPECT_CAPMODE(sched_rr_get_interval(child, &ts));
+  EXPECT_OK(sched_rr_get_interval(me, &ts));
+
+  struct rtprio rtp;
+  EXPECT_CAPMODE(rtprio(RTP_LOOKUP, child, &rtp));
+  EXPECT_OK(rtprio(RTP_LOOKUP, me, &rtp));
+  EXPECT_CAPMODE(rtprio_thread(RTP_LOOKUP, child_tid, &rtp));
+  EXPECT_OK(rtprio_thread(RTP_LOOKUP, my_tid, &rtp));
+
+  close(pipefds[0]);
+  close(pipefds[1]);
+}