74de835
From 05bdc03130d741e53e1fb45a958d0a2c184be503 Mon Sep 17 00:00:00 2001
74de835
From: Mike Palmiotto <mike.palmiotto@crunchydata.com>
74de835
Date: Wed, 5 Aug 2020 15:43:12 -0400
74de835
Subject: [PATCH] libselinux: use kernel status page by default
74de835
74de835
Commit bc2a8f418e3b ("libselinux: add selinux_status_* interfaces for
74de835
/selinux/status") introduced the sestatus mechanism, which allows for
74de835
mmap()'ing of the kernel status page as a replacement for avc_netlink.
74de835
74de835
The mechanism was initially intended for userspace object managers that
74de835
were calculating access decisions within their application and did not
74de835
rely on the libselinux AVC implementation. In order to properly make use
74de835
of sestatus within avc_has_perm(), the status mechanism needs to
74de835
properly set avc internals during status events; else, avc_enforcing is
74de835
never updated upon sestatus changes.
74de835
74de835
This commit gets rid of the default avc_netlink_open() in
74de835
avc_init_internal(), replacing it with selinux_status_open(). In the
74de835
event that the kernel status page cannot be mapped, the netlink fallback
74de835
will be used. By default, avc_has_perm_noaudit() and
74de835
selinux_check_access() will now attempt to read the kernel status page,
74de835
which removes a system call from two critical code paths.
74de835
74de835
Since the AVC thread create/stop callbacks were intended to avoid a
74de835
system call in the critical code path, they no longer need to be created
74de835
by default. In the event that the kernel status page is successfully
74de835
mapped, threads will not be created. Threads will still be
74de835
created/stopped for the sestatus fallback codepaths.
74de835
74de835
Userspace object managers that still need a netlink socket can call
74de835
avc_netlink_acquire_fd() to open and/or obtain one.
74de835
74de835
Update the manpage to reflect the new avc_netlink_acquire_fd()
74de835
functionality.
74de835
74de835
Signed-off-by: Mike Palmiotto <mike.palmiotto@crunchydata.com>
74de835
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
74de835
---
74de835
 libselinux/man/man3/avc_init.3            | 51 ++++++++++++--
74de835
 libselinux/man/man3/avc_netlink_loop.3    |  8 +++
74de835
 libselinux/man/man3/avc_open.3            | 36 +++++++++-
74de835
 libselinux/man/man3/selinux_status_open.3 | 13 ++--
74de835
 libselinux/src/avc.c                      | 15 ++---
74de835
 libselinux/src/avc_internal.c             | 82 ++++++++++++++++-------
74de835
 libselinux/src/avc_internal.h             |  4 ++
74de835
 libselinux/src/checkAccess.c              |  2 +-
74de835
 libselinux/src/sestatus.c                 | 24 +++++++
74de835
 9 files changed, 184 insertions(+), 51 deletions(-)
74de835
74de835
diff --git a/libselinux/man/man3/avc_init.3 b/libselinux/man/man3/avc_init.3
74de835
index e26c3be6071c..a5dc7c93c703 100644
74de835
--- a/libselinux/man/man3/avc_init.3
74de835
+++ b/libselinux/man/man3/avc_init.3
74de835
@@ -117,6 +117,8 @@ argument, which does not return under normal conditions.  The
74de835
 callback should cancel the running thread referenced by 
74de835
 .IR thread .
74de835
 By default, threading is not used; see 
74de835
+.B KERNEL STATUS PAGE
74de835
+and
74de835
 .B NETLINK NOTIFICATION
74de835
 below.
74de835
 
74de835
@@ -153,14 +155,49 @@ callback should destroy
74de835
 .IR lock ,
74de835
 freeing any resources associated with it.  The default behavior is not to perform any locking.  Note that undefined behavior may result if threading is used without appropriate locking.
74de835
 .
74de835
-.SH "NETLINK NOTIFICATION"
74de835
-Beginning with version 2.6.4, the Linux kernel supports SELinux status change notification via netlink.  Two message types are currently implemented, indicating changes to the enforcing mode and to the loaded policy in the kernel, respectively.  The userspace AVC listens for these messages and takes the appropriate action, modifying the behavior of
74de835
-.BR avc_has_perm (3)
74de835
-to reflect the current enforcing mode and flushing the cache on receipt of a policy load notification.  Audit messages are produced when netlink notifications are processed.
74de835
+.SH "KERNEL STATUS PAGE"
74de835
+Linux kernel version 2.6.37 supports the SELinux kernel status page, enabling userspace applications to
74de835
+.BR mmap (2)
74de835
+SELinux status state in read-only mode to avoid system calls during the cache hit code path.
74de835
 
74de835
-In the default single-threaded mode, the userspace AVC checks for new netlink messages at the start of each permission query.  If threading and locking callbacks are passed to
74de835
 .BR avc_init ()
74de835
-however, a dedicated thread will be started to listen on the netlink socket.  This may increase performance and will ensure that log messages are generated immediately rather than at the time of the next permission query.
74de835
+calls
74de835
+.BR selinux_status_open (3)
74de835
+to initialize the selinux status state. If successfully initialized, the userspace AVC will default to single-threaded mode and ignore the
74de835
+.B func_create_thread
74de835
+and
74de835
+.B func_stop_thread
74de835
+callbacks. All callbacks set via
74de835
+.BR selinux_set_callback (3)
74de835
+will still be honored.
74de835
+
74de835
+.BR avc_has_perm (3)
74de835
+and
74de835
+.BR selinux_check_access (3)
74de835
+both check for status updates through calls to
74de835
+.BR selinux_status_updated (3)
74de835
+at the start of each permission query and take the appropriate action.
74de835
+
74de835
+Two status types are currently implemented.
74de835
+.B setenforce
74de835
+events will change the effective enforcing state used within the AVC, and
74de835
+.B policyload
74de835
+events will result in a cache flush.
74de835
+.
74de835
+.SH "NETLINK NOTIFICATION"
74de835
+In the event that the kernel status page is not successfully
74de835
+.BR mmap (2)'ed
74de835
+the AVC will default to the netlink fallback mechanism, which opens a netlink socket for receiving status updates.
74de835
+.B setenforce
74de835
+and
74de835
+.B policyload
74de835
+events will have the same results as for the status page implementation, but all status update checks will now require a system call.
74de835
+
74de835
+By default,
74de835
+.BR avc_open (3)
74de835
+does not set threading or locking callbacks. In the fallback case, the userspace AVC checks for new netlink messages at the start of each permission query. If threading and locking callbacks are passed to
74de835
+.BR avc_init (),
74de835
+a dedicated thread will be started to listen on the netlink socket.  This may increase performance in the absence of the status page and will ensure that log messages are generated immediately rather than at the time of the next permission query.
74de835
 .
74de835
 .SH "RETURN VALUE"
74de835
 Functions with a return value return zero on success.  On error, \-1 is returned and
74de835
@@ -192,5 +229,7 @@ Eamon Walsh <ewalsh@tycho.nsa.gov>
74de835
 .
74de835
 .SH "SEE ALSO"
74de835
 .BR avc_open (3),
74de835
+.BR selinux_status_open (3),
74de835
+.BR selinux_status_updated (3),
74de835
 .BR selinux_set_callback (3),
74de835
 .BR selinux (8)
74de835
diff --git a/libselinux/man/man3/avc_netlink_loop.3 b/libselinux/man/man3/avc_netlink_loop.3
74de835
index c8268a124df0..f03d78138d8c 100644
74de835
--- a/libselinux/man/man3/avc_netlink_loop.3
74de835
+++ b/libselinux/man/man3/avc_netlink_loop.3
74de835
@@ -54,6 +54,11 @@ closes the netlink socket.  This function is called automatically by
74de835
 returns the netlink socket descriptor number and informs the userspace AVC
74de835
 not to check the socket descriptor automatically on calls to
74de835
 .BR avc_has_perm (3).
74de835
+If no such socket descriptor exists,
74de835
+.BR avc_netlink_acquire_fd (3)
74de835
+will first call
74de835
+.BR avc_netlink_open (3)
74de835
+and then return the resulting fd.
74de835
 
74de835
 .BR avc_netlink_release_fd ()
74de835
 returns control of the netlink socket to the userspace AVC, re-enabling
74de835
@@ -78,6 +83,9 @@ with a return value return zero on success.  On error, \-1 is returned and
74de835
 .I errno
74de835
 is set appropriately.
74de835
 .
74de835
+.SH "AUTHOR"
74de835
+Originally KaiGai Kohei. Updated by Mike Palmiotto <mike.palmiotto@crunchydata.com>
74de835
+.
74de835
 .SH "SEE ALSO"
74de835
 .BR avc_open (3),
74de835
 .BR selinux_set_callback (3),
74de835
diff --git a/libselinux/man/man3/avc_open.3 b/libselinux/man/man3/avc_open.3
74de835
index 5b275a8ee040..3090dd5077c7 100644
74de835
--- a/libselinux/man/man3/avc_open.3
74de835
+++ b/libselinux/man/man3/avc_open.3
74de835
@@ -46,10 +46,37 @@ include the following:
74de835
 .B AVC_OPT_SETENFORCE
74de835
 This option forces the userspace AVC into enforcing mode if the option value is non-NULL; permissive mode otherwise.  The system enforcing mode will be ignored.
74de835
 .
74de835
-.SH "NETLINK NOTIFICATION"
74de835
-Beginning with version 2.6.4, the Linux kernel supports SELinux status change notification via netlink.  Two message types are currently implemented, indicating changes to the enforcing mode and to the loaded policy in the kernel, respectively.  The userspace AVC listens for these messages and takes the appropriate action, modifying the behavior of
74de835
+.SH "KERNEL STATUS PAGE"
74de835
+Linux kernel version 2.6.37 supports the SELinux kernel status page, enabling userspace applications to
74de835
+.BR mmap (2)
74de835
+SELinux status state in read-only mode to avoid system calls during the cache hit code path.
74de835
+
74de835
+.BR avc_open ()
74de835
+calls
74de835
+.BR selinux_status_open (3)
74de835
+to initialize the selinux status state.
74de835
+
74de835
 .BR avc_has_perm (3)
74de835
-to reflect the current enforcing mode and flushing the cache on receipt of a policy load notification.  Audit messages are produced when netlink notifications are processed.
74de835
+and
74de835
+.BR selinux_check_access (3)
74de835
+both check for status updates through calls to
74de835
+.BR selinux_status_updated (3)
74de835
+at the start of each permission query and take the appropriate action.
74de835
+
74de835
+Two status types are currently implemented.
74de835
+.B setenforce
74de835
+events will change the effective enforcing state used within the AVC, and
74de835
+.B policyload
74de835
+events will result in a cache flush.
74de835
+.
74de835
+.SH "NETLINK NOTIFICATION"
74de835
+In the event that the kernel status page is not successfully
74de835
+.BR mmap (2)'ed
74de835
+the AVC will default to the netlink fallback mechanism, which opens a netlink socket for receiving status updates.
74de835
+.B setenforce
74de835
+and
74de835
+.B policyload
74de835
+events will have the same results as for the status page implementation, but all status update checks will now require a system call.
74de835
 .
74de835
 .SH "RETURN VALUE"
74de835
 Functions with a return value return zero on success.  On error, \-1 is returned and
74de835
@@ -61,9 +88,12 @@ Eamon Walsh <ewalsh@tycho.nsa.gov>
74de835
 .
74de835
 .SH "SEE ALSO"
74de835
 .BR selinux (8),
74de835
+.BR selinux_check_access (3),
74de835
 .BR avc_has_perm (3),
74de835
 .BR avc_context_to_sid (3),
74de835
 .BR avc_cache_stats (3),
74de835
 .BR avc_add_callback (3),
74de835
+.BR selinux_status_open (3),
74de835
+.BR selinux_status_updated (3),
74de835
 .BR selinux_set_callback (3),
74de835
 .BR security_compute_av (3)
74de835
diff --git a/libselinux/man/man3/selinux_status_open.3 b/libselinux/man/man3/selinux_status_open.3
74de835
index 2d44be57cbbc..5c9da2f61d19 100644
74de835
--- a/libselinux/man/man3/selinux_status_open.3
74de835
+++ b/libselinux/man/man3/selinux_status_open.3
74de835
@@ -48,7 +48,7 @@ Set 1 on the
74de835
 argument to handle a case of older kernels without kernel status page support.
74de835
 In this case, this function tries to open a netlink socket using
74de835
 .BR avc_netlink_open (3)
74de835
-and overwrite corresponding callbacks ( setenforce and policyload).
74de835
+and overwrite corresponding callbacks (setenforce and policyload).
74de835
 Thus, we need to pay attention to the interaction with these interfaces,
74de835
 when fallback mode is enabled.
74de835
 .sp
74de835
@@ -57,9 +57,14 @@ unmap the kernel status page and close its file descriptor, or close the
74de835
 netlink socket if fallbacked.
74de835
 .sp
74de835
 .BR selinux_status_updated ()
74de835
-informs us whether something has been updated since the last call.
74de835
-It returns 0 if nothing was happened, however, 1 if something has been
74de835
-updated in this duration, or \-1 on error.
74de835
+processes status update events. There are two kinds of status updates.
74de835
+.B setenforce
74de835
+events will change the effective enforcing state used within the AVC, and
74de835
+.B policyload
74de835
+events will result in a cache flush.
74de835
+
74de835
+This function returns 0 if there have been no updates since the last call,
74de835
+1 if there have been updates since the last call, or \-1 on error.
74de835
 .sp
74de835
 .BR selinux_status_getenforce ()
74de835
 returns 0 if SELinux is running in permissive mode, 1 if enforcing mode,
74de835
diff --git a/libselinux/src/avc.c b/libselinux/src/avc.c
74de835
index b4648b2de170..8314d7ba3de6 100644
74de835
--- a/libselinux/src/avc.c
74de835
+++ b/libselinux/src/avc.c
74de835
@@ -50,7 +50,6 @@ struct avc_callback_node {
74de835
 	struct avc_callback_node *next;
74de835
 };
74de835
 
74de835
-static void *avc_netlink_thread = NULL;
74de835
 static void *avc_lock = NULL;
74de835
 static void *avc_log_lock = NULL;
74de835
 static struct avc_node *avc_node_freelist = NULL;
74de835
@@ -215,17 +214,13 @@ static int avc_init_internal(const char *prefix,
74de835
 		avc_enforcing = rc;
74de835
 	}
74de835
 
74de835
-	rc = avc_netlink_open(0);
74de835
+	rc = selinux_status_open(1);
74de835
 	if (rc < 0) {
74de835
 		avc_log(SELINUX_ERROR,
74de835
-			"%s:  can't open netlink socket: %d (%s)\n",
74de835
+			"%s: could not open selinux status page: %d (%s)\n",
74de835
 			avc_prefix, errno, strerror(errno));
74de835
 		goto out;
74de835
 	}
74de835
-	if (avc_using_threads) {
74de835
-		avc_netlink_thread = avc_create_thread(&avc_netlink_loop);
74de835
-		avc_netlink_trouble = 0;
74de835
-	}
74de835
 	avc_running = 1;
74de835
       out:
74de835
 	return rc;
74de835
@@ -557,9 +552,7 @@ void avc_destroy(void)
74de835
 
74de835
 	avc_get_lock(avc_lock);
74de835
 
74de835
-	if (avc_using_threads)
74de835
-		avc_stop_thread(avc_netlink_thread);
74de835
-	avc_netlink_close();
74de835
+	selinux_status_close();
74de835
 
74de835
 	for (i = 0; i < AVC_CACHE_SLOTS; i++) {
74de835
 		node = avc_cache.slots[i];
74de835
@@ -766,7 +759,7 @@ int avc_has_perm_noaudit(security_id_t ssid,
74de835
 		avd_init(avd);
74de835
 
74de835
 	if (!avc_using_threads && !avc_app_main_loop) {
74de835
-		(void)avc_netlink_check_nb();
74de835
+		(void) selinux_status_updated();
74de835
 	}
74de835
 
74de835
 	if (!aeref) {
74de835
diff --git a/libselinux/src/avc_internal.c b/libselinux/src/avc_internal.c
74de835
index 568a3d928ac1..4ef924527e10 100644
74de835
--- a/libselinux/src/avc_internal.c
74de835
+++ b/libselinux/src/avc_internal.c
74de835
@@ -53,6 +53,49 @@ int avc_enforcing = 1;
74de835
 int avc_setenforce = 0;
74de835
 int avc_netlink_trouble = 0;
74de835
 
74de835
+/* process setenforce events for netlink and sestatus */
74de835
+int avc_process_setenforce(int enforcing)
74de835
+{
74de835
+	int rc = 0;
74de835
+
74de835
+	avc_log(SELINUX_INFO,
74de835
+		"%s:  received setenforce notice (enforcing=%d)\n",
74de835
+		avc_prefix, enforcing);
74de835
+	if (avc_setenforce)
74de835
+		goto out;
74de835
+	avc_enforcing = enforcing;
74de835
+	if (avc_enforcing && (rc = avc_ss_reset(0)) < 0) {
74de835
+		avc_log(SELINUX_ERROR,
74de835
+			"%s:  cache reset returned %d (errno %d)\n",
74de835
+			avc_prefix, rc, errno);
74de835
+		return rc;
74de835
+	}
74de835
+
74de835
+out:
74de835
+	return selinux_netlink_setenforce(enforcing);
74de835
+}
74de835
+
74de835
+/* process policyload events for netlink and sestatus */
74de835
+int avc_process_policyload(uint32_t seqno)
74de835
+{
74de835
+	int rc = 0;
74de835
+
74de835
+	avc_log(SELINUX_INFO,
74de835
+		"%s:  received policyload notice (seqno=%u)\n",
74de835
+		avc_prefix, seqno);
74de835
+	rc = avc_ss_reset(seqno);
74de835
+	if (rc < 0) {
74de835
+		avc_log(SELINUX_ERROR,
74de835
+			"%s:  cache reset returned %d (errno %d)\n",
74de835
+			avc_prefix, rc, errno);
74de835
+		return rc;
74de835
+	}
74de835
+
74de835
+	selinux_flush_class_cache();
74de835
+
74de835
+	return selinux_netlink_policyload(seqno);
74de835
+}
74de835
+
74de835
 /* netlink socket code */
74de835
 static int fd = -1;
74de835
 
74de835
@@ -177,20 +220,7 @@ static int avc_netlink_process(void *buf)
74de835
 
74de835
 	case SELNL_MSG_SETENFORCE:{
74de835
 		struct selnl_msg_setenforce *msg = NLMSG_DATA(nlh);
74de835
-		msg->val = !!msg->val;
74de835
-		avc_log(SELINUX_INFO,
74de835
-			"%s:  received setenforce notice (enforcing=%d)\n",
74de835
-			avc_prefix, msg->val);
74de835
-		if (avc_setenforce)
74de835
-			break;
74de835
-		avc_enforcing = msg->val;
74de835
-		if (avc_enforcing && (rc = avc_ss_reset(0)) < 0) {
74de835
-			avc_log(SELINUX_ERROR,
74de835
-				"%s:  cache reset returned %d (errno %d)\n",
74de835
-				avc_prefix, rc, errno);
74de835
-			return rc;
74de835
-		}
74de835
-		rc = selinux_netlink_setenforce(msg->val);
74de835
+		rc = avc_process_setenforce(!!msg->val);
74de835
 		if (rc < 0)
74de835
 			return rc;
74de835
 		break;
74de835
@@ -198,18 +228,7 @@ static int avc_netlink_process(void *buf)
74de835
 
74de835
 	case SELNL_MSG_POLICYLOAD:{
74de835
 		struct selnl_msg_policyload *msg = NLMSG_DATA(nlh);
74de835
-		avc_log(SELINUX_INFO,
74de835
-			"%s:  received policyload notice (seqno=%u)\n",
74de835
-			avc_prefix, msg->seqno);
74de835
-		rc = avc_ss_reset(msg->seqno);
74de835
-		if (rc < 0) {
74de835
-			avc_log(SELINUX_ERROR,
74de835
-				"%s:  cache reset returned %d (errno %d)\n",
74de835
-				avc_prefix, rc, errno);
74de835
-			return rc;
74de835
-		}
74de835
-		selinux_flush_class_cache();
74de835
-		rc = selinux_netlink_policyload(msg->seqno);
74de835
+		rc = avc_process_policyload(msg->seqno);
74de835
 		if (rc < 0)
74de835
 			return rc;
74de835
 		break;
74de835
@@ -284,6 +303,17 @@ void avc_netlink_loop(void)
74de835
 
74de835
 int avc_netlink_acquire_fd(void)
74de835
 {
74de835
+	if (fd < 0) {
74de835
+		int rc = 0;
74de835
+		rc = avc_netlink_open(0);
74de835
+		if (rc < 0) {
74de835
+			avc_log(SELINUX_ERROR,
74de835
+				"%s: could not open netlink socket: %d (%s)\n",
74de835
+				avc_prefix, errno, strerror(errno));
74de835
+			return rc;
74de835
+		}
74de835
+	}
74de835
+
74de835
     avc_app_main_loop = 1;
74de835
 
74de835
     return fd;
74de835
diff --git a/libselinux/src/avc_internal.h b/libselinux/src/avc_internal.h
74de835
index 3f8a6bb1cf84..da67affc9307 100644
74de835
--- a/libselinux/src/avc_internal.h
74de835
+++ b/libselinux/src/avc_internal.h
74de835
@@ -32,6 +32,10 @@ extern void (*avc_func_get_lock) (void *);
74de835
 extern void (*avc_func_release_lock) (void *);
74de835
 extern void (*avc_func_free_lock) (void *);
74de835
 
74de835
+/* selinux status processing for netlink and sestatus */
74de835
+extern int avc_process_setenforce(int enforcing);
74de835
+extern int avc_process_policyload(uint32_t seqno);
74de835
+
74de835
 static inline void set_callbacks(const struct avc_memory_callback *mem_cb,
74de835
 				 const struct avc_log_callback *log_cb,
74de835
 				 const struct avc_thread_callback *thread_cb,
74de835
diff --git a/libselinux/src/checkAccess.c b/libselinux/src/checkAccess.c
74de835
index 3491fded7895..b337ea64f977 100644
74de835
--- a/libselinux/src/checkAccess.c
74de835
+++ b/libselinux/src/checkAccess.c
74de835
@@ -39,7 +39,7 @@ int selinux_check_access(const char *scon, const char *tcon, const char *class,
74de835
 	if (rc < 0)
74de835
 		return rc;
74de835
 
74de835
-	(void) avc_netlink_check_nb();
74de835
+	(void) selinux_status_updated();
74de835
 
74de835
        sclass = string_to_security_class(class);
74de835
        if (sclass == 0) {
74de835
diff --git a/libselinux/src/sestatus.c b/libselinux/src/sestatus.c
74de835
index 86267ff89646..814e86ee10e7 100644
74de835
--- a/libselinux/src/sestatus.c
74de835
+++ b/libselinux/src/sestatus.c
74de835
@@ -39,11 +39,14 @@ struct selinux_status_t
74de835
 static struct selinux_status_t *selinux_status = NULL;
74de835
 static int			selinux_status_fd;
74de835
 static uint32_t			last_seqno;
74de835
+static uint32_t			last_policyload;
74de835
 
74de835
 static uint32_t			fallback_sequence;
74de835
 static int			fallback_enforcing;
74de835
 static int			fallback_policyload;
74de835
 
74de835
+static void			*fallback_netlink_thread = NULL;
74de835
+
74de835
 /*
74de835
  * read_sequence
74de835
  *
74de835
@@ -116,6 +119,15 @@ int selinux_status_updated(void)
74de835
 
74de835
 	if (last_seqno != curr_seqno)
74de835
 	{
74de835
+		if (avc_enforcing != (int) selinux_status->enforcing) {
74de835
+			if (avc_process_setenforce(selinux_status->enforcing) < 0)
74de835
+				return -1;
74de835
+		}
74de835
+		if (last_policyload != selinux_status->policyload) {
74de835
+			if (avc_process_policyload(selinux_status->policyload) < 0)
74de835
+				return -1;
74de835
+			last_policyload = selinux_status->policyload;
74de835
+		}
74de835
 		last_seqno = curr_seqno;
74de835
 		result = 1;
74de835
 	}
74de835
@@ -282,6 +294,9 @@ int selinux_status_open(int fallback)
74de835
 	selinux_status_fd = fd;
74de835
 	last_seqno = (uint32_t)(-1);
74de835
 
74de835
+	/* No need to use avc threads if the kernel status page is available */
74de835
+	avc_using_threads = 0;
74de835
+
74de835
 	return 0;
74de835
 
74de835
 error:
74de835
@@ -305,6 +320,12 @@ error:
74de835
 		selinux_status_fd = avc_netlink_acquire_fd();
74de835
 		last_seqno = (uint32_t)(-1);
74de835
 
74de835
+		if (avc_using_threads)
74de835
+		{
74de835
+			fallback_netlink_thread = avc_create_thread(&avc_netlink_loop);
74de835
+			avc_netlink_trouble = 0;
74de835
+		}
74de835
+
74de835
 		fallback_sequence = 0;
74de835
 		fallback_enforcing = security_getenforce();
74de835
 		fallback_policyload = 0;
74de835
@@ -333,6 +354,9 @@ void selinux_status_close(void)
74de835
 	/* fallback-mode */
74de835
 	if (selinux_status == MAP_FAILED)
74de835
 	{
74de835
+		if (avc_using_threads)
74de835
+			avc_stop_thread(fallback_netlink_thread);
74de835
+
74de835
 		avc_netlink_release_fd();
74de835
 		avc_netlink_close();
74de835
 		selinux_status = NULL;
74de835
-- 
74de835
2.29.0
74de835