Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFI: create a test case for sched_setscheduler() syscall #365

Open
dougsland opened this issue Apr 16, 2024 · 7 comments · May be fixed by #450
Open

FFI: create a test case for sched_setscheduler() syscall #365

dougsland opened this issue Apr 16, 2024 · 7 comments · May be fixed by #450
Assignees
Labels
enhancement New feature or request ffi jira

Comments

@dougsland
Copy link
Collaborator

dougsland commented Apr 16, 2024

Basically, inside QM sched_setscheduler() syscall is not allowed and we should prove it.
Transform the below steps into a test plan.

Steps:

1- Build source code:

gcc -o test_sched_setscheduler test_sched_setscheduler.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <errno.h>
#include <string.h>

int main() {
    int pid = getpid(); 
    int policy = SCHED_FIFO;  // Desired scheduling policy
    struct sched_param param;

    // Assign the maximum priority for the SCHED_FIFO policy
    param.sched_priority = sched_get_priority_max(policy);
    if (param.sched_priority == -1) {
        fprintf(stderr, "Failed to get max priority for SCHED_FIFO: %s\n", strerror(errno));
        return EXIT_FAILURE;
    }

    // Attempt to set the scheduling policy and priority
    if (sched_setscheduler(pid, policy, &param) == -1) {
        fprintf(stderr, "Failed to set scheduler: %s\n", strerror(errno));
        return EXIT_FAILURE;
    }

    printf("Scheduler set to SCHED_FIFO with priority %d\n", param.sched_priority);
    return EXIT_SUCCESS;
}

2- copy the binary to qm

cp test_sched_setscheduler /usr/lib/qm/rootfs/root/

3- Execute the test

# podman exec -it qm bash
bash-5.1# ./test_sched_setscheduler
Failed to set scheduler: Operation not permitted

Please note: the QM pull request 362 includes the patch to make sure set schedules is not allowed, to test without this restriction just test previous version or remove create_qm_seccomp_rules from setup and --security-opt seccomp=/usr/share/qm/seccomp.json from qm.container.

See also:
#362 (comment)
https://gitlab.com/CentOS/automotive/container-images/ffi-tools/-/blob/main/Containerfile?ref_type=heads

@dougsland
Copy link
Collaborator Author

cc @pbrilla-rh @Yarboa

@dougsland dougsland added enhancement New feature or request jira labels Apr 16, 2024
@Yarboa
Copy link
Collaborator

Yarboa commented Apr 16, 2024

@dougsland better add it to ffi tools
something like that:

From host partition or qm partition

podman cp ctr_name:/root/tests/FFI/bin/QM/test_sched_setscheduler .

@pbrilla-rh
This test should could exist in public repo, since it is checking seccomp

@dougsland
Copy link
Collaborator Author

@dougsland better add it to ffi tools something like that:

From host partition or qm partition

podman cp ctr_name:/root/tests/FFI/bin/QM/test_sched_setscheduler .

@pbrilla-rh This test should could exist in public repo, since it is checking seccomp

Agreed @Yarboa, opened this one to document and track the work.

@dougsland dougsland assigned dougsland and unassigned dougsland Apr 17, 2024
@dougsland dougsland added the ffi label Apr 18, 2024
@dougsland
Copy link
Collaborator Author

If no complain get raised, the tool should be included here: #371
After that, we can just include into the cycle of tests https://gitlab.com/CentOS/automotive/container-images/ffi-tools

@pengshanyu
Copy link
Collaborator

filed a PR: #438

@dougsland
Copy link
Collaborator Author

Resolved.

@dougsland dougsland reopened this May 22, 2024
@dougsland
Copy link
Collaborator Author

talked with @pengshanyu still need to finish the tmt case.

@pengshanyu pengshanyu linked a pull request May 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ffi jira
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants