archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] modules:capabilities: automatic module loading restrictions
@ 2017-04-19 22:20 Djalal Harouni
  2017-04-19 22:20 ` [PATCH v3 1/2] modules:capabilities: automatic module loading restriction Djalal Harouni
  2017-04-19 22:20 ` [PATCH v3 2/2] modules:capabilities: add a per-task modules autoload restriction Djalal Harouni
  0 siblings, 2 replies; 38+ messages in thread
From: Djalal Harouni @ 2017-04-19 22:20 UTC (permalink / raw)
  To: Linux Kernel Mailing List, Andy Lutomirski, Kees Cook,
	Andrew Morton, serge-A9i7LUbDfNHQT0dZR+AlfA,
  Cc: Linux API, Dongsu Park, Casey Schaufler, James Morris,
	Paul Moore, Tetsuo Handa, Greg Kroah-Hartman, Jonathan Corbet,
	Jessica Yu, Rusty Russell, Arnaldo Carvalho de Melo,
	Mauro Carvalho Chehab, Ingo Molnar,
	zendyani-Re5JQEeQqe8AvxtiuMwx3w, Peter Zijlstra, Djalal Harouni

Hi List,

This is an update of the previous two RFCs that implemented module
auto-load restriction as a stackable LSM [1] [2].

The previous versions were presented as a stackable LSM, this new
version is implemented as a core kernel feature inside the capability

This new version is clean and smaller compared to previous versions.
Kees Cook suggested to implement this as a core kernel feature so it is
easy to enable and to be more consistent with "modules_disabled" sysctl
that restrict all module operations.

These patches are against next-20170419


Currently, an explicit call to load or unload kernel modules require
CAP_SYS_MODULE capability. However unprivileged users have always been
able to load some modules using the implicit auto-load operation. An
automatic module loading happens when programs request a kernel feature
from a module that is not loaded. In order to satisfy userspace, the
kernel then automatically load all these required modules.

However, some programs may abuse the interface to load vulnerable or
buggy modules where system administrators still did not have a chance to
blacklist these modules. This affects the global state of the machine,
especially with containers where some applications may use it to exploit
the vulnerable parts and escape the container sandbox. Not to mention
that some devices which one may call IoT also started to use containers
semantics as a deployment workflow, but as an isolation tool too where the
base system image can be any generic distro or other root filesystem with
its own kernel. These setups may include unnecessary modules that the
final applications will not need. Untrusted access may abuse the module
auto-load feature to expose those vulnerabilities.

As every code contains bugs or vulnerabilties, the following
vulnerabilities that affected some features that are often compiled as
modules could have been completely blocked, by restricting autoloading
modules if the system does not need them.

Past months:
* DCCP use after free CVE-2017-6074
* n_hldc CVE-2017-2636
* XFRM framework CVE-2017-7184
* L2TPv3 CVE-2016-10200

Some of these bugs where advertised, websites claim that they have been
used against some distros in security contests. Other devices may also
be subject to such abuses, so lets protect our systems.

This patch introduces "modules_autoload" kernel sysctl flag. The flag
controls modules auto-load feature and complements "modules_disabled" which
apply to all modules operations. This new flag allows to control only
automatic module loading and if it is allowed or not. This allows to
align implicit module loading with the explicit one where both now are
covered by capabilities checks.

The "modules_autoload" sysctl was inspired from grsecurity

/proc/sys/kernel/modules_autoload takes three values:

*) When set to (0), the default, there are no restrictions.

*) When set to (1), processes must have CAP_SYS_MODULE to be able to
trigger a module auto-load operation, or CAP_NET_ADMIN for modules with
a 'netdev-%s' alias. Maybe in future more capabilities will allow to
load the specific related modules.

*) When set to (2), automatic module loading is disabled for all. Once
set, this value can not be changed.

The patches also support process trees, containers, and sandboxes by
providing an inherited per-task "modules_autoload" flag that cannot be
re-enabled once disabled. Any task can set its "modules_autoload" by

        prctl(PR_SET_MODULES_AUTOLOAD, value, 0, 0, 0).

*) When value is (0), the default, automatic modules loading is allowed.

*) When value is (1), task must have CAP_SYS_MODULE to be able to
trigger a module auto-load operation, or CAP_NET_ADMIN for modules with
a 'netdev-%s' alias. The capabilities checks are in the initial user

*) When value is (2), automatic modules loading is disabled for the
current task.

The per-task "modules_autoload" value may only be increased, never
decreased, thus ensuring that once applied, processes can never relax
their setting.

The prctl() interface allows to restrict automatic module loading for
untrusted users without affecting the functionality of the rest of the

