Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

Getting it out of the way: Not iptables!

What I'd like to do is block network access to certain IPs, subnets, and/or hostnames at the Linux kernel level, such that no user, including root, could bypass them once the system is running.

I actually do have a specific need for this, but I won't get into the details since it doesn't change the question.

Additional restrictions:

  • Is running unvirtualized on bare-hardware.
  • No access to upstream networking devices.
  • Not running SELinux (but feel free to give responses that use SELinux for the benefit of others).

Ideally root would be unable to remove the access restrictions in any way, but if root were still able to remove them in extreme ways such as directly overwriting in-memory structures, that would still be ok.

share|improve this question
1  
Preventing root from doing something? Thats unpossilbe! –  Rook May 3 '13 at 4:57
    
I like that word, "unpossilbe" :) –  Tek Tengu May 3 '13 at 9:46
add comment

5 Answers

Filtering arbitrary connections could be done with a kernel module by hooking netfilter. And anything done in kernel land with a kernel module, can be undone with a kernel module. Also, nothing is keeping root form just installing their own kernel...

root is GOD, never forget that.

share|improve this answer
    
This is interesting, but it's too easy to just remove the module using rmmod. Building the netfilter hooks into a recompiled kernel might be possible, although none of the examples that I found online show that method. –  Animism May 13 '13 at 16:43
    
@Animism any module can be built into a compiled kernel, and root can change or modify what kernel they are using and reboot. root is god. –  Rook May 13 '13 at 17:17
add comment

"Root is God". Well, there are gods... and then, there are elder gods.

The root user can do a lot of things on a machine. In particular, he can replace the files which are used to boot the machine; thus, he can potentially replace your kernel with another of his own, which would let him pass. SELinux can be used as a way to make a declawed, neutered root who will be limited in some ways, so no longer the real root user; in particular, forcing any escape to go through a reboot of the machine. However, it is hard to block all paths and, arguably, the Linux kernel and SELinux are way too complex to be bug-free -- therefore, there MUST exist local exploits allowing at least root to go in full-physical mode.

Also, there are devious ways to escape network filters. For instance, root could access the network interface at the ethernet level and emit and receive ethernet frames by himself, completely bypassing the TCP/IP stack of the kernel, thus unaffected by any blocking filter you would have inserted at that level (and, for that matter, it would bypass iptables as well).


To really contain root, overawe him with heavy artillery. I mean a Virtual Machine. Make the Linux system run in a VM; all external network traffic to and from the VM will go through the VM manager system, which can then block and allow in any way as you see fit, completely outside of reach of the evil root, regardless of what he does. This would even work if the evil root replaced the whole system with NetBSD or Windows or anything else.

The VM arrangement requires that the VM is effective at containing the guest and preventing it from tapping into the host. This requires a bit of faith, but much less than believing that something as complex as SELinux or the Unix permission system could accomplish the same level of isolation reliability.

share|improve this answer
add comment

So Rook's answer to you is yes/no. Basically without downloading the linux kernel source and rewriting some of it yourself, what he proposes is your answer. You could do most of what you want, but you could not achieve preventing root from being able to bypass changing it.

You could make it so that you have root account that never sees the light of day, and a secondary (through sudo like capabilities) root like account that does have the restriction and is prevented from changing it.

Or you could have your machine so that you have every login chroot jailed into a subordinate environment that could never see your outer scope that had the module changes.

So you can get some of the way there, but without hardware implementation, or some rewriting of the OS, not all of the way.

share|improve this answer
add comment

Rook is correct, of course. Given that you would be setting this up as root, someone could just as easily take it apart as root. However, you could make that time consuming.

The most direct approach would be to edit sys_socket.c, or perhaps just socket.c (the usermode-wrapper) to include a IP filter.

If you edit sys_socket.c you would have to recompile the kernel, but someone would have to boot a different kernel to undo your work, whereas recompiling socket.c should be a little easier to both implement and undo.

However the best approach would be to go buy a little basic IP firewall, and block the hosts on that.

share|improve this answer
add comment

Root is not god if you have SELinux enabled. That is the only way I can see to accomplish what you want. Block it with iptables and run SELinux in strict mode.

You might have uid 0 but you won't have the capabilities(7).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.