netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kmod: don't load module unless req process has CAP_SYS_MODULE
@ 2017-05-12 23:22 Mahesh Bandewar
  2017-05-14 10:45 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 14+ messages in thread
From: Mahesh Bandewar @ 2017-05-12 23:22 UTC (permalink / raw)
  To: Ingo Molnar, Greg Kroah-Hartman, LKML, netdev
  Cc: Eric W . Biederman, Kees Cook, David Miller, Eric Dumazet,
	Mahesh Bandewar, Mahesh Bandewar

From: Mahesh Bandewar <maheshb@google.com>

A process inside random user-ns should not load a module, which is
currently possible. As demonstrated in following scenario -

  Create namespaces; especially a user-ns and become root inside.
  $ unshare -rfUp -- unshare -unm -- bash

  Try to load the bridge module. It should fail and this is expected!
  #  modprobe bridge
  WARNING: Error inserting stp (/lib/modules/4.11.0-smp-DEV/kernel/net/802/stp.ko): Operation not permitted
  FATAL: Error inserting bridge (/lib/modules/4.11.0-smp-DEV/kernel/net/bridge/bridge.ko): Operation not permitted

  Verify bridge module is not loaded.
  # lsmod | grep bridge
  #

  Now try to create a bridge inside this newly created net-ns which would
  mean bridge module need to be loaded.
  # ip link add br0 type bridge
  # echo $?
  0
  # lsmod | grep bridge
  bridge                110592  0
  stp                    16384  1 bridge
  llc                    16384  2 bridge,stp
  #

  After this patch -
  # ip link add br0 type bridge
  RTNETLINK answers: Operation not supported
  # echo $?
  2
  # lsmod | grep bridge
  #

Signed-off-by: Mahesh Bandewar <maheshb@google.com>
---
 kernel/kmod.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/kmod.c b/kernel/kmod.c
index 563f97e2be36..ac30157169b7 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -133,6 +133,9 @@ int __request_module(bool wait, const char *fmt, ...)
 #define MAX_KMOD_CONCURRENT 50	/* Completely arbitrary value - KAO */
 	static int kmod_loop_msg;
 
+	if (!capable(CAP_SYS_MODULE))
+		return -EPERM;
+
 	/*
 	 * We don't allow synchronous module loading from async.  Module
 	 * init may invoke async_synchronize_full() which will end up
-- 
2.13.0.rc2.291.g57267f2277-goog

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

end of thread, other threads:[~2017-05-15 19:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-12 23:22 [PATCH] kmod: don't load module unless req process has CAP_SYS_MODULE Mahesh Bandewar
2017-05-14 10:45 ` Greg Kroah-Hartman
2017-05-14 13:57   ` Eric W. Biederman
2017-05-15  6:10     ` Greg Kroah-Hartman
2017-05-15 13:52       ` David Miller
2017-05-15 17:59         ` Mahesh Bandewar (महेश बंडेवार)
2017-05-15 18:14           ` David Miller
2017-05-15 18:20           ` Eric W. Biederman
2017-05-15 19:59             ` Florian Westphal
2017-05-15  2:42   ` Mahesh Bandewar (महेश बंडेवार)
2017-05-15  6:10     ` Greg Kroah-Hartman
2017-05-15 13:12     ` Eric Dumazet
2017-05-15 17:07       ` Kees Cook
2017-05-15 13:48     ` David Miller

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).