Skip to content

Commit aa8e712

Browse files
stephensmalleypcmoore
authored andcommitted
selinux: wrap global selinux state
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 <[email protected]> [PM: minor fixups needed due to collisions with the SCTP patches] Signed-off-by: Paul Moore <[email protected]>
1 parent 2572f5b commit aa8e712

File tree

25 files changed

+1155
-797
lines changed

25 files changed

+1155
-797
lines changed

security/selinux/avc.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,17 @@ static void avc_dump_query(struct audit_buffer *ab, u32 ssid, u32 tsid, u16 tcla
149149
char *scontext;
150150
u32 scontext_len;
151151

152-
rc = security_sid_to_context(ssid, &scontext, &scontext_len);
152+
rc = security_sid_to_context(&selinux_state, ssid,
153+
&scontext, &scontext_len);
153154
if (rc)
154155
audit_log_format(ab, "ssid=%d", ssid);
155156
else {
156157
audit_log_format(ab, "scontext=%s", scontext);
157158
kfree(scontext);
158159
}
159160

160-
rc = security_sid_to_context(tsid, &scontext, &scontext_len);
161+
rc = security_sid_to_context(&selinux_state, tsid,
162+
&scontext, &scontext_len);
161163
if (rc)
162164
audit_log_format(ab, " tsid=%d", tsid);
163165
else {
@@ -969,7 +971,8 @@ static noinline struct avc_node *avc_compute_av(u32 ssid, u32 tsid,
969971
{
970972
rcu_read_unlock();
971973
INIT_LIST_HEAD(&xp_node->xpd_head);
972-
security_compute_av(ssid, tsid, tclass, avd, &xp_node->xp);
974+
security_compute_av(&selinux_state, ssid, tsid, tclass,
975+
avd, &xp_node->xp);
973976
rcu_read_lock();
974977
return avc_insert(ssid, tsid, tclass, avd, xp_node);
975978
}
@@ -982,7 +985,8 @@ static noinline int avc_denied(u32 ssid, u32 tsid,
982985
if (flags & AVC_STRICT)
983986
return -EACCES;
984987

985-
if (selinux_enforcing && !(avd->flags & AVD_FLAGS_PERMISSIVE))
988+
if (is_enforcing(&selinux_state) &&
989+
!(avd->flags & AVD_FLAGS_PERMISSIVE))
986990
return -EACCES;
987991

988992
avc_update_node(AVC_CALLBACK_GRANT, requested, driver, xperm, ssid,
@@ -1043,8 +1047,8 @@ int avc_has_extended_perms(u32 ssid, u32 tsid, u16 tclass, u32 requested,
10431047
goto decision;
10441048
}
10451049
rcu_read_unlock();
1046-
security_compute_xperms_decision(ssid, tsid, tclass, driver,
1047-
&local_xpd);
1050+
security_compute_xperms_decision(&selinux_state, ssid, tsid,
1051+
tclass, driver, &local_xpd);
10481052
rcu_read_lock();
10491053
avc_update_node(AVC_CALLBACK_ADD_XPERMS, requested, driver, xperm,
10501054
ssid, tsid, tclass, avd.seqno, &local_xpd, 0);

0 commit comments

Comments
 (0)