If you host things on the internet I’m going to hazard a guess that the last few weeks have left you pretty tired. Perhaps you’ve wondered whether there is even any point in trying to secure your stuff. Why bother trying to lock down services when anyone who exploits them can just slop up an LPE and pop your kernel?
I don’t have answers, exactly, but I am going to offer up a couple of relatively easy things I’ve done to try to reduce my exposure to python2heck or whatever.
audit net/ modules¶
Linux’s net tree is involved in a lot of the exploits for a good reason. It has been quite slow to adopt defensive programming practices, it’s full of code you theoretically could but almost certainly don’t run, and much of it is easily autoloaded by any process by simply calling socket().
Thus I strongly suggest blocking any net/ modules that your systems are running happily without. I think this would have pre-empted at least four LPE vulnerabilities for me this year, but I haven’t been counting. It could be more.
I came up with my list by comparing the .ko files in /lib/modules with the output of lsmod.1
systemd sandboxing¶
When I started trying to think of things to improve, I initially dismissed the idea of revisiting my systemd sandboxing settings. What’s the point of relying on a broken kernel to confine rogue processes?
But of course that’s not quite right. Sandboxing is still useful if it protects the kernel attack surface an exploit relied on. Two obvious settings that can help are RestrictNamespaces and SystemCallFilter.
User namespaces allow unprivileged processes to use systems that are otherwise only for root, like netfilter. While things are slowly improving, the security of these systems against hostile userland is generally not as good as in the areas that are traditionally exposed to all users. There are some very useful uses of user namespaces, but I think it’s a very good idea to restrict them from any process that doesn’t use them.
RestrictNamespaces=true
The system call filter is a bit more prosaic. Most of these exploits require calling socket(). Let’s just disallow that:
SystemCallFilter=~socket
Alternatively, for things that need sockets, systemd can limit the address families that are allowed:
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
Allowing IP brings those skeletons lurking in net/ back within reach, but there’s probably still some value in this.
That’s about all I’ve got. On this topic more than ever, please do email me if you have something to add. Good luck out there.