Skip to contentSkip to conversation

security: mark nf ops in SELinux and Smack as __ro_after_init

RFC PATCH In review James Morris 5 participants 13 messages Feb 13, 2017 – Feb 14, 2017

Subsystems (3)
lore
Share & tools
lore

James Morris

author maintainer
#0 lore raw

RFC PATCH 2/4 security: mark nf ops in SELinux and Smack as __ro_after_init

Both SELinux and Smack register Netfilter operations during init, which then don't change. Mark these ops as __ro_after_init.

---
 security/selinux/hooks.c         |    2 +-
 security/smack/smack_netfilter.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
security/selinux/hooks.c +1 -1
index 9599e97..37a7866 100644
@@ -6379,7 +6379,7 @@ void selinux_complete_init(void)
 
 #if defined(CONFIG_NETFILTER)
 
-static struct nf_hook_ops selinux_nf_ops[] = {
+static struct nf_hook_ops selinux_nf_ops[] __ro_after_init = {
 	{
 		.hook =		selinux_ipv4_postroute,
 		.pf =		NFPROTO_IPV4,
security/smack/smack_netfilter.c +1 -1
index 205b785..b945f2c 100644
@@ -57,7 +57,7 @@ static unsigned int smack_ipv4_output(void *priv,
 	return NF_ACCEPT;
 }
 
-static struct nf_hook_ops smack_nf_ops[] = {
+static struct nf_hook_ops smack_nf_ops[] __ro_after_init = {
 	{
 		.hook =		smack_ipv4_output,
 		.pf =		NFPROTO_IPV4,
Signature · 1 line
1.7.1
#1 lore raw
Quoted 4 lines · James Morris

Both SELinux and Smack register Netfilter operations during init, which then don't change. Mark these ops as __ro_after_init.

This patch breaks CONFIG_SECURITY_SELINUX_DISABLE=y + SELINUX=disabled in /etc/selinux/config case, doesn't it? Although I heard that SELinux is planning to remove CONFIG_SECURITY_SELINUX_DISABLE, CONFIG_SECURITY_SELINUX_DISABLE is valid as of current linux-security.git#next .

#2 lore raw
Quoted 9 lines · Tetsuo Handa
Quoted 4 lines · James Morris

Both SELinux and Smack register Netfilter operations during init, which then don't change. Mark these ops as __ro_after_init.

This patch breaks CONFIG_SECURITY_SELINUX_DISABLE=y + SELINUX=disabled in /etc/selinux/config case, doesn't it? Although I heard that SELinux is planning to remove CONFIG_SECURITY_SELINUX_DISABLE, CONFIG_SECURITY_SELINUX_DISABLE is valid as of current linux-security.git#next .

We could fold that removal into this series?

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
#3 lore raw
Quoted 10 lines · Kees Cook
Quoted 8 lines · Tetsuo Handa
Quoted 5 lines · James Morris

Both SELinux and Smack register Netfilter operations during init, which then don't change.  Mark these ops as __ro_after_init.

Quoted 8 lines
Quoted 6 lines

This patch breaks CONFIG_SECURITY_SELINUX_DISABLE=y + SELINUX=disabled in /etc/selinux/config case,
doesn't it? Although I heard that SELinux is planning to remove CONFIG_SECURITY_SELINUX_DISABLE, CONFIG_SECURITY_SELINUX_DISABLE is valid as of current linux- security.git#next .

We could fold that removal into this series?

I'm personally in favor of removing it, but that support was originally requested by the Fedora distro folks on the grounds that it is too painful to manage kernel boot parameters on some platforms, and therefore they needed an alternative to booting with selinux=0 on the kernel command line.  The documented way to disable SELinux on such distros is through the use of /etc/selinux/config SELINUX=disabled, which relies on this mechanism.  So you'd have to work through removal with the distro folks.

Maybe in the interim we could just wrap the ro-after-init markings under a conditional dependent on !CONFIG_SECURITY_SELINUX_DISABLE so that systems (e.g. Android) that do not rely on this feature could benefit.

maintainer
#4 lore raw
Quoted 24 lines · Stephen Smalley
Quoted 6 lines · Kees Cook
Quoted 4 lines · Tetsuo Handa
Quoted 3 lines · James Morris

Both SELinux and Smack register Netfilter operations during init, which then don't change. Mark these ops as __ro_after_init.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

This patch breaks CONFIG_SECURITY_SELINUX_DISABLE=y + SELINUX=disabled in /etc/selinux/config case,
doesn't it? Although I heard that SELinux is planning to remove CONFIG_SECURITY_SELINUX_DISABLE, CONFIG_SECURITY_SELINUX_DISABLE is valid as of current linux- security.git#next .

We could fold that removal into this series?

I'm personally in favor of removing it, but that support was originally requested by the Fedora distro folks on the grounds that it is too painful to manage kernel boot parameters on some platforms, and therefore they needed an alternative to booting with selinux=0 on the kernel command line. The documented way to disable SELinux on such distros is through the use of /etc/selinux/config SELINUX=disabled, which relies on this mechanism. So you'd have to work through removal with the distro folks.

Quoted 4 lines

Maybe in the interim we could just wrap the ro-after-init markings under a conditional dependent on !CONFIG_SECURITY_SELINUX_DISABLE so that systems (e.g. Android) that do not rely on this feature could benefit.

If we changed CONFIG_SECURITY_SELINUX_DISABLE to CONFIG_SECURITY_DYNAMIC_MODULES and put the __ro_after_init under !CONFIG_SECURITY_DYNAMIC_MODULES we solve both the current and potential future issues.

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 30 lines · Casey Schaufler
Quoted 24 lines · Stephen Smalley
Quoted 6 lines · Kees Cook
Quoted 4 lines · Tetsuo Handa
Quoted 3 lines · James Morris

Both SELinux and Smack register Netfilter operations during init, which then don't change. Mark these ops as __ro_after_init.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

This patch breaks CONFIG_SECURITY_SELINUX_DISABLE=y + SELINUX=disabled in /etc/selinux/config case,
doesn't it? Although I heard that SELinux is planning to remove CONFIG_SECURITY_SELINUX_DISABLE, CONFIG_SECURITY_SELINUX_DISABLE is valid as of current linux- security.git#next .

We could fold that removal into this series?

I'm personally in favor of removing it, but that support was originally requested by the Fedora distro folks on the grounds that it is too painful to manage kernel boot parameters on some platforms, and therefore they needed an alternative to booting with selinux=0 on the kernel command line. The documented way to disable SELinux on such distros is through the use of /etc/selinux/config SELINUX=disabled, which relies on this mechanism. So you'd have to work through removal with the distro folks.

Quoted 4 lines

Maybe in the interim we could just wrap the ro-after-init markings under a conditional dependent on !CONFIG_SECURITY_SELINUX_DISABLE so that systems (e.g. Android) that do not rely on this feature could benefit.

Quoted 4 lines

If we changed CONFIG_SECURITY_SELINUX_DISABLE to CONFIG_SECURITY_DYNAMIC_MODULES and put the __ro_after_init under !CONFIG_SECURITY_DYNAMIC_MODULES we solve both the current and potential future issues.

Something like...

#ifdef CONFIG_SECURITY_DYNAMIC_LSM

# define lsm_ro_after_init __ro_after_init
# define lsm_const         const
#else
# define lsm_ro_after_init
# define lsm_const
#endif

?

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
maintainer
#6 lore raw
Quoted 37 lines · Kees Cook
Quoted 25 lines · Casey Schaufler
Quoted 24 lines · Stephen Smalley
Quoted 6 lines · Kees Cook
Quoted 4 lines · Tetsuo Handa
Quoted 3 lines · James Morris

Both SELinux and Smack register Netfilter operations during init, which then don't change. Mark these ops as __ro_after_init.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

This patch breaks CONFIG_SECURITY_SELINUX_DISABLE=y + SELINUX=disabled in /etc/selinux/config case,
doesn't it? Although I heard that SELinux is planning to remove CONFIG_SECURITY_SELINUX_DISABLE, CONFIG_SECURITY_SELINUX_DISABLE is valid as of current linux- security.git#next .

We could fold that removal into this series?

I'm personally in favor of removing it, but that support was originally requested by the Fedora distro folks on the grounds that it is too painful to manage kernel boot parameters on some platforms, and therefore they needed an alternative to booting with selinux=0 on the kernel command line. The documented way to disable SELinux on such distros is through the use of /etc/selinux/config SELINUX=disabled, which relies on this mechanism. So you'd have to work through removal with the distro folks.

Quoted 8 lines
Quoted 4 lines

Maybe in the interim we could just wrap the ro-after-init markings under a conditional dependent on !CONFIG_SECURITY_SELINUX_DISABLE so that systems (e.g. Android) that do not rely on this feature could benefit.

If we changed CONFIG_SECURITY_SELINUX_DISABLE to CONFIG_SECURITY_DYNAMIC_MODULES and put the __ro_after_init under !CONFIG_SECURITY_DYNAMIC_MODULES we solve both the current and potential future issues.

Something like...

#ifdef CONFIG_SECURITY_DYNAMIC_LSM

Quoted 8 lines
# define lsm_ro_after_init __ro_after_init
# define lsm_const         const
#else
# define lsm_ro_after_init
# define lsm_const
#endif

?

That's more elaborate than I was thinking, but sure. I was going to put ifdefs in the respective declarations, but this may be more in line with modern tastes.

Quoted 3 lines

-Kees

#7 lore raw

Re: [kernel-hardening] Re: [RFC PATCH 2/4] security: mark nf ops inSELinux and Smack as __ro_after_init

In reply to Kees Cook
Quoted 9 lines · Kees Cook
Quoted 4 lines · Casey Schaufler

If we changed CONFIG_SECURITY_SELINUX_DISABLE to CONFIG_SECURITY_DYNAMIC_MODULES and put the __ro_after_init under !CONFIG_SECURITY_DYNAMIC_MODULES we solve both the current and potential future issues.

Something like...

#ifdef CONFIG_SECURITY_DYNAMIC_LSM

Quoted 8 lines
# define lsm_ro_after_init __ro_after_init
# define lsm_const         const
#else
# define lsm_ro_after_init
# define lsm_const
#endif

?

Fedora/RHEL won't use CONFIG_SECURITY_DYNAMIC_LSM=y whereas LKM based LSMs are targeted for such distributions.

I don't worry much about Android, for manufactures who ship their products with TOMOYO enabled can rebuild their kernels. But asking for rebuild of Fedora/RHEL kernels to end users is too painful.

#8 lore raw

Re: [kernel-hardening] Re: [RFC PATCH 2/4] security: mark nf ops inSELinux and Smack as __ro_after_init

Quoted 17 lines · Tetsuo Handa
Quoted 16 lines · Kees Cook
Quoted 4 lines · Casey Schaufler

If we changed CONFIG_SECURITY_SELINUX_DISABLE to CONFIG_SECURITY_DYNAMIC_MODULES and put the __ro_after_init under !CONFIG_SECURITY_DYNAMIC_MODULES we solve both the current and potential future issues.

Something like...

#ifdef CONFIG_SECURITY_DYNAMIC_LSM

# define lsm_ro_after_init __ro_after_init
# define lsm_const         const
#else
# define lsm_ro_after_init
# define lsm_const
#endif
Quoted 8 lines
Quoted 1 line

?

Fedora/RHEL won't use CONFIG_SECURITY_DYNAMIC_LSM=y whereas LKM based LSMs are targeted for such distributions.

I don't worry much about Android, for manufactures who ship their products with TOMOYO enabled can rebuild their kernels. But asking for rebuild of Fedora/RHEL kernels to end users is too painful.

I thought the argument was that Fedora WOULD ship that way, since it needs to have the run-time selinux disabling feature?

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
#9 lore raw
Quoted 24 lines · Kees Cook
Quoted 22 lines · Tetsuo Handa
Quoted 9 lines · Kees Cook
Quoted 4 lines · Casey Schaufler

If we changed CONFIG_SECURITY_SELINUX_DISABLE to CONFIG_SECURITY_DYNAMIC_MODULES and put the __ro_after_init under !CONFIG_SECURITY_DYNAMIC_MODULES we solve both the current and potential future issues.

Something like...

#ifdef CONFIG_SECURITY_DYNAMIC_LSM

Quoted 8 lines
# define lsm_ro_after_init __ro_after_init
# define lsm_const         const
#else
# define lsm_ro_after_init
# define lsm_const
#endif

?

Fedora/RHEL won't use CONFIG_SECURITY_DYNAMIC_LSM=y whereas LKM based LSMs are targeted for such distributions.

Quoted 6 lines
Quoted 3 lines

I don't worry much about Android, for manufactures who ship their products with TOMOYO enabled can rebuild their kernels. But asking for rebuild of Fedora/RHEL kernels to end users is too painful.

I thought the argument was that Fedora WOULD ship that way, since it needs to have the run-time selinux disabling feature?

True only if Fedora/RHEL doesn't separate kernel packages. They can build separate kernel packages for with-/etc/selinux/config environments and without-/etc/selinux/config environments because modules needed for those environments would differ.

author maintainer
#10 lore raw
In reply to Casey Schaufler
Quoted 4 lines · Casey Schaufler

If we changed CONFIG_SECURITY_SELINUX_DISABLE to CONFIG_SECURITY_DYNAMIC_MODULES and put the __ro_after_init under !CONFIG_SECURITY_DYNAMIC_MODULES we solve both the current and potential future issues.

We don't need to solve issues which don't exist and ideally will not exist.

Signature · 2 lines
James Morris
<[email protected]>
maintainer
#11 lore raw
Quoted 9 lines · James Morris
Quoted 4 lines · Casey Schaufler

If we changed CONFIG_SECURITY_SELINUX_DISABLE to CONFIG_SECURITY_DYNAMIC_MODULES and put the __ro_after_init under !CONFIG_SECURITY_DYNAMIC_MODULES we solve both the current and potential future issues.

We don't need to solve issues which don't exist and ideally will not exist.

There is a problem with CONFIG_SECURITY_SELINUX_DISABLE and __ro_after_init that does exist. Whether the possible future issue should or shouldn't exist has no bearing on the existing issue. It's true that we don't need to change CONFIG_SECURITY_SELINUX_DISABLE to CONFIG_SECURITY_DYNAMIC_MODULES to solve the current problem. I suggest that we leave that change to the separate debate on loadable security modules.

author maintainer
#12 lore raw
Quoted 10 lines · Casey Schaufler
Quoted 9 lines · James Morris
Quoted 4 lines · Casey Schaufler

If we changed CONFIG_SECURITY_SELINUX_DISABLE to CONFIG_SECURITY_DYNAMIC_MODULES and put the __ro_after_init under !CONFIG_SECURITY_DYNAMIC_MODULES we solve both the current and potential future issues.

We don't need to solve issues which don't exist and ideally will not exist.

Quoted 7 lines

There is a problem with CONFIG_SECURITY_SELINUX_DISABLE and __ro_after_init that does exist. Whether the possible future issue should or shouldn't exist has no bearing on the existing issue. It's true that we don't need to change CONFIG_SECURITY_SELINUX_DISABLE to CONFIG_SECURITY_DYNAMIC_MODULES to solve the current problem. I suggest that we leave that change to the separate debate on loadable security modules.

Agreed.

Signature · 2 lines
James Morris
<[email protected]>