When a request to a kernel module is denied, the module name with the
corresponding process name and its pid are logged. Administrators can use
such information to explicitly load the appropriate modules.

# Testing:

The following tool can be used to test the feature:

$ lsmod | grep ipip -
$ sudo ip tunnel add mytun mode ipip remote local ttl 255
$ lsmod | grep ipip -
ipip                   16384  0
tunnel4                16384  1 ipip
ip_tunnel              28672  1 ipip

$ lsmod | grep ipip -
$ ./pr_modules_autoload
$ grep "Modules" /proc/self/status
ModulesAutoload:        2
$ sudo ip tunnel add mytun mode ipip remote local ttl 255 
add tunnel "tunl0" failed: No such device
$ lsmod | grep ipip
$ dmesg | tail -3
[   16.363903] virbr0: port 1(virbr0-nic) entered disabled state
[  823.565958] Automatic module loading of netdev-tunl0 by "ip"[1362] was denied
[  823.565967] Automatic module loading of tunl0 by "ip"[1362] was denied

Finally we already have a use case for the prctl() interface to enforce
some systemd services [3], and we plan to use it for our containers and

# Changes since v2:
*) Implemented as a core kernel feature inside capabilities subsystem
*) Renamed sysctl to "modules_autoload" to align with "modules_disabled"
*) Improved documentation.
*) Removed unused code.

# Changes since v1:
*) Renamed module to ModAutoRestrict
*) Improved documentation to explicity refer to module autoloading.
*) Switched to use the new task_security_alloc() hook.
*) Switched from rhash tables to use task->security since it is in
   linux-security/next branch now.
*) Check all parameters passed to prctl() syscall.
*) Many other bug fixes and documentation improvements.


^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2017-05-05 16:18 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-19 22:20 [PATCH v3 0/2] modules:capabilities: automatic module loading restrictions Djalal Harouni
2017-04-19 22:20 ` [PATCH v3 1/2] modules:capabilities: automatic module loading restriction Djalal Harouni
2017-04-19 23:16   ` Andy Lutomirski
2017-04-20  2:22   ` Ben Hutchings
2017-04-20 12:44     ` [kernel-hardening] " Djalal Harouni
2017-04-20 15:02       ` Ben Hutchings
     [not found]         ` <1492700543.31767.23.camel-/>
2017-04-20 20:39           ` [kernel-hardening] " Djalal Harouni
     [not found]             ` <>
2017-04-20 21:28               ` Kees Cook
2017-04-19 22:20 ` [PATCH v3 2/2] modules:capabilities: add a per-task modules autoload restriction Djalal Harouni
2017-04-19 23:15   ` Andy Lutomirski
2017-04-19 23:43     ` Kees Cook
2017-04-20  2:41       ` Andy Lutomirski
     [not found]         ` <>
2017-04-21 23:19           ` Kees Cook
2017-04-21 23:28             ` Andy Lutomirski
2017-04-21 23:40               ` Kees Cook
2017-04-21 23:51                 ` Andy Lutomirski
2017-04-22  0:12                   ` Djalal Harouni
     [not found]                     ` <>
2017-04-22  1:19                       ` Djalal Harouni
2017-04-22  6:51                       ` Andy Lutomirski
     [not found]                         ` <>
2017-04-22 19:29                           ` Kees Cook
     [not found]                             ` <>
2017-04-24 14:25                               ` Djalal Harouni
2017-04-24 18:02                                 ` Kees Cook
     [not found]                                   ` <>
2017-04-24 18:35                                     ` Djalal Harouni
2017-04-21 23:52               ` Casey Schaufler
2017-04-22  0:00                 ` Andy Lutomirski
2017-04-22  0:13                   ` Casey Schaufler
2017-04-22  6:45                     ` Andy Lutomirski
2017-04-22 12:17               ` Djalal Harouni
     [not found]                 ` <>
2017-05-04 13:07                   ` Djalal Harouni
2017-05-04 14:58                     ` Serge E. Hallyn
2017-05-05 13:06                       ` Djalal Harouni
2017-05-05 16:18                     ` Andy Lutomirski
2017-04-20  1:57   ` kbuild test robot
     [not found]   ` <>
2017-04-19 22:38     ` Djalal Harouni
2017-04-24  4:29     ` Rusty Russell
2017-04-26  9:06       ` Djalal Harouni
2017-04-27  2:07         ` Rusty Russell
     [not found]           ` <87k266hacq.fsf-8n+1lVoiYb80n/>
2017-04-27 13:16             ` Djalal Harouni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).