Lec 13: Security

Lecture notes courtesy of David Mazieres and Robert Morris

Security overview

Design Principles

  • Why is securing computer systems difficult?
  • Two important principles of building secure systems (book includes many other..)
  • 1. Least privilege principle.
  • 2. Minimize trusted computing base (TCB).

    UNIX security mechanisms

  • Each user is identified by a (32-bit) UID
  • A root user (UID=0), treated specially by the kernel as the administrator. Root has all privileges.
  • Each process has a UID.
  • Each inode (file, dir) has an owner UID
  • One can view access control as a matrix, where each cell specifies allowed permissions
                      file_1         file_2        file_3    ...     file_n
    user_1            read            write         -         -       read
    user_2            write           write        write      -        -
    user_3             -               -            read      -        read
    ...
    user_m            read            write         read      -        write
    
  • Easier to specify permissions with role-based access control
  • Two ways to slice the permission matrix
  • Now let's examine Unix protection
  • OS stores with each file permissions for user, group and others
      $ ls -l index.html 
      -rw-rw-r-- 1 jinyang users ... 2009-04-15 13:22 index.html
                       /     /
                      /     /
                    owner  group
      $ ls -dl /etc/
      drwxr-xr-x 135 root root 12288 2009-04-08 18:43 /etc
    
  • "User permissions" apply to processes with the same UID as the file/dir
  • "Group permissions" apply to processes with the same GID ...
  • "Other permissions" apply otherwise
  • Root (UID=0) has all privileges on all files/dirs
  • Other non-file access controls, e.g.

    Privileged code (the TCB) in UNIX

  • All of UNIX kernel is certainly part of TCB.
  • In UNIX, many other user-level programs are privileged as well and hence part of TCB.

  • What runs as root and why?
  • Example: /bin/login runs as root. Why? In order to set the UID of a process to the authenticated user.
  • Login is part of TCB now. If it's buggy, ....
  • Example: rlogind runs "login [-f] username", then assume user already authenticated. User requests to login as "-froot"...

  • Many programs require privileges as part of their normal operations
  • UNIX solution: setuid/setgid programs (the alternative is to run a program as root)
  • Setuid-programs are very tricky to implement securely
  • Example attacks on setuid-programs
  • Getting setuid-programs right is harder than you think: exploit race conditions (TOCTTOU bugs)
  • xterm security hole:
  • TOCTTOU attack on xterm
     |    xterm                              attacker
     |   ------------------------------------------------------------------
     |                                       creat("/tmp/X")
     |   access("/tmp/X") -->OK          
     |                                       unlink("/tmp/X")
     |                                       symlink("/tmp/X", "/etc/passwd")
     |   open("/tmp/X")  -->OK
    \|/
    
    time
    
  • Attacker changes /tmp/X between check and use. xterm unwittingly overwrites /etc/passwd

  • setuid-programs often acquire and then drop privileges.
  • Another nasty case
       Attacker creates two processes: A and B
      |      A                                   B
      |  ---------------------------------------------------
      |    ptrace(B,...) --> OK
      |    execute "su attacker"
      |    su's effective UID becomes 0
      |                                        execute "su root"
      |                                        su's effective UID becomes 0
      |                                        A's allowed to trace "su root" because A's eUID=0
      |    A types in correct passwd
      |    su drops privilege
      |    now A is attached to process "su root" which has effective UID=0, can modify memory to get root shell     
      |
     \|/
     

    Limitations of UNIX's security

  • 1. Cannot pass privileges to other processes
  • 2. Cannot have multiple privileges at once
  • Programmers get around the limitations 1 and 2 by running setuid or root programs (violation of least privileges, bloated TCB)
  • 3. UNIX security policy is somewhat ad-hoc:

    Alternative and (arguably better) security models

  • Capability-based systems (Hydra, KeyKOS)
  • Discretional vs. mandatory access control (DAC vs. MAC)
  • Typical MAC model:
  • Information can only flow up the lattice
  • Many recent efforts to make MAC practical for non-miliary systems: LOMAC, Aesbestos, HiStar