KernelHardening

Differences between revisions 3 and 4
Revision 3 as of 2010-04-29 23:15:26
Size: 6302
Editor: c-76-105-168-175
Comment: add chroot notes for good measure
Revision 4 as of 2010-04-29 23:18:41
Size: 6310
Editor: c-76-105-168-175
Comment:
Deletions are marked like this. Additions are marked like this.
Line 49: Line 49:
As Linux grows in popularity, it will become a growing target for malware. One particularly troubling weakness of the Linux process interfaces is that a single user is able to examine the memory and running state of any of their processes. For example, if Firefox was compromised, it would be possible for an attacker to attach to other processes to extract additional credentials and continue to expand the scope of their attack. Some applications use `prctl()` to specifically disallow such PTRACE attachment (e.g. ssh-agent), but a better solution is to only allow PTRACE directly from a parent to child process (i.e. direct `gdb` and `strace` still work), or from the root user (i.e. `gdb BIN PID`, and `strace -p PID` still work as root). As Linux grows in popularity, it will become a growing target for malware. One particularly troubling weakness of the Linux process interfaces is that a single user is able to examine the memory and running state of any of their processes. For example, if Firefox was compromised, it would be possible for an attacker to attach to other processes to extract additional credentials and continue to expand the scope of their attack. Some applications use `prctl()` to specifically disallow such `PTRACE` attachment (e.g. `ssh-agent`), but a better solution is to only allow `PTRACE` directly from a parent to child process (i.e. direct `gdb` and `strace` still work), or from the root user (i.e. `gdb BIN PID`, and `strace -p PID` still work as root).
Line 57: Line 57:
Since these security containment protections are being designed correctly with containers ([[Manpage:clone|`CLONE_NEW*`]]), it would be better to use containers or MAC from the start when trying to isolate a service. Since these security containment protections are being designed correctly with containers (see [[Manpage:clone|CLONE_NEW*]]), it would be better to use containers or MAC from the start when trying to isolate a service.

There are several kernel hardening features that have appeared in other hardened operating systems that would improve the security of Ubuntu, and Linux in general. They have been controversial, so this page attempts to describe the features, track their controversy and discussion over the years so as much information is available to make an educated decision about potential implementations.

Variations on these approaches have appeared in many projects, including OpenWall and grsecurity.

Proposed for Ubuntu

A long-standing class of security issues is the symlink-based ToCToU race, most commonly seen in world-writable directories like /tmp/.

The common method of exploitation of this flaw is crossing privilege boundaries when following a given symlink (i.e. a root user follows a symlink belonging to another user). The solution is to not permit symlinks to be followed when users do not match, but only in a world-writable directory (with an additional improvement that the directory owner's symlinks can always be followed).

Some links to the history of its discussion:

Past objections and rebuttals could be summarized as:

  • Violates POSIX.
    • POSIX didn't consider this situation, and it's not useful to follow a broken specification at the cost of security.
  • Might break some unknown application that uses this feature.
    • These applications cannot be identified, and as such, are few fewer than the applications that are vulnerable to symlink ToCToU.
  • Applications should just use mkstemp() or O_CREATE|O_EXCL.

    • True, but applications are not perfect, and new software is written all the time that makes these mistakes; blocking this flaw at the kernel is a single solution to the entire class of vulnerability.

Example implementation

Hardlinks can be abused in a similar fashion, but they are not limited to world-writable directories. If /etc/ and /home/ are on the same partition, a regular user can create a hardlink to /etc/shadow in their home directory. While it retains the original owner and permissions, it is possible for privileged programs that are otherwise symlink-safe to mistakenly access the file through its hardlink. Additionally, a very minor untraceable quota-bypassing local denial of service is possible by an attacker exhausting disk space by filling a world-writable directory with hardlinks.

Some links to the history of its discussion:

Past objections and rebuttals could be summarized as:

  • Violates POSIX.
    • POSIX didn't consider this situation, and it's not useful to follow a broken specification at the cost of security.
  • Might break atd, courier, and other unknown application that uses this feature.
    • These applications can be tested and fixed. The others, since they cannot be identified, are by definition fewer than the applications that are vulnerable to hardlink attacks.
  • Applications should correctly drop privileges before attempting to access user files.
    • True, but applications are not perfect, and new software is written all the time that makes these mistakes; blocking this flaw at the kernel is a single solution to the entire class of vulnerability.

PTRACE Protection

As Linux grows in popularity, it will become a growing target for malware. One particularly troubling weakness of the Linux process interfaces is that a single user is able to examine the memory and running state of any of their processes. For example, if Firefox was compromised, it would be possible for an attacker to attach to other processes to extract additional credentials and continue to expand the scope of their attack. Some applications use prctl() to specifically disallow such PTRACE attachment (e.g. ssh-agent), but a better solution is to only allow PTRACE directly from a parent to child process (i.e. direct gdb and strace still work), or from the root user (i.e. gdb BIN PID, and strace -p PID still work as root).

Not Currently Proposed For Ubuntu

chroot Protection

Many administrators attempt to contain potentially exploitable services in chroots. Unfortunately, chroots are not designed to be a security protection (they are for development and debugging). While it is possible to reasonably contain a non-privileged process in a chroot, attempting to contain a root user is fraught with pitfalls. While it is possible to patch the kernel to have a hardened chroot() (for example, grsecurity has a large set of protections that lock down chroots) so many things are fundamentally changed that the benefits to certain development configurations are lost in favor of the security protections.

Since these security containment protections are being designed correctly with containers (see CLONE_NEW*), it would be better to use containers or MAC from the start when trying to isolate a service.

Among the methods of chroot escape is abusing the current working directory while performing additional chroot calls (others include using /proc/*/cwd, fchdir(), and PTRACE). This single flaw is trivial to fix, but does not block the other avenues, so the gain very small when compared with the down-side of carrying a delta from the upstream kernel.

Example implementation

SecurityTeam/Roadmap/KernelHardening (last edited 2022-01-04 22:35:37 by rodrigo-zaiden)