Re: [PATCH] selinux: add selinux_is_enforced() function

From: Stephen Smalley
Date: Wed Apr 12 2017 - 08:09:45 EST


On Wed, 2017-04-12 at 18:06 +0900, Sebastien Buisson wrote:
> Add selinux_is_enforced() function to give access to SELinux
> enforcement to the rest of the kernel.
>
> Signed-off-by: Sebastien Buisson <sbuisson@xxxxxxx>
> ---
> Âinclude/linux/selinux.hÂÂÂÂÂÂÂÂÂÂÂÂÂ| 5 +++++
> Âsecurity/selinux/exports.cÂÂÂÂÂÂÂÂÂÂ| 6 ++++++
> Âsecurity/selinux/hooks.cÂÂÂÂÂÂÂÂÂÂÂÂ| 2 ++
> Âsecurity/selinux/include/avc.hÂÂÂÂÂÂ| 6 ------
> Âsecurity/selinux/include/security.h | 1 +
> Â5 files changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/selinux.h b/include/linux/selinux.h
> index 44f4596..1007321 100644
> --- a/include/linux/selinux.h
> +++ b/include/linux/selinux.h
> @@ -24,12 +24,17 @@
> Â * selinux_is_enabled - is SELinux enabled?
> Â */
> Âbool selinux_is_enabled(void);
> +bool selinux_is_enforced(void);
> Â#else
> Â
> Âstatic inline bool selinux_is_enabled(void)
> Â{
> Â return false;
> Â}
> +static inline bool selinux_is_enforced(void)
> +{
> + return false;
> +}
> Â#endif /* CONFIG_SECURITY_SELINUX */
> Â
> Â#endif /* _LINUX_SELINUX_H */
> diff --git a/security/selinux/exports.c b/security/selinux/exports.c
> index e75dd94..016f1e2 100644
> --- a/security/selinux/exports.c
> +++ b/security/selinux/exports.c
> @@ -21,3 +21,9 @@ bool selinux_is_enabled(void)
> Â return selinux_enabled;
> Â}
> ÂEXPORT_SYMBOL_GPL(selinux_is_enabled);
> +
> +bool selinux_is_enforced(void)
> +{
> + return selinux_enforcing;
> +}
> +EXPORT_SYMBOL_GPL(selinux_is_enforced);
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index e67a526..da2baeb 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -109,6 +109,8 @@ static int __init enforcing_setup(char *str)
> Â return 1;
> Â}
> Â__setup("enforcing=", enforcing_setup);
> +#else
> +int selinux_enforcing;
> Â#endif
> Â
> Â#ifdef CONFIG_SECURITY_SELINUX_BOOTPARAM
> diff --git a/security/selinux/include/avc.h
> b/security/selinux/include/avc.h
> index 0999df0..ff98351 100644
> --- a/security/selinux/include/avc.h
> +++ b/security/selinux/include/avc.h
> @@ -19,12 +19,6 @@
> Â#include "av_permissions.h"
> Â#include "security.h"
> Â
> -#ifdef CONFIG_SECURITY_SELINUX_DEVELOP
> -extern int selinux_enforcing;
> -#else
> -#define selinux_enforcing 1
> -#endif

If CONFIG_SECURITY_SELINUX_DEVELOP=n, then selinux_enforcing is
supposed to always be 1, i.e. global permissive mode is not supported.
Your patch breaks that. That's in addition to the points raised by
others about needing an in-tree user and use of a LSM hook interface
instead.

> -
> Â/*
> Â * An entry in the AVC.
> Â */
> diff --git a/security/selinux/include/security.h
> b/security/selinux/include/security.h
> index f979c35..1e67e268 100644
> --- a/security/selinux/include/security.h
> +++ b/security/selinux/include/security.h
> @@ -64,6 +64,7 @@
> Âstruct netlbl_lsm_secattr;
> Â
> Âextern int selinux_enabled;
> +extern int selinux_enforcing;
> Â
> Â/* Policy capabilities */
> Âenum {