[PATCH v2 0/1] MR10251: server: Create temp files for anonymous mappings with memfd_create() if available.
-- v2: server: Create temp files for anonymous mappings with memfd_create() if available. https://gitlab.winehq.org/wine/wine/-/merge_requests/10251
From: Paul Gofman <pgofman@codeweavers.com> --- configure.ac | 2 ++ server/mapping.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 77b80ecb395..f63669df192 100644 --- a/configure.ac +++ b/configure.ac @@ -691,6 +691,7 @@ AC_CHECK_HEADERS(\ linux/input.h \ linux/ioctl.h \ linux/major.h \ + linux/memfd.h \ linux/ntsync.h \ linux/param.h \ linux/serial.h \ @@ -2116,6 +2117,7 @@ AC_CHECK_FUNCS(\ getifaddrs \ getrandom \ kqueue \ + memfd_create \ pipe2 \ port_create \ posix_fadvise \ diff --git a/server/mapping.c b/server/mapping.c index 905d528b04f..d7383387b6d 100644 --- a/server/mapping.c +++ b/server/mapping.c @@ -29,7 +29,9 @@ #include <sys/stat.h> #include <sys/mman.h> #include <unistd.h> - +#ifdef HAVE_LINUX_MEMFD_H +# include <linux/memfd.h> +#endif #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -365,6 +367,13 @@ static int create_temp_file( file_pos_t size ) char tmpfn[16]; int fd; +#if defined(HAVE_MEMFD_CREATE) && defined(MFD_EXEC) + if ((fd = memfd_create( "wine-mapping", MFD_EXEC )) != -1) + { + if (grow_file( fd, size )) return fd; + close( fd ); + } +#endif if (temp_dir_fd == -1) { temp_dir_fd = server_dir_fd; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10251
v2: - use MEMFD_EXEC flag. By default memfd_create() is supposed to create without noexec, but since kernel 6.3 it is possible to change system defaults in various ways: have default with noexec, or deny creating memfd files with executable perimissions. With the flag it should just work in the latter case and in the latter case fail and fallback to other ways of creating temp mapping file. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10251#note_131469
participants (2)
-
Paul Gofman -
Paul Gofman (@gofman)