From 7a3cc285107b59135ab822b6877d8ed169761e08 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 13 Apr 2024 09:54:51 +0100 Subject: [PATCH] sapi/phpdbg: Update of userfaultfd workflow. unpriviliged_userfaultfd is set to 0 by default. Since Linux 5.11 handling memory ranges from the user-space is allowed with the `UFFD_USER_MODE_ONLY` fd open mode flag. --- sapi/phpdbg/phpdbg_watch.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sapi/phpdbg/phpdbg_watch.c b/sapi/phpdbg/phpdbg_watch.c index d3e4ca7d98c9..757cf67e3fcd 100644 --- a/sapi/phpdbg/phpdbg_watch.c +++ b/sapi/phpdbg/phpdbg_watch.c @@ -1472,7 +1472,14 @@ void phpdbg_setup_watchpoints(void) { PHPDBG_G(watch_tmp) = NULL; #ifdef HAVE_USERFAULTFD_WRITEFAULT - PHPDBG_G(watch_userfaultfd) = syscall(SYS_userfaultfd, O_CLOEXEC); + int flags = O_CLOEXEC; +#ifdef UFFD_USER_MODE_ONLY + // unpriviliged userfaultfd are disabled by default, + // with this flag it allows ranges from the user space + // being reported. + flags |= UFFD_USER_MODE_ONLY; +#endif + PHPDBG_G(watch_userfaultfd) = syscall(SYS_userfaultfd, flags); if (PHPDBG_G(watch_userfaultfd) < 0) { PHPDBG_G(watch_userfaultfd) = 0; } else {