From: Stas Boukarev Date: Sat, 5 Oct 2013 16:59:22 +0000 (+0400) Subject: Prevent personality setting on Linux from going in circles. X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=518493eab883e50237043153c0d45b245e929c7d;p=sbcl.git Prevent personality setting on Linux from going in circles. Apparently, setuid causes ADDR_NO_RANDOMIZE to be stripped away. Stop restarting SBCL itself indefinitely by adding an SBCL_IS_RESTARTING environment variable and consulting it before trying to restart again. Reported by Teemu Likonen. --- diff --git a/src/runtime/linux-os.c b/src/runtime/linux-os.c index b7ceca1..a23bc5d 100644 --- a/src/runtime/linux-os.c +++ b/src/runtime/linux-os.c @@ -273,7 +273,9 @@ os_init(char *argv[], char *envp[]) * in an error or if the value didn't change. Otherwise * this might result in an infinite loop. */ - if (retval != -1 && newpers != pers) { + + if (!getenv("SBCL_IS_RESTARTING") && + retval != -1 && newpers != pers) { /* Use /proc/self/exe instead of trying to figure out * the executable path from PATH and argv[0], since * that's unreliable. We follow the symlink instead of @@ -282,15 +284,21 @@ os_init(char *argv[], char *envp[]) char runtime[PATH_MAX+1]; int i = readlink("/proc/self/exe", runtime, PATH_MAX); if (i != -1) { + environ = envp; + setenv("SBCL_IS_RESTARTING", "T", 1); runtime[i] = '\0'; - execve(runtime, argv, envp); + execv(runtime, argv); } } /* Either changing the personality or execve() failed. Either * way we might as well continue, and hope that the random * memory maps are ok this time around. */ - fprintf(stderr, "WARNING: Couldn't re-execute SBCL with the proper personality flags (maybe /proc isn't mounted?). Trying to continue anyway.\n"); + fprintf(stderr, "WARNING:\ +\nCouldn't re-execute SBCL with proper personality flags (/proc isn't mounted? setuid?)\ +\nTrying to continue anyway.\n"); + } else { + unsetenv("SBCL_IS_RESTARTING"); } } #ifdef LISP_FEATURE_X86