This is an old revision of the document!
FreeBSD libc security extensions
- Student: OliverPinter <op@{free,hardened}bsd.org>
- Mentor: PedroGiffuni pfg@FreeBSD.org
Project description
Buffer overflows are the common origin of many security vulnerabilities, if we could catch these type of errors, then we would be able to protect against buffer overflows and buffer overflow based ROP attacks.
In part of this project I plan the following two phases:
First Phase:
Implement FORTIFY_SOURCE, a gcc extension (also partially supported in clang), where the compiler's builtin object size informations is used by the C library to detect buffer overflows. The extension is known to be supported already by GNU libc, Apple’s Xcode, Android’s bionic libc, and NetBSD’s libc. This extension causes no secondary effects on the generated code but adds lightweight buffer checking during the compile and runtime.
Second Phase:
Implement standard C11 Boundary checking Extensions to the C Library Part I: Bounds-checking interfaces[1][2] with their corresponding unit tests. These extensions are rather controversial but they are already implemented in commercial compilers like Microsoft Visual C and would be very useful in the future to port software from that platform. Part of this code could be useful in complementing the checks developed in the first phase and could be considered for future research.
Deliverables
phase #1
- Implement FORTIFY_SOURCE extension in libc.
- Android’s Bionic libc provides a reference implementation under a BSD License.
- Tests implemented extensions by building world to detect vulnerabilities.
- Test ports that already know about FORTIFY_SOURCE like mozilla and vim.
phase #2
- Implement C11 extensions, described in TR 24731-1 [1][2]
- New functions must be documented, probably along within the related man pages.
- Safeclib provides a reference implementation under an MIT license.
- Provide unit tests related to implemented extensions.
- Bring FreeBSD one step closer to support C11 completely in the base system.
GSoC extra
- Review if we can re-use phase 2 into phase 1.
Milestones
phase #1
| schedule | description | status |
| May 25 - May 31 | deeply understand FORTIFY_SOURCE extensions and create a schedule for required changes | done |
| June 1 - June 7 | inspect the existing implementations and start the porting | done |
| June 8 - June 14 | adapt portable codes from NetBSD / bionic libc - part 1. - based on the upper scheduling | done |
| June 15 - June 21 | adapt portable codes from NetBSD / bionic libc - part 2. - based on the upper scheduling | done |
phase #2 - rescheduled
| schedule | description | status |
| June 22 - June 28 | implement missing or non portable parts of FORTIFY_SOURCE - part 3. - based on the upper scheduling | done |
| June 29 - July 5 | test cases, bugfixes and man pages | started |
| July 6 - July 12 | deeply understand TR 24731-1 and create a schedule for required changes | not started |
| July 13 - July 19 | design a new implementation or adapt portable codes from safelibc - part 1. | not started |
| July 20 - August 2 | design a new implementation or adapt portable codes from safelibc - part 2. | not started |
| August 3 - August 9 | test cases | not started |
| August 10 - August 24 | bugfixes, man pages and extra works | not started |
Test Plan
phase #1
(implement FORTIFY_SOURCE)
- Bounds range checking.
- Basic exploitation checking.
- Kyua tests.
phase #2
(implement C11 extensions which described in TR 24731)
- Parameter range checking.
- Basic exploitation checking.
- May reuse infrastructure from phase 1.
- General build testing: should work with base gcc and clang.
The Code
Useful links
[F] http://cvsweb.netbsd.org/bsdweb.cgi/src/tests/lib/libc/ssp/ - netbsd test cases
[F] https://svnweb.freebsd.org/base/head/contrib/gcc/builtins.def?revision=258428&view=markup#l704
[F] https://github.com/android/platform_bionic/tree/master/libc/bionic
[F] https://android.googlesource.com/platform/bionic/+/16d1af167f8e36a9aa4a07ae77034ad519b00463
[F] https://llvm.org/bugs/show_bug.cgi?id=5028
[F] https://llvm.org/bugs/show_bug.cgi?id=23277
[F] https://llvm.org/bugs/show_bug.cgi?id=23280
[F] http://isisblogs.poly.edu/2011/04/11/fortify_source-semantics/
[F] https://securityblog.redhat.com/2014/03/26/fortify-and-you/
[F] https://idea.popcount.org/2013-08-15-fortify_source/
[F] http://phrack.org/issues/67/9.html
[F][clang] http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20140915/115049.html
[F][clang] https://android.googlesource.com/platform/bionic/+/829c089f83ddee37203b52bcb294867a9ae7bdbc
[F][clang] https://android.googlesource.com/platform/bionic/+/16d1af167f8e36a9aa4a07ae77034ad519b00463
[F][E] https://github.com/jsonn/src/tree/b89bad92261a943f900d7235ae50a7326ccd5062/include/ssp
[E] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1225.pdf n1225.pdf
[E] http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1173.pdf n1173.pdf
[E] https://msdn.microsoft.com/en-us/library/wd3wzwts.aspx
[E] https://gustedt.wordpress.com/2013/02/04/runtime-constraint-violations/
[E] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1255.pdf
[G] http://bxr.su/
1.1
| apple | bionic | netbsd | freebsd | |
__bos | n.a. | 3BSDL | n.a. | done |
__bos0 | n.a. | 3BSDL | n.a. | done |
__chk_fail | APSL | n.a. | 2BSDL | done |
__chk_fail_overflow | APSL | n.a. | n.a. | n.a. |
__chk_fail_overlap | APSL | n.a. | n.a. | n.a. |
__darwin_obsz | APSL | n.a. | n.a. | n.a. |
__darwin_obsz0 | APSL | n.a. | n.a. | n.a. |
__fortify_chk_fail | n.a. | 2BSDL | n.a. | done |
__fortify_chk_overlap | n.a. | n.a. | n.a. | done |
__ssp_bos | n.a. | n.a. | 2BSDL | n.a. |
__ssp_bos0 | n.a. | n.a. | 2BSDL | n.a. |
__ssp_overlap | n.a. | n.a. | 2BSDL | n.a. |
__FD_ISSET_chk | n.a. | 2BSDL | n.a. | done |
__FD_CLR_chk | n.a. | 2BSDL | n.a. | done |
__FD_SET_chk | n.a. | 2BSDL | n.a. | done |
"__bcopy_chk" | n.a. | 4BSDL | n.a. | done |
"__bzero_chk" | n.a. | 4BSDL | n.a. | done |
__fgets_chk | n.a. | 2BSDL | 2BSDL | done |
__fread_chk | n.a. | 2BSDL | n.a. | done |
__fwrite_chk | n.a. | 2BSDL | n.a. | done |
__gets_chk | n.a. | n.a. | 2BSDL | done |
__memccpy_chk | APSL | n.a. | n.a. | done + overlap |
__memchr_chk | n.a. | 2BSDL | n.a. | done |
__memcpy_chk | APSL | 2BSDL | 2BSDL | done + overlap |
__memmove_chk | APSL | 2BSDL | 2BSDL | done |
__memrchr_chk | n.a. | 2BSDL | n.a. | done |
__memset_chk | APSL | 2BSDL | 2BSDL | done |
__open_2 (XXX) | n.a. | 2BSDL | n.a. | ??? |
__openat_2 (XXX) | n.a. | 2BSDL | n.a. | ??? |
__poll_chk | n.a. | 2BSDL | n.a. | done |
__ppoll_chk | n.a. | 2BSDL | n.a. | done |
__pread64_chk | n.a. | 2BSDL | n.a. | n.a. |
__pread_chk | n.a. | 2BSDL | n.a. | done |
__read_chk | n.a. | 2BSDL | n.a. | done |
__readlink_chk | n.a. | 2BSDL | n.a. | done |
__readlinkat_chk | n.a. | 2BSDL | n.a. | done |
__recvfrom_chk | n.a. | 2BSDL | n.a. | done |
__rindex_chk | n.a. | 3BSDL | n.a. | done |
__snprintf_chk | APSL | 2BSDL | 2BSDL | done |
__sprintf_chk | APSL | 2BSDL | 2BSDL | done |
__stpcpy_chk | APSL | 2BSDL | 2BSDL | done |
__stpncpy_chk | APSL | 2BSDL | 2BSDL | done |
__stpncpy_chk2 | n.a. | 2BSDL | n.a. | done |
__strcat_chk | APSL | 2BSDL | 2BSDL | done |
__strchr_chk | n.a. | 3BSDL | n.a. | done |
__strchrnul_chk | n.a. | n.a. | n.a. | done |
__strcpy_chk | APSL | 2BSDL | 2BSDL | done |
__strlcat_chk | APSL | 2BSDL | n.a. | done |
__strlcpy_chk | APSL | 2BSDL | n.a. | done |
__strlen_chk | n.a. | 2BSDL | n.a. | done |
__strncat_chk | APSL | 2BSDL | 2BSDL | done |
__strncpy_chk | APSL | 2BSDL | 2BSDL | done |
__strncpy_chk2 | n.a. | 2BSDL | n.a. | done |
__strrchr_chk | n.a. | 3BSDL | n.a. | done |
__umask_chk | n.a. | 2BSDL | n.a. | done (sys/stat.h) |
__vsnprintf_chk | APSL | 2BSDL | 2BSDL | done |
__vsprintf_chk | APSL | 2BSDL | 2BSDL | done |
| realpath? | ||||
| fread? | ||||
| fwrite? | ||||
| getcwd? | ||||
| w*? |
1.2
- Netbsd has updated their stack smash protector related files (${NETBSDSRC}/lib/libc/misc/stack_protector.c, which contains the
__fail(...)and__chk_fail(...)functions. I plan to update these functions from NetBSD too. - Other thing, is to factor out the
__fail(...)and__chk_fail(...)to common place, and add them to libc_prive.h or security/common.h. After this change, we could use them from ssp and fortify. - The headers should placed in the lib/libc/include/security/{stack_protector,fortify_source,common}.h files.
__fail | |
__chk_fail | |
__ssp_chk_fail | |
__fortify_chk_fail |
- FreeBSD libc's headers live here:
| ${SRCTOP}/include/string.h | |
| ${SRCTOP}/include/stdlib.h | |
| ${SRCTOP}/include/stdio.h |
- what is right place for the newly added
__*_chksymbols: FBSD_1.4 or FBSDprivate_1.0 - in first sight FBSD_1.4 because they should be accessible from any library
1.3
- TODO
1.4
- TODO
notes
2.1
- TODO
2.2
- TODO
2.3
- TODO
tools
| svn-cherry-pick-from-git.csh | http://svnweb.freebsd.org/socsvn/soc2014/op/tools/svn-cherry-pick-from-git.csh?view=log |
weekly status
| 20150627 | https://lists.freebsd.org/pipermail/soc-status/2015-June/000918.html |
| 20150801 | http://xxx |
| 20150808 | http://xxx |
| 20150823 | http://xxx |