darling icon indicating copy to clipboard operation
darling copied to clipboard

`Terminated due to signal 5` when debugging an app that uses `execve`

Open trungnt2910 opened this issue 4 years ago • 1 comments

Expected Result The program should continue to execute.

Actual Result The program stops with signal 5

Steps To Reproduce

  1. Compile and run this code:
__attribute__((noinline))
int IsDebuggerPresent()
{
	return 0;
}

int main(int argc, char** argv, char** envp)
{
	std::cerr << "Debugger PID: " << getpid() << "\r\n" << std::flush;

	while (!IsDebuggerPresent())
	{
		continue;
	}

	std::cerr << "Debugger attached." << "\r\n" << std::flush;

	#define NAME "/usr/local/share/vsdbg/vsdbg"
	char** argv1 = new char*[argc + 1];
	memcpy(argv1, argv, sizeof(char*) * argc);
	argv1[0] = NAME;
	argv1[argc] = nullptr;

	execve(NAME, argv1, envp);
}
  1. Attach lldb, specifically the one provided on the Darling docs page.
  2. Break in IsDebuggerPresent function, step out of it, modify the value of rax to a nonzero value so that the program can break out of the while loop.
  3. Break again at execve, step all the way until the next linux_syscall. The program should terminate there.

dmesg Output Run dmesg | grep 'overlay\|darling'

[ 4422.536499] Darling TID 480 (PID 480) says: darling_sigexc_self()

System Information What system are you using?

Software Version
Linux Kernel 5.10.60.1-microsoft-standard-WSL2+
Darling 289628cccf0cd7567c1d275f09600ad214d26acd

trungnt2910 avatar Nov 19 '21 08:11 trungnt2910

It is failing here: https://github.com/darlinghq/darling/blob/289628cccf0cd7567c1d275f09600ad214d26acd/src/kernel/emulation/linux/process/execve.c#L131

trungnt2910 avatar Nov 19 '21 09:11 trungnt2910