Index: lib/Makefile =================================================================== --- lib/Makefile +++ lib/Makefile @@ -18,6 +18,8 @@ ${_libcplusplus} \ ${_libcxxrt} \ libelf \ + libssp \ + libssp_nonshared \ msun # The main list; please keep these sorted alphabetically. Index: lib/libc/secure/stack_protector.c =================================================================== --- lib/libc/secure/stack_protector.c +++ lib/libc/secure/stack_protector.c @@ -61,10 +61,12 @@ extern int __sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen); +void __stack_chk_fail(void); +static void __fail(const char *); + +#ifndef IN_LIBSSP long __stack_chk_guard[8] = {0, 0, 0, 0, 0, 0, 0, 0}; static void __guard_setup(void) _GUARD_SETUP_CTOR_ATTR; -static void __fail(const char *); -void __stack_chk_fail(void); void __chk_fail(void); /*LINTED used*/ @@ -105,6 +107,13 @@ } } +void +__chk_fail(void) +{ + __fail("buffer overflow detected; terminated"); +} +#endif /* IN_LIBSSP */ + /*ARGSUSED*/ static void __fail(const char *msg) @@ -135,12 +144,6 @@ __fail("stack overflow detected; terminated"); } -void -__chk_fail(void) -{ - __fail("buffer overflow detected; terminated"); -} - #ifndef PIC __weak_reference(__stack_chk_fail, __stack_chk_fail_local); #endif Index: lib/libssp/Makefile =================================================================== --- /dev/null +++ lib/libssp/Makefile @@ -0,0 +1,14 @@ +# $FreeBSD$ + +PACKAGE=clibs +SHLIBDIR?= /lib +SHLIB=ssp +SHLIB_MAJOR=1 + +LDFLAGS+=-Wl,-F,libc.so.7 +VERSION_DEF=${SRCTOP}/lib/libc/Versions.def +SYMBOL_MAPS=${.CURDIR}/Symbol.map + +SRCS=__stub.c + +.include Index: lib/libssp/Symbol.map =================================================================== --- /dev/null +++ lib/libssp/Symbol.map @@ -0,0 +1,9 @@ +/* + * $FreeBSD$ + */ + +FBSD_1.0 { + __chk_fail; + __stack_chk_fail; + __stack_chk_guard; +}; Index: lib/libssp/__stub.c =================================================================== --- /dev/null +++ lib/libssp/__stub.c @@ -0,0 +1,33 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2013 Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +extern int __stub_N8TwezWFyocUB; + +int __stub_N8TwezWFyocUB; /* 42 */ Index: lib/libssp_nonshared/Makefile =================================================================== --- /dev/null +++ lib/libssp_nonshared/Makefile @@ -0,0 +1,14 @@ +# $FreeBSD$ + +PACKAGE=clibs +LIB=ssp_nonshared +NO_PIC= + +VERSION_DEF=${SRCTOP}/lib/libc/Versions.def +SYMBOL_MAPS=${.CURDIR}/Symbol.map + +.PATH: ${SRCTOP}/lib/libc/secure +CFLAGS+=-I${SRCTOP}/lib/libc/include -DIN_LIBSSP +SRCS=stack_protector.c + +.include Index: lib/libssp_nonshared/Symbol.map =================================================================== --- /dev/null +++ lib/libssp_nonshared/Symbol.map @@ -0,0 +1,8 @@ +/* + * $FreeBSD$ + */ + +FBSD_1.0 { + __stack_chk_fail; + __stack_chk_fail_local; +};