6 ms·
This is a good reason for systems running untrusted code to disable module automatic loading. Almost nobody uses DCCP, and as a result, almost nobody looks at t
by geofft 10y ago
This is a good reason for systems running untrusted code to disable module automatic loading. Almost nobody uses DCCP, and as a result, almost nobody looks at the DCCP code, writes bad userspace apps that trigger kernel bugs that get debugged, etc. We rarely see double-frees in the TCP or UDP implementations.
On my Debian kernel, CONFIG_IP_DCCP is set to "m" (in /boot/config-`uname -r`), which means that DCCP support is built as a module. The code isn't loaded until the first program tries to call socket(...IPPROTO_DCCP). At that point, the kernel will look at /proc/sys/kernel/modprobe and run that program, /sbin/modprobe by default, to load dccp.ko.
Automatic module loading is great when e.g. udev runs and detects what hardware you have, but it's probably not something you'd ever need once a system has completed boot. A very simple hardening measure for machines running untrusted unprivileged code is to echo /bin/false > /proc/sys/kernel/modprobe, late in the boot process (e.g., in /etc/rc.local).
The downside is that system administrator won't be able to run tools that require loading modules, of which iptables is probably the most notable one. A better option than /bin/false is a shell script that logs its arguments to syslog, e.g., `logger -p authpriv.info -- "Refused modprobe $*"`. The sysadmin can manually run modprobe on whatever module name got syslogged (or temporarily set /proc/sys/kernel/modprobe back to /sbin/modprobe). And you can alert on that syslog line to see if there's an attack in progress.
(Does anyone know if it's possible to disable module auto-loading for a tree/namespace of processes, e.g. a Docker container, but keep it working for the base system?)
- amluto 10y agoThere's a patchset called "Timgad" floating around to do exactly this.
- youdontknowtho 10y agoThat's really good advice, thank you.
- sdeziel 10y agoroot can undo that with echo /sbin/modprobe > /proc/sys/kernel/modprobe at any time so you are better off using: echo 1 > /proc/sys/kernel/modules_disabled
- sp332 10y agoDoes this work in a container that shares a kernel with the host?
- sdeziel 10y agoNo, /proc/sys/kernel/{modules_disabled,modprobe} are not writable from a container. Tested with LXD on Ubuntu 16.04.
- geofft 10y agoIf you're root, a local privilege escalation isn't going to get you any more privileges than you already have. If you're root in a container, but not root on the outside system, you shouldn't be able to write to /proc/sys/kernel/modprobe, no?
- sdeziel 10y agoI just wanted to mention that the path to modprobe is something reversible (containers aside) if the sysadmin wants autoloading. /proc/sys/kernel/modprobe is not writable from a container. Disabling module loading is not reversible, you need to reboot.
- zuzun 10y ago> Does anyone know if it's possible to disable module auto-loading for a tree/namespace of processes, e.g. a Docker container, but keep it working for the base system? Block CAP_SYS_MODULE or filter init_module syscalls. Container software should have this enabled as sensible default.
- justincormack 10y agoThat is the default in Docker.
- geofft 10y agoThis is module auto-loading, i.e., you don't need CAP_SYS_MODULE, nor do you make an init_module syscall. The only syscall you make is socket(...IPPROTO_DCCP), and the kernel asks /sbin/modprobe (which it runs with full privileges) to load the appropriate module. The userspace program does not have any privileges. Does Docker actually block that? amluto's comment about the Timgad LSM implies that such functionality doesn't exist yet. (And the replies on LKML show the same confusion between explicit module loading, which requires privilege, and auto-loading, which does not. https://lkml.org/lkml/2017/2/6/279 https://lkml.org/lkml/2017/2/6/279) The easy way to try this is to lsmod and look for dccp and dccp_ipv4, `modprobe -r` them if they're already there, run python -c 'from socket import *; socket(AF_INET, 6, 33)' in your container, and lsmod again and see if they're present.
- justincormack 10y agoYeah true. Docker master has a seccomp profile that blocks this socket family though.
- joser 10y agoNot what you ask, but you can blacklist that module with a fake install. https://wiki.debian.org/KernelModuleBlacklisting https://wiki.debian.org/KernelModuleBlacklisting
- julie1 10y agoSimpler: compile everything you know your hardware requires in static. No modules make menuconfig && make dep && make clean && make bzImage And build a package from your new shiny kernel...
- blockoperation 10y ago...or just roll your own kernel with CONFIG_MODULES=n. If you only need a specific set of modules, you might as well just build them in and just forget LKMs altogether. It's not very convenient when you run into some obscure hardware/fs/protocol, but depending on your use case, that might not be an issue (and even in the rare case where it does come up, it's not the end of the world – a minimal kernel build only takes a couple of minutes on a reasonably fast machine). The only case where LKMs really seem necessary (besides in generic distro kernels) is for module development/debugging, but you're probably not going to do that with a production kernel anyway.
- kbenson 10y agoThe last thing I want is to be manually rolling package updates for kernels. That's one of the reasons I use a distro in the first place, to offload testing to a dedicated team of people. If I was still interested in that, I would run Linux From Scratch again. As soon as you've administered 10+ servers at the same time, your patience for variation from the norm and manual patch building goes way down. Once you've administered 100+ servers at the same time, any thoughts of doing that go right out the window. along with the person that brought it up. At that point, any changes are diffs applied to the original package (or a brand new package from scratch) that you put in your local repo. Kernels actually get updates fairly often, which means you either have a lot of work, or you ignore the non-essential updates. Neither are ideal.
- geofft 10y agoYes. Updated packages for this CVE are already out, and you can just `apt-get dist-upgrade && reboot`. Unless you're prepared to invest organizational effort in a kernel build process, the amount of security you gain from running a custom kernel, in exploits that don't affect you, is vastly outweighed by the amount of security you lose when an exploit does affect you and you have to get around to doing a local kernel build. Good luck if the person who usually does it is sick that day. It's certainly possible to build infrastructure to automate compiling, testing, and pushing out a new kernel, but very few organizations are going to justify that much development effort just for security reasons. If you're already building your own kernels because you have other technical reasons for it, and therefore have already put this effort in, then yes, just turn off CONFIG_IP_DCCP and call it done.