SELinux
1 DAC
- Linux has Discretionary Access Control as a default permissions model
- Examples: File permissions (chmod)
- Examples: Process ownership
- The user (subject) has discretion to set or not security policies.
2 MAC
- Mandatory Access Control enforces a central policy on a system
- MAC enforcement requires all policies to be specified by an administrator. Users cannot change these policies
3 Principles
- privilege of least authority
- The principle of least authority says you should only give the minimum privilege needed
- fine-grained access control permission to kernel objects
- Read/write permissions are coarse
4 SELinux
- Disables root user priviledges
- Several administrative roles with limited extra privileges
- Example: Changing passwords does not require root access to setting up firewalls
- Multi-level security: Declassified, Secret, Top-Secret, etc.
- In MLS, only a trusted declassifier can lower the secrecy of a file
- Users with appropriate privilege can read classified files, but cannot output their contents to lower secrecy levels
4.1 SELinux Example
- Suppose I want to read a secret file
- In SELinux, I transition to a secret role to do this
- This role is restricted:
- Cannot write to the network
- Cannot write to declassified files
- Secret files cannot be read in a declassified role
- This role is restricted:
- Idea: Policies often require applications/users to give up some privileges (network) for others (access to secrets) General principles
- Secrecy (Bell-LaPadula)
- No read up, no write down
- In secret mode, you can’t write a declassified file, or read top-secret data
- Integrity (Biba)
- No write up, no read down
- A declassified user can’t write garbage into a secret file
- A top-secret application can’t read input/load libraries from an untrusted source (reduce risk of compromise)
4.2 SELinux Policies
- Written by an administrator in a SELinux-specific
language
- Often written by an expert at Red Hat and installed wholesale
- Difficult to modify or write from scratch
- Very expansive—covers all sorts of subjects, objects, and verbs Key Points of Interest
- Role-Based Access Control (RBAC)
- Type Enforcement
- Linux Security Modules (LSM)
- Labeling and persistence Role-Based Access
4.3 Control
- Idea: Extend or restrict user rights with a role that captures what they are trying to do
- Example: I may browse the web, grade labs, and
administer a web server
- Create a role for each, with different privileges
- My grader role may not have network access, except to blackboard
- My web browsing role may not have access to my home directory files
- My admin role and web roles can’t access students’ labs Roles vs. Restricted
4.4 Context
- Win2k ACLs allow a user to create processes with a subset of his/her privileges
- Roles provide the same functionality
- But also allow a user to add privileges, such as administrative rights
- Roles may also have policy restrictions on who/when/
how roles are changed
- Not just anyone (or any program) can get admin privileges
5 The power of RBAC
- Conditional access control
- Example: Don’t let this file go out on the internet
- Create secret file role
- No network access, can’t write any files except other secret files
- Process cannot change roles, only exit
- Process can read secret files
- I challenge you to express this policy in Unix permissions!
Roles vs. Specific Users
- Create secret file role
- Policies are hard to write
- Roles allow policies to be generalized
- Users everywhere want similar restrictions on their browser
- Roles eliminate the need to re-tailor the policy file for
every user
- Anyone can transition to the browser role
6 Type Enforcement
- Very much like the fine-grained ACLs we saw last time
- Rather than everything being a file, objects are given a
more specific type
- Type includes a set of possible actions on the object
- E.g., Socket: create, listen, send, recv, close
- Type includes ACLs based on roles
- Type includes a set of possible actions on the object
7 Type examples
- Device types:
- agpdevicet - AGP device (/dev/agpgart)
- consoledevicet - Console device (/dev/console)
- mousedevicet - Mouse (/dev/mouse)
- File types:
- fst - Defaults file type
- etcaliasest - /etc/aliases and related files
- bint - Files in /bin More type examples
- Networking:
- netifeth0t – Interface eth0
- portt – TCP/IP port
- tcpsockett – TCP socket
- /proc types
- proct - /proc and related files
- sysctlt - /proc/sys and related files
- sysctlfst - /proc/sys/fs and related files
8 Detailed example
- pingexect type associated with ping binary
- Policies for pingexect:
- Restrict who can transition into pingt domain
- Admins for sure, and init scripts
- Regular users: admin can configure
- pingt domain (executing process) allowed to:
- Use shared libraries
- Use the network
- Call ypbind (for hostname lookup in YP/NIS)
- Restrict who can transition into pingt domain
8.1 Ping cont.
- pingt domain process can also:
- Read certain files in /etc
- Create Unix socket streams
- Create raw ICMP sockets + send/recv on them on any interface
- setuid (Why? Don’t know)
- Access the terminal
- Get file system attributes and search /var (mostly harmless
operations that would pollute the logs if disallowed)
- Violate least privilege to avoid modification!
9 Full ping policy
01 type pingt, domain, privlog; 02 type pingexect, filetype, sysadmfile, exectype; 19 03 role sysadmr types pingt; 20 auditallow pingt anysockett:rawipsocket 04 role systemr types pingt; sendto; 05 21 06 # Transition into this domain when you run this 22 # Let ping receive ICMP replies. program. 23 allow pingt { self icmpsockett }:rawipsocket 07 domainautotrans(sysadmt, pingexect, pingt) recvfrom;
- domainautotrans(initrct, pingexect, pingt) 24
09 25 # Use capabilities. 10 usesshlib(pingt) 26 allow pingt self:capability { netraw setuid }; 11 cannetwork(pingt) 27 12 generaldomainaccess(pingt) 28 # Access the terminal. 13 allow pingt { etct resolvconft }:file { getattr 29 allow pingt adminttytype:chrfile read }; rwfileperms; 14 allow pingt self:unixstreamsocket 30 ifdef(`gnome-pty-helper.te', `allow pingt createsocketperms; sysadmgpht:fd use;') 15 31 allow pingt privfd:fd use; 16 # Let ping create raw ICMP packets. 32 17 allow pingt self:rawipsocket {create ioctl read 33 dontaudit pingt fst:filesystem getattr; write bind getopt setopt}; 34 18 allow pingt anysockett:rawipsocket sendto; 35 # it tries to access /var/run 36 dontaudit pingt vart:dir search;
10 Linux Security Modules
- Culturally, top Linux developers care about writing a
good kernel
- Not as much about security
- Different specializations
- Their goal: Modularize security as much as humanly
possible
- Security folks write modules that you can load if you care about security; kernel developers don’t have to worry about understanding security
11 Basic deal
- Linux Security Modules API:
- Linux developers put dozens of access control hooks all
over the kernel
- See include/linux/security.h
- LSM writer can implement access control functions called by these hooks that enforce arbitrary policies
- Linux also adds opaque “security” pointer that LSM can use to store security info they need in processes, inodes, sockets, etc.
- Linux developers put dozens of access control hooks all
over the kernel
12 SELinux example
- A task has an associated security pointer
- Stores current role
- An inode also has a security pointer
- Stores type and policy rules
- Initialization hooks for both called when created SELinux example, cont.
- A task reads the inode
- VFS function calls LSM hook, with inode and task pointer
- LSM reads policy rules from inode
- Suppose the file requires a role transition for read
- LSM hook modifies task’s security data to change its role
- Then read allowed to proceed Problem: Persistence
- All of these security hooks are great for in memory data
structures
- E.g., VFS inodes
- How do you ensure the policy associated with a given file persists across reboots? Extended Attributes
- In addition to 9+ standard Unix attributes, associate a small
key/value store with an on-disk inode
- User can tag a file with arbitrary metadata
- Key must be a string, prefixed with a domain
- User, trusted, system, security
- Users must use ‘user’ domain
- LSM uses ‘security’ domain
- Only a few file systems support extended attributes
- E.g., ext2/3/4; not NFS, FAT32
13 Persistence
- All ACLs, type information, etc. are stored in extended attributes for persistence
- Each file must be labeled for MAC enforcement
- Labeling is the generic problem of assigning a type or security context to each object/file in the system
- Can be complicated
- SELinux provides some tools to help, based on standard system file names and educated guesses
14 Summary
- SELinux augments Linux with a much more restrictive
security model
- MAC vs. DAC
- Understand Roles and Types
- Basic ideas of LSM
- Labeling and extended attributes