From 2a542af8829c4fa938556dbf404fcf21fefbf91d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 7 Feb 2018 20:21:57 -0600 Subject: loader: gracefully handle user-exec of the ELF interpreter itself --- loader/loader.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/loader/loader.c b/loader/loader.c index 53a2c38..ebcdbfe 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -34,6 +34,12 @@ #error LOADER must be defined #endif +void usage(void) +{ + printf("This is the gcompat ELF interpreter stub.\n"); + printf("You are not meant to run this directly.\n"); +} + /* * Given the argv { "foo", "bar", "baz" }, and the environment variable * "LD_PRELOAD=/another/preload.so", the new argv will be { @@ -96,6 +102,12 @@ int main(int argc, char *argv[], char *envp[]) } target[len] = '\0'; + /* somebody is trying to run the loader directly */ + if (strstr(target, LOADER) != NULL) { + usage(); + return EXIT_FAILURE; + } + new_argv[0] = LOADER; new_argv[1] = "--argv0"; new_argv[2] = argv[0]; -- cgit v1.2.3-70-g09d2