From: Andrea Cervesato <andrea.cervesato@suse.de>
To: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH v9 2/5] sched_getattr01: Convert to new API
Date: Thu, 10 Sep 2026 13:57:55 +0200 [thread overview]
Message-ID: <20260910-cve-ghostlock-v9-2-ff3c31791cd6@suse.com> (raw)
In-Reply-To: <20260910-cve-ghostlock-v9-0-ff3c31791cd6@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
Rewrite the test to use the modern LTP API (tst_test.h) with
TST_EXP_* macros and cleanup callback.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/sched_getattr/Makefile | 1 -
.../syscalls/sched_getattr/sched_getattr01.c | 143 ++++++++-------------
2 files changed, 57 insertions(+), 87 deletions(-)
diff --git a/testcases/kernel/syscalls/sched_getattr/Makefile b/testcases/kernel/syscalls/sched_getattr/Makefile
index ea299ff4a..4cef5e763 100644
--- a/testcases/kernel/syscalls/sched_getattr/Makefile
+++ b/testcases/kernel/syscalls/sched_getattr/Makefile
@@ -5,6 +5,5 @@ top_srcdir ?= ../../../..
include $(top_srcdir)/include/mk/testcases.mk
-CFLAGS += -pthread
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c b/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c
index 2e06d1809..0edd9e47e 100644
--- a/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c
+++ b/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c
@@ -1,105 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) Huawei Technologies Co., Ltd., 2015
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Copyright (C) 2026 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify that :manpage:`sched_getattr(2)` correctly reads back the scheduling
+ * attributes of a task configured with :manpage:`sched_setattr(2)`.
+ *
+ * Root is required (:c:macro:`CAP_SYS_NICE`) to configure the
+ * :c:macro:`SCHED_DEADLINE` policy.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
+ * The test relies on the LTP harness process isolation and resets the
+ * scheduling policy to :c:macro:`SCHED_OTHER` after testing to prevent
+ * :c:macro:`SCHED_DEADLINE` constraints from leaking across test iterations.
*/
#define _GNU_SOURCE
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <linux/unistd.h>
-#include <linux/kernel.h>
-#include <linux/types.h>
-#include <sys/syscall.h>
-#include <pthread.h>
-#include <errno.h>
-#include "test.h"
+#include "tst_test.h"
#include "lapi/sched.h"
-char *TCID = "sched_getattr01";
-int TST_TOTAL = 1;
-
#define RUNTIME_VAL 10000000
#define PERIOD_VAL 30000000
#define DEADLINE_VAL 30000000
-void *run_deadline(void *data LTP_ATTRIBUTE_UNUSED)
-{
- struct sched_attr attr, attr_copy;
- int ret;
- unsigned int flags = 0;
- unsigned int size;
-
- attr.size = sizeof(attr);
- attr.sched_flags = 0;
- attr.sched_nice = 0;
- attr.sched_priority = 0;
-
- /* This creates a 10ms/30ms reservation */
- attr.sched_policy = SCHED_DEADLINE;
- attr.sched_runtime = RUNTIME_VAL;
- attr.sched_period = PERIOD_VAL;
- attr.sched_deadline = DEADLINE_VAL;
-
- ret = sched_setattr(0, &attr, flags);
- if (ret < 0)
- tst_brkm(TFAIL | TERRNO, NULL, "sched_setattr() failed");
-
- size = sizeof(attr_copy);
- ret = sched_getattr(0, &attr_copy, size, flags);
- if (ret < 0)
- tst_brkm(TFAIL | TERRNO, NULL, "sched_getattr() failed");
+static struct sched_attr *read_attr;
- int fail = 0;
-
- if (attr_copy.sched_runtime != RUNTIME_VAL) {
- tst_resm(TINFO, "sched_runtime is incorrect (%"PRIu64"),"
- " expected %u", attr.sched_runtime, RUNTIME_VAL);
- fail++;
- }
- if (attr_copy.sched_period != PERIOD_VAL) {
- tst_resm(TINFO, "sched_period is incorrect (%"PRIu64"),"
- " expected %u", attr.sched_period, PERIOD_VAL);
- fail++;
- }
- if (attr_copy.sched_deadline != DEADLINE_VAL) {
- tst_resm(TINFO, "sched_deadline is incorrect (%"PRIu64"),"
- " expected %u", attr.sched_deadline, DEADLINE_VAL);
- fail++;
- }
-
- if (fail)
- tst_resm(TFAIL, "attributes were read back incorrectly");
- else
- tst_resm(TPASS, "attributes were read back correctly");
+static void reset_sched(void)
+{
+ struct sched_attr normal = {
+ .size = sizeof(normal),
+ .sched_policy = SCHED_OTHER,
+ };
- return NULL;
+ sched_setattr(0, &normal, 0);
}
-int main(int argc, char **argv)
+static void run(void)
{
- pthread_t thread;
- int lc;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- tst_require_root();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- pthread_create(&thread, NULL, run_deadline, NULL);
- pthread_join(thread, NULL);
- }
-
- tst_exit();
+ struct sched_attr attr = {
+ .size = sizeof(attr),
+ .sched_policy = SCHED_DEADLINE,
+ .sched_runtime = RUNTIME_VAL,
+ .sched_deadline = DEADLINE_VAL,
+ .sched_period = PERIOD_VAL,
+ };
+
+ if (sched_setattr(0, &attr, 0) == -1)
+ tst_brk(TBROK | TERRNO, "sched_setattr() failed");
+
+ memset((void *)read_attr, 0, sizeof(*read_attr));
+
+ TST_EXP_PASS(sched_getattr(0, read_attr, sizeof(*read_attr), 0),
+ "sched_getattr() with valid parameters");
+ if (!TST_PASS)
+ return;
+
+ TST_EXP_EQ_LU(read_attr->sched_policy, SCHED_DEADLINE);
+ TST_EXP_EQ_LU(read_attr->sched_runtime, RUNTIME_VAL);
+ TST_EXP_EQ_LU(read_attr->sched_deadline, DEADLINE_VAL);
+ TST_EXP_EQ_LU(read_attr->sched_period, PERIOD_VAL);
+
+ reset_sched();
}
+
+static struct tst_test test = {
+ .test_all = run,
+ .cleanup = reset_sched,
+ .needs_root = 1,
+ .bufs = (struct tst_buffers []) {
+ {&read_attr, .size = sizeof(*read_attr)},
+ {},
+ },
+};
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-09-10 11:58 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 ` Andrea Cervesato [this message]
2026-09-10 11:57 ` [LTP] [PATCH v9 3/5] lapi/sched: add SAFE_SCHED_SETATTR() Andrea Cervesato
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-2-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.