From: Arran Cudbard-Bell Date: Wed, 18 Jul 2018 00:52:32 +0000 (-0400) Subject: Try and fix -C unlang lsan X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8b4e756604ab475168990a415bcae84c9cc26644;p=thirdparty%2Ffreeradius-server.git Try and fix -C unlang lsan --- diff --git a/src/bin/radiusd.c b/src/bin/radiusd.c index b3520b63f3f..789c9f14b30 100644 --- a/src/bin/radiusd.c +++ b/src/bin/radiusd.c @@ -893,11 +893,19 @@ cleanup: fr_strerror_free(); /* - * Anything not cleaned up by the above is allocated in the NULL - * top level context, and is likely leaked memory. + * Anything not cleaned up by the above is + * allocated in the NULL top level context, + * and is likely leaked memory. */ if (talloc_memory_report) fr_log_talloc_report(NULL); + /* + * If we're running under LSAN, try and SUID + * back up so we don't inteferere with the + * onexit() handler. + */ + if (!rad_suid_is_down_permanent() && (fr_get_lsan_state() == 1)) rad_suid_up(); + return ret; } diff --git a/src/lib/server/base.h b/src/lib/server/base.h index 415add33aeb..5aba8701e78 100644 --- a/src/lib/server/base.h +++ b/src/lib/server/base.h @@ -78,8 +78,6 @@ extern "C" { */ typedef struct request_data_t request_data_t; - - /** Return codes indicating the result of the module call * * All module functions must return one of the codes listed below (apart from @@ -449,6 +447,7 @@ void rad_suid_set_down_uid(uid_t uid); void rad_suid_down(void); void rad_suid_up(void); void rad_suid_down_permanent(void); +bool rad_suid_is_down_permanent(void); /* regex.c */ #ifdef HAVE_REGEX diff --git a/src/lib/server/util.c b/src/lib/server/util.c index 35bf96e4e1c..2975b065e49 100644 --- a/src/lib/server/util.c +++ b/src/lib/server/util.c @@ -31,6 +31,8 @@ RCSID("$Id$") #include #include +static bool suid_down_permanent = false; //!< Record whether we've permanently dropped privilledges + /* * The signal() function in Solaris 2.5.1 sets SA_NODEFER in * sa_flags, which causes grief if signal() is called in the @@ -1362,6 +1364,8 @@ void rad_suid_down_permanent(void) } fr_reset_dumpable(); + + suid_down_permanent = true; } # else /* @@ -1425,25 +1429,41 @@ void rad_suid_down_permanent(void) } fr_reset_dumpable(); + + suid_down_permanent = true; } # endif /* HAVE_SETRESUID && HAVE_GETRESUID */ #else /* HAVE_SETUID */ void rad_suid_set_down_uid(uid_t uid) { } + void rad_suid_up(void) { } + void rad_suid_down(void) { fr_reset_dumpable(); } + void rad_suid_down_permanent(void) { fr_reset_dumpable(); } #endif /* HAVE_SETUID */ +/** Return whether we've permanently dropped root privileges + * + * @return + * - true if root privileges have been dropped. + * - false if root privileges have not been dropped. + */ +bool rad_suid_is_down_permanent(void) +{ + return suid_down_permanent; +} + /** Alter the effective user id * * @param uid to set diff --git a/src/lib/util/debug.c b/src/lib/util/debug.c index da4206e2386..f5280a7c43c 100644 --- a/src/lib/util/debug.c +++ b/src/lib/util/debug.c @@ -947,8 +947,8 @@ int fr_log_talloc_report(TALLOC_CTX const *ctx) { #define TALLOC_REPORT_MAX_DEPTH 20 - FILE *log; - int fd; + FILE *log; + int fd; fd = dup(fr_fault_log_fd); if (fd < 0) {