mirror of
https://github.com/SELinuxProject/selinux
synced 2025-03-03 00:37:37 +00:00
Use library destructors to destroy per-thread keys.
This prevents the key destructors, intented to free per-thread heap storage, from being called after libselinux has been unloaded. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=680887 Signed-off-by: Eamon Walsh <ewalsh@tycho.nsa.gov>
This commit is contained in:
parent
fdab2ec279
commit
f0b3127ca3
@ -290,6 +290,11 @@ static void matchpathcon_thread_destructor(void __attribute__((unused)) *ptr)
|
||||
matchpathcon_fini();
|
||||
}
|
||||
|
||||
void __attribute__((destructor)) matchpathcon_lib_destructor(void)
|
||||
{
|
||||
__selinux_key_delete(destructor_key);
|
||||
}
|
||||
|
||||
static void matchpathcon_init_once(void)
|
||||
{
|
||||
__selinux_key_create(&destructor_key, matchpathcon_thread_destructor);
|
||||
|
@ -98,6 +98,7 @@ extern int selinux_page_size hidden;
|
||||
/* Make pthread_once optional */
|
||||
#pragma weak pthread_once
|
||||
#pragma weak pthread_key_create
|
||||
#pragma weak pthread_key_delete
|
||||
#pragma weak pthread_setspecific
|
||||
|
||||
/* Call handler iff the first call. */
|
||||
@ -118,6 +119,12 @@ extern int selinux_page_size hidden;
|
||||
pthread_key_create(KEY, DESTRUCTOR); \
|
||||
} while (0)
|
||||
|
||||
#define __selinux_key_delete(KEY) \
|
||||
do { \
|
||||
if (pthread_key_delete != NULL) \
|
||||
pthread_key_delete(KEY); \
|
||||
} while (0)
|
||||
|
||||
#define __selinux_setspecific(KEY, VALUE) \
|
||||
do { \
|
||||
if (pthread_setspecific != NULL) \
|
||||
|
@ -252,6 +252,11 @@ static void setrans_thread_destructor(void __attribute__((unused)) *unused)
|
||||
free(prev_r2c_raw);
|
||||
}
|
||||
|
||||
void __attribute__((destructor)) setrans_lib_destructor(void)
|
||||
{
|
||||
__selinux_key_delete(destructor_key);
|
||||
}
|
||||
|
||||
static inline void init_thread_destructor(void)
|
||||
{
|
||||
if (destructor_initialized == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user