Skip to content

Commit 62a9252

Browse files
committed
Fix map_shadow_stack syscall number
* Syscall number for map_shadow_stack has changed since initial support was added. * Use SYS_map_shadow_stack instead of hard-coded number when possible
1 parent fdeb748 commit 62a9252

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Zend/zend_fibers.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@
7070
#endif
7171

7272
# if defined __CET__
73+
# include <sys/syscall.h>
74+
# include <unistd.h>
7375
# include <cet.h>
7476
# define SHSTK_ENABLED (__CET__ & 0x2)
7577
# define BOOST_CONTEXT_SHADOW_STACK (SHSTK_ENABLED && SHADOW_STACK_SYSCALL)
76-
# define __NR_map_shadow_stack 451
78+
# ifndef SYS_map_shadow_stack
79+
# define SYS_map_shadow_stack 453
80+
# endif
7781
# ifndef SHADOW_STACK_SET_TOKEN
7882
# define SHADOW_STACK_SET_TOKEN 0x1
7983
#endif
@@ -279,7 +283,7 @@ static zend_fiber_stack *zend_fiber_stack_allocate(size_t size)
279283

280284
/* issue syscall to create shadow stack for the new fcontext */
281285
/* SHADOW_STACK_SET_TOKEN option will put "restore token" on the new shadow stack */
282-
stack->ss_base = (void *)syscall(__NR_map_shadow_stack, 0, stack->ss_size, SHADOW_STACK_SET_TOKEN);
286+
stack->ss_base = (void *)syscall(SYS_map_shadow_stack, 0, stack->ss_size, SHADOW_STACK_SET_TOKEN);
283287

284288
if (stack->ss_base == MAP_FAILED) {
285289
zend_throw_exception_ex(NULL, 0, "Fiber shadow stack allocate failed: mmap failed: %s (%d)", strerror(errno), errno);

configure.ac

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,11 +1253,18 @@ fi
12531253
AC_CACHE_CHECK([whether syscall to create shadow stack exists],
12541254
[php_cv_have_shadow_stack_syscall],
12551255
[AC_RUN_IFELSE([AC_LANG_SOURCE([
1256+
#include <sys/syscall.h>
12561257
#include <unistd.h>
12571258
#include <sys/mman.h>
1259+
#ifndef SYS_map_shadow_stack
1260+
# define SYS_map_shadow_stack 453
1261+
#endif
1262+
#ifndef SHADOW_STACK_SET_TOKEN
1263+
# define SHADOW_STACK_SET_TOKEN 0x1
1264+
#endif
12581265
int main(void) {
1259-
/* test if syscall 451, i.e., map_shadow_stack is available */
1260-
void* base = (void *)syscall(451, 0, 0x20000, 0x1);
1266+
/* test if map_shadow_stack is available */
1267+
void* base = (void *)syscall(SYS_map_shadow_stack, 0, 0x20000, SHADOW_STACK_SET_TOKEN);
12611268
if (base != (void*)-1) {
12621269
munmap(base, 0x20000);
12631270
return 0;

0 commit comments

Comments
 (0)