Skip to content

Commit

Permalink
selinux: Remove awful CONFIG_ALWAYS_ENFORCE
Browse files Browse the repository at this point in the history
Change-Id: I0411903968d625fd8399d7464d77e181e2951aaa
  • Loading branch information
underscoremone committed Jul 26, 2017
1 parent 07b76a6 commit 63e27b4
Show file tree
Hide file tree
Showing 10 changed files with 1 addition and 73 deletions.
6 changes: 0 additions & 6 deletions security/selinux/Makefile
Expand Up @@ -2,12 +2,6 @@
# Makefile for building the SELinux module as part of the kernel tree.
#

ifeq ($(CONFIG_SAMSUNG_PRODUCT_SHIP),y)
ifeq ($(SEC_BUILD_OPTION_SELINUX_ENFORCE),true)
EXTRA_CFLAGS += -DCONFIG_ALWAYS_ENFORCE=true
endif
endif

obj-$(CONFIG_SECURITY_SELINUX) := selinux.o

selinux-y := avc.o hooks.o selinuxfs.o netlink.o nlmsgtab.o netif.o \
Expand Down
4 changes: 0 additions & 4 deletions security/selinux/avc.c
Expand Up @@ -685,11 +685,7 @@ static noinline int avc_denied(u32 ssid, u32 tsid,
{
if (flags & AVC_STRICT)
return -EACCES;
#ifdef CONFIG_ALWAYS_ENFORCE
if (!(avd->flags & AVD_FLAGS_PERMISSIVE))
#else
if (selinux_enforcing && !(avd->flags & AVD_FLAGS_PERMISSIVE))
#endif
return -EACCES;

avc_update_node(AVC_CALLBACK_GRANT, requested, ssid,
Expand Down
4 changes: 0 additions & 4 deletions security/selinux/exports.c
Expand Up @@ -18,10 +18,6 @@

bool selinux_is_enabled(void)
{
#ifdef CONFIG_ALWAYS_ENFORCE
return true;
#else
return selinux_enabled;
#endif
}
EXPORT_SYMBOL_GPL(selinux_is_enabled);
22 changes: 0 additions & 22 deletions security/selinux/hooks.c
Expand Up @@ -109,11 +109,7 @@ static int __init enforcing_setup(char *str)
{
unsigned long enforcing;
if (!strict_strtoul(str, 0, &enforcing))
#ifdef CONFIG_ALWAYS_ENFORCE
selinux_enforcing = 1;
#else
selinux_enforcing = enforcing ? 1 : 0;
#endif
return 1;
}
__setup("enforcing=", enforcing_setup);
Expand All @@ -126,11 +122,7 @@ static int __init selinux_enabled_setup(char *str)
{
unsigned long enabled;
if (!strict_strtoul(str, 0, &enabled))
#ifdef CONFIG_ALWAYS_ENFORCE
selinux_enabled = 1;
#else
selinux_enabled = enabled ? 1 : 0;
#endif
return 1;
}
__setup("selinux=", selinux_enabled_setup);
Expand Down Expand Up @@ -4668,11 +4660,7 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
"SELinux: unrecognized netlink message"
" type=%hu for sclass=%hu\n",
nlh->nlmsg_type, sksec->sclass);
#ifdef CONFIG_ALWAYS_ENFORCE
if (security_get_allow_unknown())
#else
if (!selinux_enforcing || security_get_allow_unknown())
#endif
err = 0;
}

Expand Down Expand Up @@ -5954,11 +5942,7 @@ static struct security_operations selinux_ops = {
static __init int selinux_init(void)
{
if (!security_module_enable(&selinux_ops)) {
#ifdef CONFIG_ALWAYS_ENFORCE
selinux_enabled = 1;
#else
selinux_enabled = 0;
#endif
return 0;
}

Expand All @@ -5981,9 +5965,6 @@ static __init int selinux_init(void)

if (register_security(&selinux_ops))
panic("SELinux: Unable to register with kernel.\n");
#ifdef CONFIG_ALWAYS_ENFORCE
selinux_enforcing = 1;
#endif
if (selinux_enforcing)
printk(KERN_DEBUG "SELinux: Starting in enforcing mode\n");
else
Expand Down Expand Up @@ -6060,9 +6041,6 @@ static struct nf_hook_ops selinux_ipv6_ops[] = {
static int __init selinux_nf_ip_init(void)
{
int err = 0;
#ifdef CONFIG_ALWAYS_ENFORCE
selinux_enabled = 1;
#endif
if (!selinux_enabled)
goto out;

Expand Down
3 changes: 0 additions & 3 deletions security/selinux/netif.c
Expand Up @@ -283,9 +283,6 @@ static __init int sel_netif_init(void)
{
int i, err;

#ifdef CONFIG_ALWAYS_ENFORCE
selinux_enabled = 1;
#endif
if (!selinux_enabled)
return 0;

Expand Down
3 changes: 0 additions & 3 deletions security/selinux/netnode.c
Expand Up @@ -312,9 +312,6 @@ static __init int sel_netnode_init(void)
int iter;
int ret;

#ifdef CONFIG_ALWAYS_ENFORCE
selinux_enabled = 1;
#endif
if (!selinux_enabled)
return 0;

Expand Down
3 changes: 0 additions & 3 deletions security/selinux/netport.c
Expand Up @@ -247,9 +247,6 @@ static __init int sel_netport_init(void)
{
int iter;
int ret;
#ifdef CONFIG_ALWAYS_ENFORCE
selinux_enabled = 1;
#endif
if (!selinux_enabled)
return 0;

Expand Down
16 changes: 1 addition & 15 deletions security/selinux/selinuxfs.c
Expand Up @@ -166,20 +166,7 @@ static ssize_t sel_write_enforce(struct file *file, const char __user *buf,
length = -EINVAL;
if (sscanf(page, "%d", &new_value) != 1)
goto out;
#ifdef CONFIG_ALWAYS_ENFORCE
// If build is user build and enforce option is set, selinux is always enforcing
new_value = 1;
length = task_has_security(current, SECURITY__SETENFORCE);
audit_log(current->audit_context, GFP_KERNEL, AUDIT_MAC_STATUS,
"config_always_enforce - true; enforcing=%d old_enforcing=%d auid=%u ses=%u",
new_value, selinux_enforcing,
from_kuid(&init_user_ns, audit_get_loginuid(current)),
audit_get_sessionid(current));
selinux_enforcing = new_value;
avc_ss_reset(0);
selnl_notify_setenforce(new_value);
selinux_status_update_setenforce(new_value);
#else

if (new_value != selinux_enforcing) {
length = task_has_security(current, SECURITY__SETENFORCE);
if (length)
Expand All @@ -195,7 +182,6 @@ static ssize_t sel_write_enforce(struct file *file, const char __user *buf,
selnl_notify_setenforce(selinux_enforcing);
selinux_status_update_setenforce(selinux_enforcing);
}
#endif
length = count;
out:
free_page((unsigned long) page);
Expand Down
9 changes: 0 additions & 9 deletions security/selinux/ss/services.c
Expand Up @@ -735,9 +735,6 @@ static int security_validtrans_handle_fail(struct context *ocontext,
kfree(n);
kfree(t);

#ifdef CONFIG_ALWAYS_ENFORCE
selinux_enforcing = 1;
#endif
if (!selinux_enforcing)
return 0;
return -EPERM;
Expand Down Expand Up @@ -1360,9 +1357,6 @@ static int compute_sid_handle_invalid_context(
kfree(s);
kfree(t);
kfree(n);
#ifdef CONFIG_ALWAYS_ENFORCE
selinux_enforcing = 1;
#endif
if (!selinux_enforcing)
return 0;
return -EACCES;
Expand Down Expand Up @@ -1653,9 +1647,6 @@ static inline int convert_context_handle_invalid_context(struct context *context
{
char *s;
u32 len;
#ifdef CONFIG_ALWAYS_ENFORCE
selinux_enforcing = 1;
#endif
if (selinux_enforcing)
return -EINVAL;

Expand Down
4 changes: 0 additions & 4 deletions security/selinux/ss/status.c
Expand Up @@ -58,11 +58,7 @@ struct page *selinux_kernel_status_page(void)

status->version = SELINUX_KERNEL_STATUS_VERSION;
status->sequence = 0;
#ifdef CONFIG_ALWAYS_ENFORCE
status->enforcing = 1;
#else
status->enforcing = selinux_enforcing;
#endif
/*
* NOTE: the next policyload event shall set
* a positive value on the status->policyload,
Expand Down

0 comments on commit 63e27b4

Please sign in to comment.