From 4bd46a4cd4b2407aa04fa2da1fdafbdcf15cfe24 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 21 Aug 2020 22:57:35 -0600 Subject: loader: use "--" between musl ldso options and the executable path This is needed for semantic correctness and also ensures argv is set up to provide a 16-byte aligned stack on aarch64 as required by hardware. --- loader/loader.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/loader/loader.c b/loader/loader.c index dd3f0d2..ba4b4b7 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -48,6 +48,7 @@ void usage(void) * "foo", * "--preload", * "/path/to/libgcompat.so /another/preload.so", + * "--", * "/path/to/foo", * "bar", * "baz" @@ -78,10 +79,13 @@ void usage(void) * to the program. An intercepted readlink("/proc/self/exe") must read it from * /proc/self/cmdline. Thus, if its position in new_argv changes, that function * must also be updated to match. + * + * NOTE: We have to use 7 arguments to ensure alignment is correct on AArch64, + * so we add an additional --, leaving the 8th argument as the binary name. */ int main(int argc, char *argv[], char *envp[]) { - char **new_argv = calloc(argc + 6, sizeof(char *)); + char **new_argv = calloc(argc + 7, sizeof(char *)); char preload[PATH_MAX] = ""; char target[PATH_MAX] = ""; ssize_t i, j, len; @@ -113,8 +117,9 @@ int main(int argc, char *argv[], char *envp[]) new_argv[2] = argv[0]; new_argv[3] = "--preload"; new_argv[4] = preload; - new_argv[5] = target; - for (i = 6, j = 1; j < argc; ++i, ++j) { + new_argv[5] = "--"; + new_argv[6] = target; + for (i = 7, j = 1; j < argc; ++i, ++j) { new_argv[i] = argv[j]; } -- cgit v1.2.3-70-g09d2