From 0b96046f1526863cd24f6556933214a14fa65f7b Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Fri, 18 Aug 2023 20:19:25 -0600 Subject: [PATCH] Update and re-enable ntdll-Syscall_Emulation patchset. Thanks DodoGTA from LGD discord for spotting related upstream ABI change and suggesting a part of the fix. --- ...dll-Support-x86_64-syscall-emulation.patch | 29 ++++++++++++------- patches/ntdll-Syscall_Emulation/definition | 1 - 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/patches/ntdll-Syscall_Emulation/0001-ntdll-Support-x86_64-syscall-emulation.patch b/patches/ntdll-Syscall_Emulation/0001-ntdll-Support-x86_64-syscall-emulation.patch index 83e6dd35..8e35cef7 100644 --- a/patches/ntdll-Syscall_Emulation/0001-ntdll-Support-x86_64-syscall-emulation.patch +++ b/patches/ntdll-Syscall_Emulation/0001-ntdll-Support-x86_64-syscall-emulation.patch @@ -1,18 +1,18 @@ -From a20d7bb78dc0d2d134cfe6461c117fea1a5753ed Mon Sep 17 00:00:00 2001 +From 45df10c65cee279caac2184919c81e6b473bd3f8 Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Tue, 14 Jul 2020 15:00:34 +0300 Subject: [PATCH] ntdll: Support x86_64 syscall emulation. --- configure.ac | 1 + - dlls/ntdll/unix/signal_x86_64.c | 185 ++++++++++++++++++++++++++++++++ - 2 files changed, 186 insertions(+) + dlls/ntdll/unix/signal_x86_64.c | 192 ++++++++++++++++++++++++++++++++ + 2 files changed, 193 insertions(+) diff --git a/configure.ac b/configure.ac -index a8c1d1522fe..2fd9f7a497d 100644 +index b759c57f4a0..b72e5c59274 100644 --- a/configure.ac +++ b/configure.ac -@@ -427,6 +427,7 @@ AC_CHECK_HEADERS(\ +@@ -420,6 +420,7 @@ AC_CHECK_HEADERS(\ linux/ioctl.h \ linux/major.h \ linux/param.h \ @@ -21,7 +21,7 @@ index a8c1d1522fe..2fd9f7a497d 100644 linux/types.h \ linux/ucdrom.h \ diff --git a/dlls/ntdll/unix/signal_x86_64.c b/dlls/ntdll/unix/signal_x86_64.c -index bf528226462..a5cd26b7ea0 100644 +index 0204139631f..117c238cf44 100644 --- a/dlls/ntdll/unix/signal_x86_64.c +++ b/dlls/ntdll/unix/signal_x86_64.c @@ -27,6 +27,7 @@ @@ -56,7 +56,7 @@ index bf528226462..a5cd26b7ea0 100644 #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" -@@ -1821,6 +1832,179 @@ static inline DWORD is_privileged_instr( CONTEXT *context ) +@@ -1773,6 +1784,186 @@ static inline DWORD is_privileged_instr( CONTEXT *context ) return 0; } @@ -70,6 +70,13 @@ index bf528226462..a5cd26b7ea0 100644 + TRACE_(seh)("SIGSYS, rax %#llx, rip %#llx.\n", ctx->uc_mcontext.gregs[REG_RAX], + ctx->uc_mcontext.gregs[REG_RIP]); + ++ if (ctx->uc_mcontext.gregs[REG_RAX] == 0xffff) ++ { ++ /* Test syscall from the Unix side (install_bpf). */ ++ ctx->uc_mcontext.gregs[REG_RAX] = STATUS_INVALID_PARAMETER; ++ return; ++ } ++ + frame->rip = ctx->uc_mcontext.gregs[REG_RIP] + 0xb; + frame->rcx = ctx->uc_mcontext.gregs[REG_RIP]; + frame->eflags = ctx->uc_mcontext.gregs[REG_EFL]; @@ -129,7 +136,7 @@ index bf528226462..a5cd26b7ea0 100644 +# endif + static const BYTE syscall_trap_test[] = + { -+ 0x48, 0x89, 0xc8, /* mov %rcx, %rax */ ++ 0x48, 0x89, 0xf8, /* mov %rdi, %rax */ + 0x0f, 0x05, /* syscall */ + 0xc3, /* retq */ + }; @@ -155,7 +162,7 @@ index bf528226462..a5cd26b7ea0 100644 + BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_TRAP), + BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW), + }; -+ long (WINAPI *test_syscall)(long sc_number); ++ long (*test_syscall)(long sc_number); + struct syscall_frame *frame = amd64_thread_data()->syscall_frame; + struct sock_fprog prog; + NTSTATUS status; @@ -236,7 +243,7 @@ index bf528226462..a5cd26b7ea0 100644 /*********************************************************************** * handle_interrupt -@@ -2520,6 +2704,7 @@ void signal_init_process(void) +@@ -2448,6 +2639,7 @@ void signal_init_process(void) if (sigaction( SIGSEGV, &sig_act, NULL ) == -1) goto error; if (sigaction( SIGILL, &sig_act, NULL ) == -1) goto error; if (sigaction( SIGBUS, &sig_act, NULL ) == -1) goto error; @@ -245,5 +252,5 @@ index bf528226462..a5cd26b7ea0 100644 error: -- -2.40.1 +2.41.0 diff --git a/patches/ntdll-Syscall_Emulation/definition b/patches/ntdll-Syscall_Emulation/definition index 02593d00..89b59eb0 100644 --- a/patches/ntdll-Syscall_Emulation/definition +++ b/patches/ntdll-Syscall_Emulation/definition @@ -1,2 +1 @@ Fixes: [48291] Detroit: Become Human crashes on launch -Disabled: True