From: Andrea Cervesato <andrea.cervesato@suse.de>
To: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH v9 3/5] lapi/sched: add SAFE_SCHED_SETATTR()
Date: Thu, 10 Sep 2026 13:57:56 +0200 [thread overview]
Message-ID: <20260910-cve-ghostlock-v9-3-ff3c31791cd6@suse.com> (raw)
In-Reply-To: <20260910-cve-ghostlock-v9-0-ff3c31791cd6@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.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/lapi/sched.h | 35 ++++++++++++++++++++++
.../syscalls/sched_getattr/sched_getattr01.c | 5 ++--
.../syscalls/sched_setattr/sched_setattr01.c | 2 +-
3 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/include/lapi/sched.h b/include/lapi/sched.h
index 05b322c1c..d623ea7cf 100644
--- a/include/lapi/sched.h
+++ b/include/lapi/sched.h
@@ -169,4 +169,39 @@ 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) {
+ if (attr) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "sched_setattr(%i, {size=%u, policy=%u}, %u) failed",
+ pid, attr->size, attr->sched_policy, flags);
+ } else {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "sched_setattr(%i, NULL, %u) failed", pid, flags);
+ }
+ }
+
+ 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 f89b829f4..93e532774 100644
--- a/testcases/kernel/syscalls/sched_setattr/sched_setattr01.c
+++ b/testcases/kernel/syscalls/sched_setattr/sched_setattr01.c
@@ -44,7 +44,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)
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-09-10 11:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 11:57 [LTP] [PATCH v9 0/5] Reproducer for ghostlock Andrea Cervesato
2026-09-10 11:57 ` [LTP] [PATCH v9 1/5] sched_setattr: Convert to new API Andrea Cervesato
2026-09-10 13:00 ` Cyril Hrubis
2026-09-10 11:57 ` [LTP] [PATCH v9 2/5] sched_getattr01: " Andrea Cervesato
2026-09-10 11:57 ` Andrea Cervesato [this message]
2026-09-10 11:57 ` [LTP] [PATCH v9 4/5] lapi/prctl: add more fallback definitions Andrea Cervesato
2026-09-10 11:57 ` [LTP] [PATCH v9 5/5] cve: add CVE-2026-43499 reproducer Andrea Cervesato
2026-09-10 12:41 ` [LTP] [PATCH v9 0/5] Reproducer for ghostlock Andrea Cervesato via ltp
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=20260910-cve-ghostlock-v9-3-ff3c31791cd6@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.