summaryrefslogtreecommitdiff
path: root/loader
diff options
context:
space:
mode:
authorAriadne Conill <ariadne@dereferenced.org>2020-08-21 22:57:35 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-08-22 00:38:31 -0500
commit4bd46a4cd4b2407aa04fa2da1fdafbdcf15cfe24 (patch)
tree1d97e4dfc2cbe6bc56701ce6c5edcadc158ae668 /loader
parentaa649428f2d294c03b50b0bc9e11b51296bab008 (diff)
downloadgcompat-4bd46a4cd4b2407aa04fa2da1fdafbdcf15cfe24.tar.gz
gcompat-4bd46a4cd4b2407aa04fa2da1fdafbdcf15cfe24.tar.bz2
gcompat-4bd46a4cd4b2407aa04fa2da1fdafbdcf15cfe24.tar.xz
gcompat-4bd46a4cd4b2407aa04fa2da1fdafbdcf15cfe24.zip
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.
Diffstat (limited to 'loader')
-rw-r--r--loader/loader.c11
1 files 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];
}