On Thu, Jan 12, 2023 at 02:19:11PM +0100, Vegard Nossum wrote:
+ns_modules_allowed
+==================
+
+Control whether processes may trigger module loading inside a user namespace.
This is false documentation. The place it is trying to protect simply
prevents trying to call modprobe for auto-loading within the kernel.
+ /*
+ * Disallow module loading if we're in a user namespace.
+ */
+ if (current_user_ns() != &init_user_ns &&
+ !sysctl_ns_modules_allowed) {
+ pr_warn_ratelimited("request_module: pid %d (%s) in user namespace requested kernel module %s; denied due to kernel.ns_modules_allowed sysctl\n",
+ task_pid_nr(current), current->comm, module_name);
+ return -EPERM;
+ }
+
if (atomic_dec_if_positive(&kmod_concurrent_max) < 0) {
pr_warn_ratelimited("request_module: kmod_concurrent_max (%u) close to 0 (max_modprobes: %u), for module %s, throttling...",
atomic_read(&kmod_concurrent_max),
Have you seen what call_modprobe() does?
This is just a limitting the auto-loading through calling modprobe.
If the concern is to load modules wouldn't you be better off just
putting a stop gap at finit_module() which actually receives the
load attempt from modprobe? Ie, an evil namespace, if it has access
to /sbin/modprobe could simply just try calling /sbin/modprobe on its
own.
Beating the royal shit out of kmod is already stress tested via
tools/testing/selftests/kmod/kmod.sh in particular:
tools/testing/selftests/kmod/kmod.sh -t 0008
tools/testing/selftests/kmod/kmod.sh -t 0009
What this *could* do is race to force a failure on some other *real*
modprobe request we do wish to honor when the above kmod kmod_concurrent_max
is triggered.
So in terms of justification, this commit log needs a bit more work as I
just can't see how this alone is fixing any CVE.
So let's take a step back and think this through. What exaclty and why
would this commit fix *any* security issue? Itemizing CVEs won't cut it.