<<

TOCTTOU Vulnerabilities in -Style Systems: An Anatomical Study

Jinpeng Wei and Calton Pu Georgia Institute of Technology

4th USENIX Conference on File and Storage Technologies December 15, 2005. San Francisco, CA Definition and Scope

z TOCTTOU – of Check To Time of Use, a kind of race condition in Unix-style file systems z Check – Establish some precondition (invariant) about a file z Use – Operate on the file assuming that the invariant is still valid Sendmail Example z Run as root z Operate on files owned by normal users

/home/abc/mailbox Check Error handling a symbolic ?

Establish some invariant No

Append the new Use message to Assuming the invariant /home/abc/mailbox still holds Sendmail Vulnerability: An Example Sendmail (root) Attacker (abc) Time /home/abc/mailbox Check a symbolic link? Delete /home/abc/mailbox No Create symbolic link mailbox, pointing to /etc/ Append the new message to Use /home/abc/mailbox (actually to /etc/passwd) Effect: The attacker may get unauthorized root access! Outline of the Presentation z Motivation of the research z CUU Model of TOCTTOU vulnerabilities z Detection of TOCTTOU vulnerabilities z Probability and event analysis of exploiting TOCTTOU vulnerabilities z Related work and conclusion CUU Model (1) z -call: a system call that establishes some preconditions about a file, either explicitly or implicitly. z Example CU-calls: access, , open, creat, , int stat(const char *file_name, struct stat *buf); CUU Model (2) z Use-call: a system call that operates on a file. z Example Use-calls: open, truncate, mkdir, rmdir, chdir, execve, , z A TOCTTOU pair is a combination of a CU-call and a Use-call. e.g., in Sendmail. CUU Model (3) Use Explicit check Implicit check Create a regular CheckSet × FileRemovalSet × file FileCreationSet FileCreationSet Create a CheckSet × DirRemovalSet × DirCreationSet DirCreationSet Create a link CheckSet × LinkRemovalSet × LinkCreationSet LinkCreationSet Read//Exec CheckSet × (FileCreationSet × ute or Change the FileNormalUseSet FileNormalUseSet)∪ attribute of a (LinkCreationSet × regular file FileNormalUseSet)∪ (FileNormalUseSet × FileNormalUseSet) Access or change CheckSet × (DirCreationSet × the attribute of a DirNormalUseSet DirNormalUseSet)∪ directory (LinkCreationSet × DirNormalUseSet)∪ (DirNormalUseSet × DirNormalUseSet)

CreationSet = FileCreationSet ∪ LinkCreationSet ∪ DirCreationSet Concrete Sets For FileCreationSet = {creat, open, mknod, rename} LinkCreationSet = {link, symlink, rename} DirCreationSet = {mkdir, rename} FileRemovalSet = {, rename} LinkRemovalSet = {unlink, rename} DirRemovalSet = {rmdir, rename} FileNormalUseSet = {chmod, chown, truncate, utime, open, execve} DirNormalUseSet = {chmod, chown, utime, , chdir, , pivot_root} CheckSet = {stat, access} Detection Framework

The Sensors record file system call traces. The filter suppresses information about safe Gathersfiles. kernel traces into log files Identifies TOCTTOU pairs Detects the TOCTTOU vulnerabilities TOCTTOU Vulnerabilities in Red Hat Linux 9

Application TOCTTOU errors Possible exploit Tested: Changing the owner of ~130 utilities /etc/passwd to an from /bin, /sbin ordinary user and /usr/bin rpm Running arbitrary emacs Making /etc/shadow readable by an ordinary user gedit Changing the owner of /etc/passwd to an ordinary user esd Gaining full access to another user’s home directory Vi 6.1 Vulnerability z The vulnerability happens when ¾ vi is run by root ¾ vi is editing a file owned by a normal user (can be an attacker) ¾ vi saves the file being edited z TOCTTOU pair: ¾ open creates a new file for writing ¾ chown changes the owner of the new file to the normal user. Event Analysis of Vi Exploit Baseline Vulnerability of Vi

Vulnerability and Save Window Sizes of Window of Vulnerability Divided by Save vi Time, as a Function of File Size Success Rate of Attacking Vi Necessary Conditions of Vi Attack z vi has called open to create the new file z vi has not called chown z vi relinquishes CPU and the attacker is scheduled to run z the attacker process finishes the file redirection during this run Reasons for Vi to Relinquish CPU z Blocked on I/O (file caching effect) z Preempted because CPU slice is used up z Preempted by higher priority processes, e.g. ntpd, kswapd and bdflush kernel threads z A probability event! Ongoing work z Prevention of TOCTTOU z Completeness of CUU model z Windows file system vulnerabilities Related Work: Detecting TOCTTOU z Static analysis ¾ Compiler extensions z Dynamic analysis ¾ Dynamic online analysis ™ Eraser ¾ Post mortem analysis Related Work: Preventing TOCTTOU z RaceGuard: z Probabilistic approach (Dean and Hu): Î z Pseudo-transaction (Tsyrklevich and Yee) Conclusion z The CUU model of TOCTTOU vulnerabilities z The dynamic monitoring framework z The probability and event analysis of attacking vi Thank you! Questions?