From: Ken Thomases Subject: [PATCH 1/2] libwine: On Mac, disable ASLR for Wine processes. Message-Id: <20190131230825.92037-1-ken@codeweavers.com> Date: Thu, 31 Jan 2019 17:08:24 -0600 ASLR can allow dyld to be loaded where it overlaps one of the regions that the preloader would like to reserve. That, in turn, can prevent Wine from using the shared user data region. With ASLR disabled, dyld will be loaded immediately after the preloader, which has a defined base address. This uses an Apple extension to posix_spawn() that allows it to replace the calling process's image, like a more featureful execve(). The flag to disable ASLR is technically private SPI, but has remained stable for many versions of the OS. And the Mac preloader is already stepping over that line. Signed-off-by: Ken Thomases --- libs/wine/config.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libs/wine/config.c b/libs/wine/config.c index 083e263..b1f526c 100644 --- a/libs/wine/config.c +++ b/libs/wine/config.c @@ -33,6 +33,13 @@ #ifdef HAVE_PWD_H #include #endif +#ifdef __APPLE__ +#include +#include +#ifndef _POSIX_SPAWN_DISABLE_ASLR +#define _POSIX_SPAWN_DISABLE_ASLR 0x0100 +#endif +#endif #include "wine/library.h" static const char server_config_dir[] = "/.wine"; /* config dir relative to $HOME */ @@ -558,6 +565,15 @@ static void preloader_exec( char **argv, int use_preloader ) new_argv = xmalloc( (last_arg - argv + 2) * sizeof(*argv) ); memcpy( new_argv + 1, argv, (last_arg - argv + 1) * sizeof(*argv) ); new_argv[0] = full_name; +#ifdef __APPLE__ + { + posix_spawnattr_t attr; + posix_spawnattr_init( &attr ); + posix_spawnattr_setflags( &attr, POSIX_SPAWN_SETEXEC | _POSIX_SPAWN_DISABLE_ASLR ); + posix_spawn( NULL, full_name, NULL, &attr, new_argv, *_NSGetEnviron() ); + posix_spawnattr_destroy( &attr ); + } +#endif execv( full_name, new_argv ); free( new_argv ); free( full_name ); -- 2.10.2