Created attachment 118743 [details] Add support for sched_setattr and sched_getattr system calls Subject: [PATCH] Add support for sched_setattr and sched_getattr system call. Based on the sched_setparam and sched_getparam syscall wrapper.
Those system calls should take a vki_sched_getattr as their second argument, not a vki_sched_getparam so as written then will be checking the wrong amount of memory. Also setattr should presumably do PRE_MEM_READ and drop the write hooks as it presumably reads the structure rather than writing it.
Thanks for the feedback. Okay, sorry for those obvious bugs. I was in a too fast copy&past mode. I'll update the patch accordingly, tomorrow.
With PRE_MEM_READ valgrind will complain for code like this (which should be fine, right?): void run_deadline() { struct sched_attr attr; ret = sched_getattr(0, &attr, sizeof(attr), 0); } ==11537== Thread 2: ==11537== Syscall param sched_getattr(p) points to uninitialised byte(s) ==11537== at 0x49A1EFD: syscall (in /usr/lib64/libc-2.28.so) ==11537== by 0x403E68: run_deadline (cyclicdeadline.c:784) ==11537== by 0x489058D: start_thread (in /usr/lib64/libpthread-2.28.so) ==11537== by 0x49A76A2: clone (in /usr/lib64/libc-2.28.so) ==11537== Address 0x5671ea0 is on thread 2's stack ==11537== in frame #1, created by run_deadline (cyclicdeadline.c:772) ==11537== No complains with PRE_MEM_WRITE.
Well that one doesn't need a PRE_MEM_READ so the fact that it would complain isn't really relevant. You should use PRE_MEM_READ before the system call for any memory which will be read by the system call and PRE_MEM_WRITE for any memory which will be written by the system call (unless it is also read - you don't need to do both). After the system call completes you should use POST_MEM_WRITE on any memory that the system call has written. Basically PRE_MEM_READ checks that the memory is both addressable (that there is actual accessible memory at that address) and defined (that it has been initialised with known contents) while PRE_MEM_WRITE just does the first check. Then POST_MEM_WRITE marks the memory as defined if it has been filled in by the system call.
Created attachment 118767 [details] Add support for sched_setattr and sched_getattr v2
I am not sure if I handle the size argument correctly. Here the snipped from the man pages: size This field should be set to the size of the structure in bytes, as in sizeof(struct sched_attr). If the provided structure is smaller than the kerβ nel structure, any additional fields are assumed to be '0'. If the provided structure is larger than the kernel structure, the kernel verifies that all additional fields are 0; if they are not, sched_setattr() fails with the error E2BIG and updates size to contain the size of the kernel structure. The above behavior when the size of the user-space sched_attr structure does not match the size of the kernel structure allows for future extensibility of the interface. Malformed applications that pass oversize structures won't break in the future if the size of the kernel sched_attr structure is increased. In the future, it could also allow applications that know about a larger user-space sched_attr structure to determine whether they are running on an older kernel that does not support the larger structure.
Sorry, I did not notice there is a newer bugzilla and posted a patch to support sched_setattr and sched_getattr in bug 369029. I wonder if someone can take a look at it. https://bugs.kde.org/show_bug.cgi?id=369029 TIA
Let's close this report if it's already tracked in 369029. *** This bug has been marked as a duplicate of bug 369029 ***