Allow syscalls for a forwarded prctl while dispatch blocks

The prctl wrapper issues its syscall from the preload's own text, so a
thread whose selector blocks got SIGSYS where the plain libc call would
have been dispatched the same way by the caller's own rules. Allow
syscalls for the forwarded call and restore the selector afterwards.

The dispatch test now waits until the selector blocks before it sends
the trim request, and checks a prctl call made while it blocks.
This commit is contained in:
maxjivi05 committed 2026-12-04 05:54:40 -05:00
1 parent e42ab05872
commit 8090c6ed04
2 files changed
+11 -1

No files matched your search

+4
View File
@@ -552,7 +552,11 @@ int prctl(int option, ...) {
unsigned long arg4 = va_arg(ap, unsigned long);
unsigned long arg5 = va_arg(ap, unsigned long);
va_end(ap);
volatile unsigned char *dispatch = zr_dispatch;
unsigned char selector = dispatch != NULL ? *dispatch : 0;
if (selector) *dispatch = 0;
long result = zr_sys(SYS_prctl, option, arg2, arg3, arg4, arg5);
if (selector) *dispatch = selector;
if ((unsigned long)result > -4096UL) {
errno = (int)-result;
return -1;
+7 -1
View File
@@ -223,7 +223,7 @@ static void *writer(void *arg) {
}
static volatile unsigned char dispatch_selector;
static int dispatch_traps, dispatch_done;
static int dispatch_traps, dispatch_done, dispatch_ready;
static long dispatch_result = -1;
static void dispatch_trap(int sig, siginfo_t *info, void *context) {
@@ -248,6 +248,7 @@ static void *dispatch_signaller(void *arg) {
if (!f) exit(3);
fprintf(f, "2 %ld\n", 1L << 30);
fclose(f);
while (!__atomic_load_n(&dispatch_ready, __ATOMIC_ACQUIRE)) usleep(1000);
kill(getpid(), SIGURG);
for (int i = 0; i < 1200 && dispatch_result < 0; i++) {
f = fopen(ack, "r");
@@ -451,13 +452,17 @@ int main(int argc, char **argv) {
pthread_t signaller;
pthread_create(&signaller, NULL, dispatch_signaller, NULL);
dispatch_selector = 1;
__atomic_store_n(&dispatch_ready, 1, __ATOMIC_RELEASE);
while (!__atomic_load_n(&dispatch_done, __ATOMIC_ACQUIRE)) {
}
char name[16] = {0};
int named = prctl(PR_GET_NAME, name, 0, 0, 0) == 0 && name[0] != 0;
dispatch_selector = 0;
prctl(59, 0, 0, 0, 0);
pthread_join(signaller, NULL);
printf("traps %d\n", __atomic_load_n(&dispatch_traps, __ATOMIC_RELAXED));
printf("trimmed %d\n", dispatch_result >= 0);
printf("named %d\n", named);
return 0;
} else if (!strcmp(argv[4], "burst")) {
send_request('0');
@@ -766,6 +771,7 @@ class ZramPreloadTest(unittest.TestCase):
self.skipTest("kernel lacks syscall user dispatch")
self.assertEqual([0], out["traps"], out)
self.assertEqual([1], out["trimmed"], out)
self.assertEqual([1], out["named"], out)
if __name__ == "__main__":