[LTP] [PATCH v6 1/3] lapi/sched: add SAFE_SCHED_SETATTR()

Andrea Cervesato andrea.cervesato@suse.de
Thu Sep 3 09:26:35 CEST 2026


From: Andrea Cervesato <andrea.cervesato@suse.com>

Add a safe variant of sched_setattr() that breaks the test with TBROK
on failure, so tests such as the CVE-2026-43499 reproducer do not have
to open-code the TEST() + tst_brk() error handling.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/lapi/sched.h | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/include/lapi/sched.h b/include/lapi/sched.h
index 05b322c1c..b068cecbb 100644
--- a/include/lapi/sched.h
+++ b/include/lapi/sched.h
@@ -34,7 +34,7 @@ struct sched_attr {
 	uint64_t sched_period;
 };
 
-static inline int sched_setattr(pid_t pid, const struct sched_attr *attr,
+static inline int sched_setattr(pid_t pid, struct sched_attr *attr,
                                 unsigned int flags)
 {
 	return syscall(__NR_sched_setattr, pid, attr, flags);
@@ -169,4 +169,33 @@ static inline int getcpu(unsigned *cpu, unsigned *node)
 # define CLONE_INTO_CGROUP 0x200000000ULL
 #endif
 
+static inline int safe_sched_setattr(const char *file, const int lineno,
+				     pid_t pid, struct sched_attr *attr,
+				     unsigned int flags)
+{
+	int ret;
+
+	ret = sched_setattr(pid, attr, flags);
+
+	if (ret == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"sched_setattr(%i) failed", pid);
+	}
+
+	return ret;
+}
+
+/**
+ * SAFE_SCHED_SETATTR() - Safe wrapper for sched_setattr().
+ * @pid: Target process or thread ID (0 for caller).
+ * @attr: Pointer to a sched_attr structure.
+ * @flags: Flags modifying the scheduling behavior.
+ *
+ * Calls sched_setattr() and breaks the test with TBROK | TERRNO on failure.
+ *
+ * Return: Zero on success.
+ */
+#define SAFE_SCHED_SETATTR(pid, attr, flags)\
+	safe_sched_setattr(__FILE__, __LINE__, (pid), (attr), (flags))
+
 #endif /* LAPI_SCHED_H__ */

-- 
2.51.0



More information about the ltp mailing list