Bell Labs libsafe-2.0, detection and protection against stack smashing and format string attacks. // Copyright (C) 2000 Avaya Labs, Avaya Inc. // Copyright (C) 1999 Bell Labs, Lucent Technologies. // Copyright (C) Arash Baratloo, Timothy Tsai, and Navjot Singh. // // This file is part of the Libsafe library. // Libsafe version 2.x: protecting against stack smashing attacks. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // For more information, // visit http://www.research.avayalabs.com/project/libsafe/index.html // or email libsafe@research.avayalabs.com The libsafe-1.3 library protects a process against the exploitation of buffer overflow vulnerabilities in process stacks. Libsafe-2.0 adds the capability of protecting against format string exploits. [See Note 1.] Libsafe works with any existing pre-compiled executable and can be used transparently, even on a system-wide basis. The method intercepts all calls to library functions that are known to be vulnerable. A substitute version of the corresponding function implements the original functionality, but in a manner that ensures that any buffer overflows are contained within the current stack frame. Libsafe has been shown to detect several known attacks and can potentially prevent yet unknown attacks. Experiments indicate that the performance overhead of libsafe is negligible. The following unsafe functions are currently monitored by libsafe: strcpy(char *dest, const char *src) May overflow the dest buffer. strcat(char *dest, const char *src) May overflow the dest buffer. getwd(char *buf) May overflow the buf buffer. gets(char *s) May overflow the s buffer. [vf]scanf(const char *format, ...) May overflow its arguments. realpath(char *path, char resolved_path[]) May overflow the path buffer. [v]sprintf(char *str, const char *format, ...) May overflow the str buffer. For more information see libsafe/doc/libsafe.8.html. -------------------------------------------------- Note 1: Tim Robbins has created an alternative solution to detecting format string attacks. Tim's solution is called libformat. Both libformat and libsafe use function interception via shared libraries to sanity check function arguments, but the particular methods for checking arguments differ. See http://box3n.gumbynet.org/~fyre/software/libformat.php3 for more information. SLACKWARE NOTES (this section added by volkerdi@slackware.com) While testing libsafe on Slackware, I noticed a couple of minor problems: o libsafe breaks libc4 and libc5 dynamic binaries. This shouldn't be too much of a surprise, since it preloads against everything. If it could be made to load only against glibc2 binaries, this problem would be solved. o libsafe may break a few programs. For example, we found that the 'xv' image program would segfault when libsafe was preloaded. Because of these problems (especially the first one) it was decided that libsafe.tgz should be placed in the /contrib directory as an optional package rather than merged into the base (A) series. However, don't think that's because we're not impressed with libsafe. :) Most people don't have a need for libc4 and libc5 compatability, and xv can always be recompiled statically to work around the problem. I run libsafe on my server/router box, and have experienced no problems with it. In an environment where security is important, libsafe is highly recommended. To install on Slackware, simply use installpkg: installpkg libsafe.tgz New processes that are started after the package is installed will be automatically protected. To get protection on things like sendmail and other daemons, you'll need to restart them (or just reboot your machine). Libsafe must be uninstalled manually. To uninstall it, follow this procedure (carefully): 1. remove /lib/libsafe.so.2 from /etc/ld.so.preload 2. reboot 3. remove /lib/libsafe.so.2 and /lib/libsafe.so.2.0 HOMEPAGE The home web page for libsafe is: http://www.research.avayalabs.com/project/libsafe