Skip to content

Commit

Permalink
selinux: wrap global selinux state
Browse files Browse the repository at this point in the history
Define a selinux state structure (struct selinux_state) for
global SELinux state and pass it explicitly to all security server
functions.  The public portion of the structure contains state
that is used throughout the SELinux code, such as the enforcing mode.
The structure also contains a pointer to a selinux_ss structure whose
definition is private to the security server and contains security
server specific state such as the policy database and SID table.

This change should have no effect on SELinux behavior or APIs
(userspace or LSM).  It merely wraps SELinux state and passes it
explicitly as needed.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
[PM: minor fixups needed due to collisions with the SCTP patches]
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
Stephen Smalley authored and Paul Moore committed Mar 1, 2018
1 parent 2572f5b commit aa8e712
Show file tree
Hide file tree
Showing 25 changed files with 1,155 additions and 797 deletions.
16 changes: 10 additions & 6 deletions security/selinux/avc.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,17 @@ static void avc_dump_query(struct audit_buffer *ab, u32 ssid, u32 tsid, u16 tcla
char *scontext;
u32 scontext_len;

rc = security_sid_to_context(ssid, &scontext, &scontext_len);
rc = security_sid_to_context(&selinux_state, ssid,
&scontext, &scontext_len);
if (rc)
audit_log_format(ab, "ssid=%d", ssid);
else {
audit_log_format(ab, "scontext=%s", scontext);
kfree(scontext);
}

rc = security_sid_to_context(tsid, &scontext, &scontext_len);
rc = security_sid_to_context(&selinux_state, tsid,
&scontext, &scontext_len);
if (rc)
audit_log_format(ab, " tsid=%d", tsid);
else {
Expand Down Expand Up @@ -969,7 +971,8 @@ static noinline struct avc_node *avc_compute_av(u32 ssid, u32 tsid,
{
rcu_read_unlock();
INIT_LIST_HEAD(&xp_node->xpd_head);
security_compute_av(ssid, tsid, tclass, avd, &xp_node->xp);
security_compute_av(&selinux_state, ssid, tsid, tclass,
avd, &xp_node->xp);
rcu_read_lock();
return avc_insert(ssid, tsid, tclass, avd, xp_node);
}
Expand All @@ -982,7 +985,8 @@ static noinline int avc_denied(u32 ssid, u32 tsid,
if (flags & AVC_STRICT)
return -EACCES;

if (selinux_enforcing && !(avd->flags & AVD_FLAGS_PERMISSIVE))
if (is_enforcing(&selinux_state) &&
!(avd->flags & AVD_FLAGS_PERMISSIVE))
return -EACCES;

avc_update_node(AVC_CALLBACK_GRANT, requested, driver, xperm, ssid,
Expand Down Expand Up @@ -1043,8 +1047,8 @@ int avc_has_extended_perms(u32 ssid, u32 tsid, u16 tclass, u32 requested,
goto decision;
}
rcu_read_unlock();
security_compute_xperms_decision(ssid, tsid, tclass, driver,
&local_xpd);
security_compute_xperms_decision(&selinux_state, ssid, tsid,
tclass, driver, &local_xpd);
rcu_read_lock();
avc_update_node(AVC_CALLBACK_ADD_XPERMS, requested, driver, xperm,
ssid, tsid, tclass, avd.seqno, &local_xpd, 0);
Expand Down
Loading

0 comments on commit aa8e712

Please sign in to comment.