Always cleanup init LD_PRELOAD hooks

Fix #6296
This commit is contained in:
残页 2022-10-03 23:26:33 +08:00 committed by GitHub
parent f9e82c9e8a
commit 44cfe94e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,11 +3,14 @@
#include <unistd.h> #include <unistd.h>
#include <dlfcn.h> #include <dlfcn.h>
int security_load_policy(void *data, size_t len) { __attribute__((constructor))
static void preload_init() {
// Make sure our next exec won't get bugged // Make sure our next exec won't get bugged
unsetenv("LD_PRELOAD"); unsetenv("LD_PRELOAD");
unlink("/dev/preload.so"); unlink("/dev/preload.so");
}
int security_load_policy(void *data, size_t len) {
int (*load_policy)(void *, size_t) = dlsym(RTLD_NEXT, "security_load_policy"); int (*load_policy)(void *, size_t) = dlsym(RTLD_NEXT, "security_load_policy");
// Skip checking errors, because if we cannot find the symbol, there // Skip checking errors, because if we cannot find the symbol, there
// isn't much we can do other than crashing anyways. // isn't much we can do other than crashing anyways.