[pkg-wine-party] Bug#865407: wine-development: Wine cannot execute position-independent (PIE) host executables via CreateProcess()

Jörn Heusipp osmanx at problemloesungsmaschine.de
Wed Jun 21 07:26:58 UTC 2017


Package: wine-development
Version: 2.0-3
Severity: normal
Tags: upstream

Dear Maintainer,


Wine cannot execute position-independent (PIE) host executables via CreateProcess()

The problem arises from the fact that `create_process_impl()` in
`dlls/kernel32/process.c` ultimately calls `MODULE_get_binary_info()`
in `dlls/kernel32/module.c` which detects PIE exectuables as ELF
shared objects and thus sets `info->type = BINARY_UNIX_LIB;` instead of
`info->type = BINARY_UNIX_EXE;`. I do not have enough knowledge about
the precise way that Winelib apps are implemented or supposed to work,
but the fact that PIE executables are in fact ELF shared objects and
not ELF executables according to the ELF header, causes Wine to detect
these as Winelib apps and ultimately invoke the wrong process creation
path.

As Debian 9 Stretch switched to PIE by default, this basically affects
all native executables. Non-PIE executables work fine.

Wine 1.8.7 is also affected, as is the current Wine development branch.

Upstream bug report is at https://bugs.winehq.org/show_bug.cgi?id=43217 .

```
manx at vmdebian9:~/test$ ./script.sh 
+ cat script.sh
#!/usr/bin/env bash
set -x
cat script.sh
cat hello.c
cat test.c
x86_64-w64-mingw32-gcc -mconsole -std=c99 -O2 -Wall -Wextra test.c -o test.exe
gcc -no-pie -fno-PIE -std=c99 -O2 -Wall -Wextra hello.c -o hello
file hello
wine64-development test.exe
WINEDEBUG=trace+process wine64-development test.exe
gcc -pie -fPIE -std=c99 -O2 -Wall -Wextra hello.c -o hello
file hello
wine64-development test.exe
WINEDEBUG=trace+process wine64-development test.exe
uname -m
cat /etc/debian_version
gcc -dumpversion
wine64-development --version

+ cat hello.c
#include <stdio.h>
int main() {
    fprintf(stderr, "%s\n", "Hello World!");
    return 0;
}
+ cat test.c
#include <stdio.h>
#include <string.h>
#include <windows.h>
int main() {
	STARTUPINFO startupInfo;
	ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
	startupInfo.lpTitle = "dummy";
	startupInfo.cb = sizeof(startupInfo);
	PROCESS_INFORMATION processInformation;
	ZeroMemory(&processInformation, sizeof(PROCESS_INFORMATION));
	if(CreateProcess(NULL, "./hello", NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &startupInfo, &processInformation) == FALSE) {
		fprintf(stderr, "CreateProcess() failed\n");
		return 1;
	}
	WaitForSingleObject(processInformation.hProcess, INFINITE);
	CloseHandle(processInformation.hThread);
	CloseHandle(processInformation.hProcess);
	return 0;
}

+ x86_64-w64-mingw32-gcc -mconsole -std=c99 -O2 -Wall -Wextra test.c -o test.exe
+ gcc -no-pie -fno-PIE -std=c99 -O2 -Wall -Wextra hello.c -o hello
+ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=db69604025be8ad94f0f8d80e9c60eff185a8b07, not stripped
+ wine64-development test.exe
Hello World!
+ WINEDEBUG=trace+process
+ wine64-development test.exe
trace:process:init_current_directory starting in L"Z:\\home\\manx\\test\\" 0x8
trace:process:__wine_kernel_init starting process name=L"Z:\\home\\manx\\test\\test.exe" argv[0]=L"Z:\\home\\manx\\test\\test.exe"
trace:process:create_process_impl app (null) cmdline L"./hello"
trace:process:find_exe_file looking for L"./hello"
trace:process:find_exe_file Trying native exe L"Z:\\home\\manx\\test\\hello"
trace:process:create_process_impl starting L"Z:\\home\\manx\\test\\hello" as Unix binary
trace:process:create_process_impl started process pid 0000 tid 0000
Hello World!
+ gcc -pie -fPIE -std=c99 -O2 -Wall -Wextra hello.c -o hello
+ file hello
hello: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=e002ea7db0a5e5223085e78d97a6f25f61160958, not stripped
+ wine64-development test.exe
wine: Bad EXE format for Z:\home\manx\test\hello..
CreateProcess() failed
+ WINEDEBUG=trace+process
+ wine64-development test.exe
trace:process:init_current_directory starting in L"Z:\\home\\manx\\test\\" 0x8
trace:process:__wine_kernel_init starting process name=L"Z:\\home\\manx\\test\\test.exe" argv[0]=L"Z:\\home\\manx\\test\\test.exe"
trace:process:create_process_impl app (null) cmdline L"./hello"
trace:process:find_exe_file looking for L"./hello"
trace:process:find_exe_file Trying native exe L"Z:\\home\\manx\\test\\hello"
trace:process:create_process_impl starting L"Z:\\home\\manx\\test\\hello" as 64-bit Winelib app
trace:process:init_current_directory starting in L"Z:\\home\\manx\\test\\" 0xc
trace:process:__wine_kernel_init starting process name=L"Z:\\home\\manx\\test\\hello." argv[0]=L"./hello"
wine: Bad EXE format for Z:\home\manx\test\hello..
CreateProcess() failed
+ uname -m
x86_64
+ cat /etc/debian_version
9.0
+ gcc -dumpversion
6.3.0
+ wine64-development --version
wine-2.0 (Debian 2.0-3+b2)
manx at vmdebian9:~/test$ 
```


-- Package-specific info:
/usr/bin/wine points to /usr/bin/wine-stable.

-- System Information:
Debian Release: 9.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.9.0-3-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US:en (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages wine-development depends on:
ii  wine32-development  2.0-3+b2
ii  wine64-development  2.0-3+b2

wine-development recommends no packages.

Versions of packages wine-development suggests:
pn  dosbox       <none>
pn  playonlinux  <none>
pn  winbind      <none>
ii  wine-binfmt  1.8.7-2
ii  winetricks   0.0+20170101-1

Versions of packages wine-development is related to:
ii  fonts-wine          1.8.7-2
ii  wine-development    2.0-3
ii  wine32-development  2.0-3+b2
ii  wine64-development  2.0-3+b2

-- no debconf information



More information about the pkg-wine-party mailing list