Skip to content

Commit

Permalink
selinux: convert policy read-write lock to RCU
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
stephensmalley authored and pcmoore committed Aug 25, 2020
1 parent c76a2f9 commit 1b8b31a
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 218 deletions.
1 change: 0 additions & 1 deletion security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -7235,7 +7235,6 @@ static __init int selinux_init(void)
memset(&selinux_state, 0, sizeof(selinux_state));
enforcing_set(&selinux_state, selinux_enforcing_boot);
selinux_state.checkreqprot = selinux_checkreqprot_boot;
selinux_ss_init(&selinux_state.ss);
selinux_avc_init(&selinux_state.avc);
mutex_init(&selinux_state.status_lock);

Expand Down
5 changes: 2 additions & 3 deletions security/selinux/include/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/dcache.h>
#include <linux/magic.h>
#include <linux/types.h>
#include <linux/rcupdate.h>
#include <linux/refcount.h>
#include <linux/workqueue.h>
#include "flask.h"
Expand Down Expand Up @@ -84,7 +85,6 @@ extern int selinux_enabled_boot;
#define POLICYDB_BOUNDS_MAXDEPTH 4

struct selinux_avc;
struct selinux_ss;
struct selinux_policy;

struct selinux_state {
Expand All @@ -102,10 +102,9 @@ struct selinux_state {
struct mutex status_lock;

struct selinux_avc *avc;
struct selinux_ss *ss;
struct selinux_policy __rcu *policy;
} __randomize_layout;

void selinux_ss_init(struct selinux_ss **ss);
void selinux_avc_init(struct selinux_avc **avc);

extern struct selinux_state selinux_state;
Expand Down
Loading

0 comments on commit 1b8b31a

Please sign in to comment.