Skip to content

Commit 1b8b31a

Browse files
stephensmalleypcmoore
authored andcommitted
selinux: convert policy read-write lock to RCU
Convert the policy read-write lock to RCU. This is significantly simplified by the earlier work to encapsulate the policy data structures and refactor the policy load and boolean setting logic. Move the latest_granting sequence number into the selinux_policy structure so that it can be updated atomically with the policy. Since removing the policy rwlock and moving latest_granting reduces the selinux_ss structure to nothing more than a wrapper around the selinux_policy pointer, get rid of the extra layer of indirection. At present this change merely passes a hardcoded 1 to rcu_dereference_check() in the cases where we know we do not need to take rcu_read_lock(), with the preceding comment explaining why. Alternatively we could pass fsi->mutex down from selinuxfs and apply a lockdep check on it instead. Based in part on earlier attempts to convert the policy rwlock to RCU by Kaigai Kohei [1] and by Peter Enderborg [2]. [1] https://lore.kernel.org/selinux/[email protected]/ [2] https://lore.kernel.org/selinux/[email protected]/ Signed-off-by: Stephen Smalley <[email protected]> Reviewed-by: Ondrej Mosnacek <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent c76a2f9 commit 1b8b31a

File tree

4 files changed

+280
-218
lines changed

4 files changed

+280
-218
lines changed

security/selinux/hooks.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7235,7 +7235,6 @@ static __init int selinux_init(void)
72357235
memset(&selinux_state, 0, sizeof(selinux_state));
72367236
enforcing_set(&selinux_state, selinux_enforcing_boot);
72377237
selinux_state.checkreqprot = selinux_checkreqprot_boot;
7238-
selinux_ss_init(&selinux_state.ss);
72397238
selinux_avc_init(&selinux_state.avc);
72407239
mutex_init(&selinux_state.status_lock);
72417240

security/selinux/include/security.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/dcache.h>
1414
#include <linux/magic.h>
1515
#include <linux/types.h>
16+
#include <linux/rcupdate.h>
1617
#include <linux/refcount.h>
1718
#include <linux/workqueue.h>
1819
#include "flask.h"
@@ -84,7 +85,6 @@ extern int selinux_enabled_boot;
8485
#define POLICYDB_BOUNDS_MAXDEPTH 4
8586

8687
struct selinux_avc;
87-
struct selinux_ss;
8888
struct selinux_policy;
8989

9090
struct selinux_state {
@@ -102,10 +102,9 @@ struct selinux_state {
102102
struct mutex status_lock;
103103

104104
struct selinux_avc *avc;
105-
struct selinux_ss *ss;
105+
struct selinux_policy __rcu *policy;
106106
} __randomize_layout;
107107

108-
void selinux_ss_init(struct selinux_ss **ss);
109108
void selinux_avc_init(struct selinux_avc **avc);
110109

111110
extern struct selinux_state selinux_state;

0 commit comments

Comments
 (0)