From: Andrea Cervesato <andrea.cervesato@suse.de>
To: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH v8 3/5] lapi/sched: add SAFE_SCHED_SETATTR()
Date: Fri, 04 Sep 2026 09:41:21 +0200 [thread overview]
Message-ID: <20260904-cve-ghostlock-v8-3-bd999083c7fb@suse.com> (raw)
In-Reply-To: <20260904-cve-ghostlock-v8-0-bd999083c7fb@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
Add a safe variant of sched_setattr() that breaks the test with TBROK
on failure and use it in sched_setattr01 and sched_getattr01.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/lapi/sched.h | 29 ++++++++++++++++++++++
.../syscalls/sched_getattr/sched_getattr01.c | 5 ++--
.../syscalls/sched_setattr/sched_setattr01.c | 2 +-
3 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/include/lapi/sched.h b/include/lapi/sched.h
index 05b322c1c..22cd27e6d 100644
--- a/include/lapi/sched.h
+++ b/include/lapi/sched.h
@@ -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__ */
diff --git a/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c b/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c
index 0edd9e47e..bd05164ca 100644
--- a/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c
+++ b/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c
@@ -34,7 +34,7 @@ static void reset_sched(void)
.sched_policy = SCHED_OTHER,
};
- sched_setattr(0, &normal, 0);
+ SAFE_SCHED_SETATTR(0, &normal, 0);
}
static void run(void)
@@ -47,8 +47,7 @@ static void run(void)
.sched_period = PERIOD_VAL,
};
- if (sched_setattr(0, &attr, 0) == -1)
- tst_brk(TBROK | TERRNO, "sched_setattr() failed");
+ SAFE_SCHED_SETATTR(0, &attr, 0);
memset((void *)read_attr, 0, sizeof(*read_attr));
diff --git a/testcases/kernel/syscalls/sched_setattr/sched_setattr01.c b/testcases/kernel/syscalls/sched_setattr/sched_setattr01.c
index 721620850..9d121327b 100644
--- a/testcases/kernel/syscalls/sched_setattr/sched_setattr01.c
+++ b/testcases/kernel/syscalls/sched_setattr/sched_setattr01.c
@@ -130,7 +130,7 @@ static void reset_sched(void)
.sched_policy = SCHED_OTHER,
};
- sched_setattr(0, &normal, 0);
+ SAFE_SCHED_SETATTR(0, &normal, 0);
}
static void verify_sched_setattr(unsigned int n)
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-09-04 7:42 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 7:41 [LTP] [PATCH v8 0/5] Reproducer for ghostlock Andrea Cervesato
2026-09-04 7:41 ` [LTP] [PATCH v8 1/5] sched_setattr01: Convert to new API Andrea Cervesato
2026-09-04 8:20 ` [LTP] " linuxtestproject.agent
2026-09-04 8:23 ` Andrea Cervesato via ltp
2026-09-10 10:40 ` [LTP] [PATCH v8 1/5] " Cyril Hrubis
2026-09-10 11:58 ` Andrea Cervesato via ltp
2026-09-04 7:41 ` [LTP] [PATCH v8 2/5] sched_getattr01: " Andrea Cervesato
2026-09-10 10:48 ` Cyril Hrubis
2026-09-04 7:41 ` Andrea Cervesato [this message]
2026-09-10 10:52 ` [LTP] [PATCH v8 3/5] lapi/sched: add SAFE_SCHED_SETATTR() Cyril Hrubis
2026-09-04 7:41 ` [LTP] [PATCH v8 4/5] lapi/prctl: add more fallback definitions Andrea Cervesato
2026-09-10 10:57 ` Cyril Hrubis
2026-09-04 7:41 ` [LTP] [PATCH v8 5/5] cve: add CVE-2026-43499 reproducer Andrea Cervesato
2026-09-10 11:08 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260904-cve-ghostlock-v8-3-bd999083c7fb@suse.com \
--to=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.