KernelHardening

Revision 1 as of 2010-04-29 22:22:59

Clear message

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.

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.

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).