Re: [PATCH RFC] Restrictions on module loading

From: Kees Cook
Date: Mon Nov 08 2010 - 00:14:19 EST


On Sun, Nov 07, 2010 at 08:23:59PM -0500, Dan Rosenberg wrote:
> A significant portion of kernel vulnerabilities do not affect core code,
> but rather individual modules. Unfortunately, there is no global kernel
> setting to restrict unprivileged users from triggering the automatic
> loading of kernel modules, for example by creating a socket using a
> packet family that is compiled as a module and not already loaded. On
> most distributions, this creates a significant attack surface, and
> requires maintenance of blacklists and other inelegant solutions to a
> general problem.
>
> The below patch replaces the existing "modules_disable" sysctl with a
> finer-grained "modules_restrict" sysctl. By default, this is set at 0,
> which results in no deviation from normal module loading behavior. When
> set to 1, unprivileged users cannot trigger the automatic loading of
> modules. This behavior is based on grsecurity's GRKERNSEC_MODHARDEN
> setting. The current check is against current_uid(), since several
> distributions explicitly remove CAP_SYS_MODULE from root processes, some
> of which incidentally cause (and rely on) the automatic loading of
> modules. I expect this to be a point of discussion.
>
> When set to 2, modules may not be loaded or unloaded by anyone, and the
> sysctl may not be changed from that point forward. This is designed to
> provide protection against kernel module rootkits.
>
> Signed-off-by: Dan Rosenberg <drosenberg@xxxxxxxxxxxxx>

Acked-by: Kees Cook <kees.cook@xxxxxxxxxxxxx>

This looks great to me. There will be a small amount of pain for people
that are already using modules_disabled=1, but I think the audience is so
small that it won't be a problem to switch to modules_restrict=2.

-Kees

--
Kees Cook
Ubuntu Security Team
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/