Skip to content

Commit 6c5a682

Browse files
stephensmalleypcmoore
authored andcommitted
selinux: clean up selinux_enabled/disabled/enforcing_boot
Rename selinux_enabled to selinux_enabled_boot to make it clear that it only reflects whether SELinux was enabled at boot. Replace the references to it in the MAC_STATUS audit log in sel_write_enforce() with hardcoded "1" values because this code is only reachable if SELinux is enabled and does not change its value, and update the corresponding MAC_STATUS audit log in sel_write_disable(). Stop clearing selinux_enabled in selinux_disable() since it is not used outside of initialization code that runs before selinux_disable() can be reached. Mark both selinux_enabled_boot and selinux_enforcing_boot as __initdata since they are only used in initialization code. Wrap the disabled field in the struct selinux_state with CONFIG_SECURITY_SELINUX_DISABLE since it is only used for runtime disable. Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 210a292 commit 6c5a682

7 files changed

Lines changed: 17 additions & 18 deletions

File tree

‎security/selinux/hooks.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct selinux_state selinux_state;
109109
static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
110110

111111
#ifdef CONFIG_SECURITY_SELINUX_DEVELOP
112-
static int selinux_enforcing_boot;
112+
static int selinux_enforcing_boot __initdata;
113113

114114
static int __init enforcing_setup(char *str)
115115
{
@@ -123,13 +123,13 @@ __setup("enforcing=", enforcing_setup);
123123
#define selinux_enforcing_boot 1
124124
#endif
125125

126-
int selinux_enabled __lsm_ro_after_init = 1;
126+
int selinux_enabled_boot __initdata = 1;
127127
#ifdef CONFIG_SECURITY_SELINUX_BOOTPARAM
128128
static int __init selinux_enabled_setup(char *str)
129129
{
130130
unsigned long enabled;
131131
if (!kstrtoul(str, 0, &enabled))
132-
selinux_enabled = enabled ? 1 : 0;
132+
selinux_enabled_boot = enabled ? 1 : 0;
133133
return 1;
134134
}
135135
__setup("selinux=", selinux_enabled_setup);
@@ -7202,7 +7202,7 @@ void selinux_complete_init(void)
72027202
DEFINE_LSM(selinux) = {
72037203
.name = "selinux",
72047204
.flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE,
7205-
.enabled = &selinux_enabled,
7205+
.enabled = &selinux_enabled_boot,
72067206
.blobs = &selinux_blob_sizes,
72077207
.init = selinux_init,
72087208
};
@@ -7271,7 +7271,7 @@ static int __init selinux_nf_ip_init(void)
72717271
{
72727272
int err;
72737273

7274-
if (!selinux_enabled)
7274+
if (!selinux_enabled_boot)
72757275
return 0;
72767276

72777277
pr_debug("SELinux: Registering netfilter hooks\n");
@@ -7318,8 +7318,6 @@ int selinux_disable(struct selinux_state *state)
73187318

73197319
pr_info("SELinux: Disabled at runtime.\n");
73207320

7321-
selinux_enabled = 0;
7322-
73237321
security_delete_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks));
73247322

73257323
/* Try to destroy the avc node cache */

‎security/selinux/ibpkey.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static __init int sel_ib_pkey_init(void)
222222
{
223223
int iter;
224224

225-
if (!selinux_enabled)
225+
if (!selinux_enabled_boot)
226226
return 0;
227227

228228
for (iter = 0; iter < SEL_PKEY_HASH_SIZE; iter++) {

‎security/selinux/include/security.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
struct netlbl_lsm_secattr;
7171

72-
extern int selinux_enabled;
72+
extern int selinux_enabled_boot;
7373

7474
/* Policy capabilities */
7575
enum {
@@ -99,7 +99,9 @@ struct selinux_avc;
9999
struct selinux_ss;
100100

101101
struct selinux_state {
102+
#ifdef CONFIG_SECURITY_SELINUX_DISABLE
102103
bool disabled;
104+
#endif
103105
#ifdef CONFIG_SECURITY_SELINUX_DEVELOP
104106
bool enforcing;
105107
#endif

‎security/selinux/netif.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static __init int sel_netif_init(void)
266266
{
267267
int i;
268268

269-
if (!selinux_enabled)
269+
if (!selinux_enabled_boot)
270270
return 0;
271271

272272
for (i = 0; i < SEL_NETIF_HASH_SIZE; i++)

‎security/selinux/netnode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static __init int sel_netnode_init(void)
291291
{
292292
int iter;
293293

294-
if (!selinux_enabled)
294+
if (!selinux_enabled_boot)
295295
return 0;
296296

297297
for (iter = 0; iter < SEL_NETNODE_HASH_SIZE; iter++) {

‎security/selinux/netport.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static __init int sel_netport_init(void)
225225
{
226226
int iter;
227227

228-
if (!selinux_enabled)
228+
if (!selinux_enabled_boot)
229229
return 0;
230230

231231
for (iter = 0; iter < SEL_NETPORT_HASH_SIZE; iter++) {

‎security/selinux/selinuxfs.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,10 @@ static ssize_t sel_write_enforce(struct file *file, const char __user *buf,
168168
goto out;
169169
audit_log(audit_context(), GFP_KERNEL, AUDIT_MAC_STATUS,
170170
"enforcing=%d old_enforcing=%d auid=%u ses=%u"
171-
" enabled=%d old-enabled=%d lsm=selinux res=1",
171+
" enabled=1 old-enabled=1 lsm=selinux res=1",
172172
new_value, old_value,
173173
from_kuid(&init_user_ns, audit_get_loginuid(current)),
174-
audit_get_sessionid(current),
175-
selinux_enabled, selinux_enabled);
174+
audit_get_sessionid(current));
176175
enforcing_set(state, new_value);
177176
if (new_value)
178177
avc_ss_reset(state->avc, 0);
@@ -304,10 +303,10 @@ static ssize_t sel_write_disable(struct file *file, const char __user *buf,
304303
goto out;
305304
audit_log(audit_context(), GFP_KERNEL, AUDIT_MAC_STATUS,
306305
"enforcing=%d old_enforcing=%d auid=%u ses=%u"
307-
" enabled=%d old-enabled=%d lsm=selinux res=1",
306+
" enabled=0 old-enabled=1 lsm=selinux res=1",
308307
enforcing, enforcing,
309308
from_kuid(&init_user_ns, audit_get_loginuid(current)),
310-
audit_get_sessionid(current), 0, 1);
309+
audit_get_sessionid(current));
311310
}
312311

313312
length = count;
@@ -2105,7 +2104,7 @@ static int __init init_sel_fs(void)
21052104
sizeof(NULL_FILE_NAME)-1);
21062105
int err;
21072106

2108-
if (!selinux_enabled)
2107+
if (!selinux_enabled_boot)
21092108
return 0;
21102109

21112110
err = sysfs_create_mount_point(fs_kobj, "selinux");

0 commit comments

Comments
 (0)