From 8090c6ed048d3d9cc548e11cb1bf314302c78e75 Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Fri, 4 Dec 2026 05:54:40 -0500 Subject: [PATCH] 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. --- tools/linuxfs/preload/zram.c | 4 ++++ tools/tests/test_zram_preload.py | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/linuxfs/preload/zram.c b/tools/linuxfs/preload/zram.c index 49be1e74d6..446996a06e 100644 --- a/tools/linuxfs/preload/zram.c +++ b/tools/linuxfs/preload/zram.c @@ -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; diff --git a/tools/tests/test_zram_preload.py b/tools/tests/test_zram_preload.py index 8996e56cc5..3d6b7d6126 100644 --- a/tools/tests/test_zram_preload.py +++ b/tools/tests/test_zram_preload.py @@ -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__":