Bypassing Buffer-Overflow Protections
Bypassing Buffer-Overflow Protections
Arbitrary Copy:
Bypassing Buffer-Overflow Protections
Krerk Piromsopa, Member, IEEE, and Richard J. Enbody, Member, IEEE
A. Example
To ease understanding, Figure 2 presents a sample case of
an attack on non-control data where the vulnerability might be
applicable.
int b() {
char *src,*dest;
char buff[10];
printf("Input string:.\n");
// Overflow *src, *dest
gets(buff);
// Copy src to dest
strcpy(src,dest);
}
int a() Figure 3 a possible scenario
bo);
IV. ISSUES
} Consider the second condition of arbitrary copy: the
int main (int argc,char *argv[]) presence of a useful address in local memory. We know that a
ao); mechanism like Secure Bit prevents the use of input as control
} data, thus only purely local data that is not derived from input
Figure 2 Sample Buffer-Overflow attacks on non- is a potential threat. One's first thought might be that any
function call could provide an address of that function.
control data However, because of relocation, local calls use relative
addresses which cannot be used for this attack. Other sources
In this example, main calls function "a" which then calls of control targets such as jumps are also relative addresses and
the vulnerable function "b". Within "b" the user inputs buff not useful. Given this observation, potential sources of
which can overflow to both overwrite *src to point to the addresses are narrowed to the presence of a shared library or a
function pointer.
return address of a previous call (e.g. "a () ") and overwrite
*dest to point to the target address (e.g. return address of Shared library. In the case of shared libraries (the function
"b ()" or "main () "). Note that this overflow is possible only is located in the shared library), a call to the function means
if all optimization is turned off so that neither src nor dest there exists a useful entry in the Global Offset Table (GOT).
is in a register. Under these circumstances it is possible to
change the control flow without replacing control data with Function Pointer. The assignment of a function address to
583
a function pointer (frequently found in C++) would create a VI. CONCLUSIONS
pointer available for reuse. Arbitrary copy is a potential threat that can bypass current
state-of-the-art buffer-overflow protection schemes. While
If a useful address is stored as an entry in the GOT or a other (easier) vectors of attacks still exist, it is unlikely that
function pointer, the buffer-overflow described above can be arbitrary copy will be used as a tool. However, the recent
used to replace a target address with this address. Target advances in buffer-overflow protection will make existing
addresses might be return addresses, function pointers, or an attacks obsolete. While trivial optimization eliminates the
entry in GOT itself. threat, one cannot count on non-optimization as a complete
The probability that all conditions are applicable is solution. We should pay a close attention to this problem.
considered to be low. In fact, some researchers [8] do not We are now working on extending Secure Bit to protect
believe that it will be a problem or suggest that encoding against buffer-overflows of non-control data. In addition to
addresses in GOT should be sufficient for preventing the the broader protection provided, this specific attack can be
attack. However, that prevention might not be able to protect prevented by preserving the integrity of the source and
some function pointers in C++. destination pointers from illegal modification. The common
practice of using user input as array indices complicates
identifying illegal modification.
V. POSSIBLE SOLUTIONS
Though the attack sounds probabilistically low, it is not
impossible, and experience suggests that no matter how REFERENCES
remote the possibility, someone, sometime will exploit it. We
have already mentioned that the most simplistic optimization [1] S. Bhatkar, D. C. Duvarney, and R. Sekar, "Address Obfuscation: an
prevents the attack. To protect against this attack in the Efficient Approach to Combat a Broad Range of Memory Error
Exploits," In Proc. of the 12th USENIXSecurity Symposium. 2003.
presence of no optimization, we simply have to eliminate at [2] S. Chen, J. Xu, N. Nakka, Z. KalbarcZyk, and R. K. Iyer, "Defeating
least one critical condition. There are three possible methods. Memory Corruption Attacks via Pointer Taintedness Detection," in
* Prevent a raw address from being stored directly in Proc. Of IEEE International Conf on Dependable Systems and
Networks (DSN), Yokohama, Japan, June 28 - July 1, 2005
the program. [3] E. Chien, and P. Szor, "Blended Attacks Exploits, Vulnerabilities and
* Secure the target address from being modified (e.g. Buffer-Overflow Techniques in Computer Viruses," In Proc. of Virus
GOT and function pointers). Bulletin Conf, 2002
[4] T. Chiueh, F. Hsu, "RAD: A Compile-Time Solution to Buffer Overflow
* Validate that both the source and destination Attacks," In Intl. Conf on Distributed Computing Systems, 2001.
pointer have not been maliciously modified. [5] M.L. Corliss, E.C. Lewis, and A. Roth, "Using DISE to Protect Return
Rather than storing an address directly into the GOT table Addresses from Attack," ACMSIGARCH, Vol 33. No. 1, 2005.
[6] C. Cowan, S. Beattie, R.F. Day, C. Pu, P. Wagle, and E. Walthinsen,
or function pointer, we may choose to store an encoded "Protecting Systems from Stack Smashing Attacks with StackGuard,"
version of an address or store a relative address. Even a trivial the Linux Expo, Raleigh, NC,1999
encoding such as XOR (like PointGuard [7]) with some [7] C. Cowan, S. Beattie, J. Johansen, and P. Wagle, "PointGuard:
Protecting Pointers From Buffer Overflow Vulnerabilities," In Proc. of
constant would be sufficient. However, this approach does not the 12th USENIXSecurity Symposium, 2003
prevent a copy between locations that share the same encoding [8] J.R. Crandall, and F.T. Chong, "Minos: Control Data Attack Prevention
scheme or key used to encrypt the address (e.g. between Orthogonal to Memory Model," Intl. Sym. on Microarchitecture, 2004.
[9] J.R. Crandall, and F.T. Chong, "A Security Assessment of the Minos
function pointers or entries in the GOT). Note that PointGuard Architecture," ACM SIGARCH, Vol 33. No. 1, 2005.
[7] can be used to reduce the probability of overwriting source [10] J. Etoh, "GCC extension for protecting applications from stack-
and destination pointers. However, if the key and algorithm smashing attacks," IBM, 2000.
[11] Flawfinder, Available: la e
can be circumvented, it is possible to overwrite it with a valid [12] M.S. Frantzen, "StackGhost: Hardware facilitated stack protection," In
copy. In fact, we may be able to overflow the value (e.g. Proc. of the 10th USENIXSecurity Symposium, 2000.
index) that is used for pointer arithmetic rather than modifying [13] A. Glew, "Segments, Capabilities, and Buffer Overrun Attacks,"
Computer Architecture NEWS, ACM SIG Computer Architecture
the pointer directly. Vol.31, No.4 - September 2003, pp. 26 - 31
Rather than making the useful address useless, we can [14] E. Haugh, and M. Bishop, "Testing C Programs for Buffer Overflow
protect the target from being modified. In the case of GOT, we Vulnerabilities," In Proc. of the 2003 Symposium on Networked and
can protect the GOT from being a target by declaring it as
Distributed System Security (SNDSS 2003) (Feb. 2003)
[15] M. Howard, D. Leblance, Chapter 10:All Input Is Evil!. Writing Secure
read-only after the shared library is configured. Nonetheless, Code, Microsoft Press, 2nd ed.(1965)
we cannot apply the same idea to protect function pointers or [16] K. Inoue, "Energy-Security Tradeoff in a Secure Cache Architecture
return addresses in general. Against Buffer Overflow Attacks," ACM SIGARCH, Vol 33. No. 1,
2005.
Alternatively, we can validate (assert) the source and [17] R.W.M. Jones, and P.H.J. Kelly, "Backwards-compatible bounds
destination pointers before running the "strcpy(..)" function. If checking for arrays and pointers in C programs," In The 3rd Intl.
the source and destination pointers can be validated, the attack Workshop on Automated Debugging, 1997.
[18] D. Kirovski, M. Drinic, and M. Potkonjak, "Enabling Trusted Software
can be prevented. However, a false alarm may be generated Integrity," ACM Intl. Conf on Architectural Support for Programming
when a pointer is the arithmetic result of input. Languages and Operating Systems, 2002.
[19] T. Krazit, "PCWorld - News - AMD Chips Guard Against Trojan
Horses," IDG News Service, 2004.
584
[20] J.P. Mcgregor, D.K. Karig, Z. Shi, R.B. Lee, "A Processor Architecture
Defense against Buffer Overflow Attacks," In Proc. of the IEEE Intl.
Conf on Information Tech.: Research and Education (ITRE 2003), 243-
250.
[21] J. Newsome, and D. Song, "Dynamic Taint Analysis: Automatic
Detection and Generation of Software Exploit Attacks," In NDSS (Feb,
2005)
[22] PAX TEAM. 2003. Documentation for the PaX project
[23] K. Piromsopa, and R. Enbody, "Secure Bit2: Transparent, Hardware
Buffer-Overflow Protection," Technical Reports #MSU-CSE-05-9,
Department of Computer Science and Engineering, Michigan State
University, 2005.
[24] K. Piromsopa, and R. Enbody, "Survey of Buffer-Overflow Protection,"
Technical Reports #MSU-CSE-06-3,, Department of Computer Science
and Engineering, Michigan State University, 2006.
[25] RATS, Available: t wst
[26] C. Schmidt, and T. Darby, "The What, Why, and How of the 1988
Internet Worm," Available:
[27] Z. Shao, Q. Zhuge, Y. He, and E.H. Sha, "Defending Embedded
Systems Against Buffer Overflow via Hardware/Software," In Proc. of
the 20th Annual Computer Security Applications Conference, Tucson,
Arizona (Dec. 6-10, 2004)
[28] SOLAR DESIGNER, Linux kernel patch from the Openwall Project
(Non-Executable User Stack), 2002. Available:
[29] G. Suh, J. Lee, and S. Devadas, "Secure program execution via dynamic
information flow tracking," In ASPLOSXI (Oct, 2004.)
[30] J. Viega, J.T. Bloch, Y. Kohno, and G. Mcgraw, "ITS4: A Static
Vulnerability Scanner for C and C++ Code," In Proc. of the 16th Annual
Computer Security Applications Conference, 2000.