Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 May 2024 01:09:17 +0000 (UTC)
From:      Pedro Giffuni <pfg@freebsd.org>
To:        Kyle Evans <kaevans@fastmail.com>
Cc:        "src-committers@freebsd.org" <src-committers@freebsd.org>,  "dev-commits-src-all@freebsd.org" <dev-commits-src-all@freebsd.org>,  "dev-commits-src-main@freebsd.org" <dev-commits-src-main@freebsd.org>
Subject:   Re: git: be04fec42638 - main - Import _FORTIFY_SOURCE implementation from NetBSD
Message-ID:  <999469960.1638478.1716080957814@mail.yahoo.com>
In-Reply-To: <02326b5e-a1fe-4411-a869-d21f9a76130c@email.android.com>
References:  <02326b5e-a1fe-4411-a869-d21f9a76130c@email.android.com>

next in thread | previous in thread | raw e-mail | index | archive | help
------=_Part_1638477_2102893408.1716080957796
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

 (sorry for top posting .. my mailer just sucks)Hi;
I used to like the limited static checking FORTIFY_SOURCE provides and when=
 I ran it over FreeBSD it did find a couple of minor issues. It only works =
for GCC though.
I guess it doesn't really hurt to have FORTIFY_SOURCE around and NetBSD had=
 the least intrusive implementation the last time I checked but I would cer=
tainly request it should never be activated by default, specially with clan=
g. The GCC version has seen more development on glibc but I still think its=
 a dead end.
What I would like to see working on FreeBSD is Safestack as a replacement f=
or the stack protector, which we were so very slow to adopt even when it wa=
s originally developed in FreeBSD. I think other projects based on FreeBSD =
(Chimera and hardenedBSD) have been using it but I don't know the details.
This is just all my $0.02
Pedro.
    On Saturday, May 18, 2024 at 05:54:42 PM GMT-5, Kyle Evans <kaevans@fas=
tmail.com> wrote: =20
=20
=20

On May 18, 2024 13:42, Pedro Giffuni <pfg@freebsd.org> wrote:

 Oh no .. please not...
We went into that in a GSoC:
https://wiki.freebsd.org/SummerOfCode2015/FreeBSDLibcSecurityExtensions


Ultimately it proved to be useless since stack-protector-strong.

Respectfully, I disagree with your conclusion here:
1.) _FORTIFY_SOURCE provides more granular detection of overflow; I don't h=
ave to overflow all the way into the canary at the end of the frame to be d=
etected, so my minor bug now can be caught before something causes the stac=
k frame to be rearranged and turn it into a security issue later
2.) __builtin_object_size doesn't work on heap objects, but it actually can=
 work on subobjects from a heap allocation (e.g., &foo->name), so the cover=
age extends beyond the stack into starting to detect other kinds of overflo=
w=C2=A0
While the security value over stack-protector-strong may be marginal (I won=
't debate this specifically), the feature still has value in general.
Thanks,
Kyle Evans

The NetBSD code was not well adapted to clang either.
Ask me more if you really want to dig into it, but we don't want this.
Pedro.

    On Monday, May 13, 2024 at 12:24:13 AM GMT-5, Kyle Evans <kevans@freebs=
d.org> wrote: =20
=20
 The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=3Dbe04fec42638f30f50b5b55fd8e3=
634c0fb89928

commit be04fec42638f30f50b5b55fd8e3634c0fb89928
Author:=C2=A0 =C2=A0 Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2024-05-13 05:23:49 +0000
Commit:=C2=A0 =C2=A0 Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2024-05-13 05:23:49 +0000

=C2=A0 =C2=A0 Import _FORTIFY_SOURCE implementation from NetBSD
=C2=A0 =C2=A0=20
=C2=A0 =C2=A0 This is a mostly-unmodified copy of the various *_chk impleme=
ntations
=C2=A0 =C2=A0 and headers from NetBSD, without yet modifying system headers=
 to start
=C2=A0 =C2=A0 actually including them.=C2=A0 A future commit will also appl=
y the needed
=C2=A0 =C2=A0 bits to fix ssp/unistd.h.
=C2=A0 =C2=A0=20
=C2=A0 =C2=A0 Reviewed by:=C2=A0 =C2=A0 imp, pauamma_gundo.com (both previo=
us versions), kib
=C2=A0 =C2=A0 Sponsored by:=C2=A0 Stormshield
=C2=A0 =C2=A0 Sponsored by:=C2=A0 Klara, Inc.
=C2=A0 =C2=A0 Differential Revision:=C2=A0 https://reviews.freebsd.org/D323=
06
---
 etc/mtree/BSD.include.dist=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 2 +
 include/Makefile=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 |=C2=A0 2 +-
 include/ssp/Makefile=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=
=A0 6 ++
 include/ssp/ssp.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 |=C2=A0 91 ++++++++++++++++++++++++++
 include/ssp/stdio.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 |=C2=A0 93 ++++++++++++++++++++++++++
 include/ssp/string.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 129=
 ++++++++++++++++++++++++++++++++++++
 include/ssp/strings.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=
=A0 67 +++++++++++++++++++
 include/ssp/unistd.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=
=A0 54 +++++++++++++++
 lib/libc/secure/Makefile.inc=C2=A0 =C2=A0 =C2=A0 |=C2=A0 11 ++++
 lib/libc/secure/Symbol.map=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 18 +++++
 lib/libc/secure/fgets_chk.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 54 ++++++++=
+++++++
 lib/libc/secure/gets_chk.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 74 +++++++++=
++++++++++++
 lib/libc/secure/memcpy_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 53 ++++++++++++++=
+
 lib/libc/secure/memmove_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 47 +++++++++++++
 lib/libc/secure/memset_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 46 +++++++++++++
 lib/libc/secure/snprintf_chk.c=C2=A0 =C2=A0 |=C2=A0 56 ++++++++++++++++
 lib/libc/secure/sprintf_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 61 +++++++++++++=
++++
 lib/libc/secure/ssp_internal.h=C2=A0 =C2=A0 |=C2=A0 37 +++++++++++
 lib/libc/secure/stpcpy_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 55 ++++++++++++++=
++
 lib/libc/secure/stpncpy_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 53 +++++++++++++=
++
 lib/libc/secure/strcat_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 60 ++++++++++++++=
+++
 lib/libc/secure/strcpy_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 54 ++++++++++++++=
+
 lib/libc/secure/strncat_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 70 +++++++++++++=
+++++++
 lib/libc/secure/strncpy_chk.c=C2=A0 =C2=A0 =C2=A0 |=C2=A0 53 +++++++++++++=
++
 lib/libc/secure/vsnprintf_chk.c=C2=A0 =C2=A0 |=C2=A0 49 ++++++++++++++
 lib/libc/secure/vsprintf_chk.c=C2=A0 =C2=A0 |=C2=A0 58 ++++++++++++++++
 lib/libssp/Makefile=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 |=C2=A0 20 +++++-
 lib/libssp/Symbol.map=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=
=A0 12 ++--
 lib/libssp/Versions.def=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 5=
 ++
 lib/libssp/__builtin_object_size.3 | 110 +++++++++++++++++++++++++++++++
 lib/libssp/fortify_stubs.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 | 131 --------------=
-----------------------
 lib/libssp/ssp.3=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 | 130 ++++++++++++++++++++++++++++++++++++
 32 files changed, 1621 insertions(+), 140 deletions(-)

diff --git a/etc/mtree/BSD.include.dist b/etc/mtree/BSD.include.dist
index a6bd5880bf61..f8c83d6dde7a 100644
--- a/etc/mtree/BSD.include.dist
+++ b/etc/mtree/BSD.include.dist
@@ -372,6 +372,8 @@
=C2=A0 =C2=A0 =C2=A0 =C2=A0 mac_veriexec
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ..
=C2=A0 =C2=A0 ..
+=C2=A0 =C2=A0 ssp
+=C2=A0 =C2=A0 ..
=C2=A0 =C2=A0 sys
=C2=A0 =C2=A0 =C2=A0 =C2=A0 disk
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ..
diff --git a/include/Makefile b/include/Makefile
index 19e6beb95203..32774419f162 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -4,7 +4,7 @@
=20
 PACKAGE=3Dclibs
 CLEANFILES=3D osreldate.h version
-SUBDIR=3D arpa protocols rpcsvc rpc xlocale
+SUBDIR=3D arpa protocols rpcsvc rpc ssp xlocale
 .if ${MACHINE_CPUARCH} =3D=3D "amd64"
 SUBDIR+=3D=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 i386
 INCLUDE_SUBDIRS+=3D=C2=A0=C2=A0=C2=A0 i386
diff --git a/include/ssp/Makefile b/include/ssp/Makefile
new file mode 100644
index 000000000000..dff19f43c920
--- /dev/null
+++ b/include/ssp/Makefile
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+INCS=3D=C2=A0=C2=A0=C2=A0 ssp.h stdio.h string.h strings.h unistd.h
+INCSDIR=3D=C2=A0=C2=A0=C2=A0 ${INCLUDEDIR}/ssp
+
+.include <bsd.prog.mk>
diff --git a/include/ssp/ssp.h b/include/ssp/ssp.h
new file mode 100644
index 000000000000..35a9aeee02df
--- /dev/null
+++ b/include/ssp/ssp.h
@@ -0,0 +1,91 @@
+/*=C2=A0=C2=A0=C2=A0 $NetBSD: ssp.h,v 1.13 2015/09/03 20:43:47 plunky Exp =
$=C2=A0=C2=A0=C2=A0 */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006, 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.
+ */
+#ifndef _SSP_SSP_H_
+#define _SSP_SSP_H_
+
+#include <sys/cdefs.h>
+
+#if !defined(__cplusplus)
+# if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && \
+=C2=A0 =C2=A0 (__OPTIMIZE__ > 0 || defined(__clang__))
+#=C2=A0 if _FORTIFY_SOURCE > 1
+#=C2=A0 define __SSP_FORTIFY_LEVEL 2
+#=C2=A0 else
+#=C2=A0 define __SSP_FORTIFY_LEVEL 1
+#=C2=A0 endif
+# else
+#=C2=A0 define __SSP_FORTIFY_LEVEL 0
+# endif
+#else
+# define __SSP_FORTIFY_LEVEL 0
+#endif
+
+#define=C2=A0=C2=A0=C2=A0 __ssp_var(type)=C2=A0=C2=A0=C2=A0 __CONCAT(__ssp=
_ ## type, __COUNTER__)
+
+/* __ssp_real is used by the implementation in libc */
+#if __SSP_FORTIFY_LEVEL =3D=3D 0
+#define __ssp_real_(fun)=C2=A0=C2=A0=C2=A0 fun
+#else
+#define __ssp_real_(fun)=C2=A0=C2=A0=C2=A0 __ssp_real_ ## fun
+#endif
+#define __ssp_real(fun)=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __ssp_real_(f=
un)
+
+#define __ssp_inline static __inline __attribute__((__always_inline__))
+
+#define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1)
+#define __ssp_bos0(ptr) __builtin_object_size(ptr, 0)
+
+#define __ssp_check(buf, len, bos) \
+=C2=A0=C2=A0=C2=A0 if (bos(buf) !=3D (size_t)-1 && len > bos(buf)) \
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail()
+#define __ssp_redirect_raw(rtype, fun, symbol, args, call, cond, bos) \
+rtype __ssp_real_(fun) args __RENAME(symbol); \
+__ssp_inline rtype fun args __RENAME(__ssp_protected_ ## fun); \
+__ssp_inline rtype fun args { \
+=C2=A0=C2=A0=C2=A0 if (cond) \
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __ssp_check(__buf, __len, bos); \
+=C2=A0=C2=A0=C2=A0 return __ssp_real_(fun) call; \
+}
+
+#define __ssp_redirect(rtype, fun, args, call) \
+=C2=A0 =C2=A0 __ssp_redirect_raw(rtype, fun, fun, args, call, 1, __ssp_bos=
)
+#define __ssp_redirect0(rtype, fun, args, call) \
+=C2=A0 =C2=A0 __ssp_redirect_raw(rtype, fun, fun, args, call, 1, __ssp_bos=
0)
+
+__BEGIN_DECLS
+void __stack_chk_fail(void) __dead2;
+void __chk_fail(void) __dead2;
+__END_DECLS
+
+#endif /* _SSP_SSP_H_ */
diff --git a/include/ssp/stdio.h b/include/ssp/stdio.h
new file mode 100644
index 000000000000..72e3236eac80
--- /dev/null
+++ b/include/ssp/stdio.h
@@ -0,0 +1,93 @@
+/*=C2=A0=C2=A0=C2=A0 $NetBSD: stdio.h,v 1.5 2011/07/17 20:54:34 joerg Exp =
$=C2=A0=C2=A0=C2=A0 */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.
+ */
+#ifndef _SSP_STDIO_H_
+#define _SSP_STDIO_H_
+
+#include <ssp/ssp.h>
+
+__BEGIN_DECLS
+int __sprintf_chk(char *__restrict, int, size_t, const char *__restrict, .=
..)
+=C2=A0 =C2=A0 __printflike(4, 5);
+int __vsprintf_chk(char *__restrict, int, size_t, const char *__restrict,
+=C2=A0 =C2=A0 __va_list)
+=C2=A0 =C2=A0 __printflike(4, 0);
+int __snprintf_chk(char *__restrict, size_t, int, size_t,
+=C2=A0 =C2=A0 const char *__restrict, ...)
+=C2=A0 =C2=A0 __printflike(5, 6);
+int __vsnprintf_chk(char *__restrict, size_t, int, size_t,
+=C2=A0 =C2=A0 const char *__restrict, __va_list)
+=C2=A0 =C2=A0 __printflike(5, 0);
+char *__gets_chk(char *, size_t);
+char *__fgets_chk(char *, int, size_t, FILE *);
+__END_DECLS
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#define sprintf(str, ...) ({=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __builtin___sprintf_chk(_ssp_str, 0, __ssp_bos(_ssp_str),=C2=
=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __VA_ARGS__); \
+})
+
+#define vsprintf(str, fmt, ap) ({=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 \
+=C2=A0 =C2=A0 __builtin___vsprintf_chk(_ssp_str, 0, __ssp_bos(_ssp_str), f=
mt,=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 ap);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+})
+
+#define snprintf(str, len, ...) ({=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 \
+=C2=A0 =C2=A0 __builtin___snprintf_chk(_ssp_str, len, 0, __ssp_bos(_ssp_st=
r),=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __VA_ARGS__);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 \
+})
+
+#define vsnprintf(str, len, fmt, ap) ({=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 \
+=C2=A0 =C2=A0 __builtin___vsnprintf_chk(_ssp_str, len, 0, __ssp_bos(_ssp_s=
tr),=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 fmt, ap);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 \
+})
+
+#define gets(str) ({=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 \
+=C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __gets_chk(_ssp_str, __ssp_bos(_ssp_str));=C2=A0=C2=A0=C2=A0=
 \
+})
+
+#define fgets(str, len, fp) ({=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 char *_ssp_str =3D (str);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 \
+=C2=A0 =C2=A0 __fgets_chk(_ssp_str, len, __ssp_bos(_ssp_str), fp);=C2=A0=
=C2=A0=C2=A0 \
+})
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+
+#endif /* _SSP_STDIO_H_ */
diff --git a/include/ssp/string.h b/include/ssp/string.h
new file mode 100644
index 000000000000..996020fda778
--- /dev/null
+++ b/include/ssp/string.h
@@ -0,0 +1,129 @@
+/*=C2=A0=C2=A0=C2=A0 $NetBSD: string.h,v 1.14 2020/09/05 13:37:59 mrg Exp =
$=C2=A0=C2=A0=C2=A0 */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.
+ */
+#ifndef _SSP_STRING_H_
+#define _SSP_STRING_H_
+
+#include <ssp/ssp.h>
+
+__BEGIN_DECLS
+void *__memcpy_chk(void *, const void *, size_t, size_t);
+void *__memmove_chk(void *, const void *, size_t, size_t);
+void *__memset_chk(void *, int, size_t, size_t);
+char *__stpcpy_chk(char *, const char *, size_t);
+char *__stpncpy_chk(char *, const char *, size_t, size_t);
+char *__strcat_chk(char *, const char *, size_t);
+char *__strcpy_chk(char *, const char *, size_t);
+char *__strncat_chk(char *, const char *, size_t, size_t);
+char *__strncpy_chk(char *, const char *, size_t, size_t);
+__END_DECLS
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#define __ssp_bos_check3_typed_var(fun, dsttype, dsrvar, dst, srctype, src=
var, \
+=C2=A0 =C2=A0 src, lenvar, len) ({=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 srctype srcvar =3D (src);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 dsttype dstvar =3D (dst);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 size_t lenvar =3D (len);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 ((__ssp_bos0(dstvar) !=3D (size_t)-1) ?=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __builtin___ ## fun ## _chk(dstvar, srcvar, lenvar,=C2=A0=C2=
=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __ssp_bos0(dstvar)) :=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __ ## fun ## _ichk(dstvar, srcvar, lenvar));=C2=A0=C2=A0=C2=
=A0 \
+})
+
+#define __ssp_bos_check3_typed(fun, dsttype, dst, srctype, src, len)=C2=A0=
=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __ssp_bos_check3_typed_var(fun, dsttype, __ssp_var(dstv), ds=
t,=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 srctype, __ssp_var(srcv), src, __ssp_var(lenv)=
, len)
+
+#define __ssp_bos_check3(fun, dst, src, len)=C2=A0=C2=A0=C2=A0 =C2=A0=C2=
=A0=C2=A0 \
+=C2=A0 =C2=A0 __ssp_bos_check3_typed_var(fun, void *, __ssp_var(dstv), dst=
,=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 const void *, __ssp_var(srcv), src, __ssp_var(=
lenv), len)
+
+#define __ssp_bos_check2_var(fun, dstvar, dst, srcvar, src) ({=C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 const void *srcvar =3D (src);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 void *dstvar =3D (dst);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 ((__ssp_bos0(dstvar) !=3D (size_t)-1) ?=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __builtin___ ## fun ## _chk(dstvar, srcvar,=C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __ssp_bos0(dstvar)) :=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __ ## fun ## _ichk(dstvar, srcvar));=C2=A0=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 \
+})
+
+#define __ssp_bos_check2(fun, dst, src)=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __ssp_bos_check2_var(fun, __ssp_var(dstv), dst, __ssp_var(sr=
cv), src)
+
+#define __ssp_bos_icheck3_restrict(fun, type1, type2) \
+static __inline type1 __ ## fun ## _ichk(type1 __restrict, type2 __restric=
t, size_t); \
+static __inline __attribute__((__always_inline__)) type1 \
+__ ## fun ## _ichk(type1 __restrict dst, type2 __restrict src, size_t len)=
 { \
+=C2=A0=C2=A0=C2=A0 return __builtin___ ## fun ## _chk(dst, src, len, __ssp=
_bos0(dst)); \
+}
+
+#define __ssp_bos_icheck3(fun, type1, type2) \
+static __inline type1 __ ## fun ## _ichk(type1, type2, size_t); \
+static __inline __attribute__((__always_inline__)) type1 \
+__ ## fun ## _ichk(type1 dst, type2 src, size_t len) { \
+=C2=A0=C2=A0=C2=A0 return __builtin___ ## fun ## _chk(dst, src, len, __ssp=
_bos0(dst)); \
+}
+
+#define __ssp_bos_icheck2_restrict(fun, type1, type2) \
+static __inline type1 __ ## fun ## _ichk(type1, type2); \
+static __inline __attribute__((__always_inline__)) type1 \
+__ ## fun ## _ichk(type1 __restrict dst, type2 __restrict src) { \
+=C2=A0=C2=A0=C2=A0 return __builtin___ ## fun ## _chk(dst, src, __ssp_bos0=
(dst)); \
+}
+
+__BEGIN_DECLS
+__ssp_bos_icheck3_restrict(memcpy, void *, const void *)
+__ssp_bos_icheck3(memmove, void *, const void *)
+__ssp_bos_icheck3(memset, void *, int)
+__ssp_bos_icheck2_restrict(stpcpy, char *, const char *)
+__ssp_bos_icheck3_restrict(stpncpy, char *, const char *)
+__ssp_bos_icheck2_restrict(strcpy, char *, const char *)
+__ssp_bos_icheck2_restrict(strcat, char *, const char *)
+__ssp_bos_icheck3_restrict(strncpy, char *, const char *)
+__ssp_bos_icheck3_restrict(strncat, char *, const char *)
+__END_DECLS
+
+#define memcpy(dst, src, len) __ssp_bos_check3(memcpy, dst, src, len)
+#define memmove(dst, src, len) __ssp_bos_check3(memmove, dst, src, len)
+#define memset(dst, val, len) \
+=C2=A0 =C2=A0 __ssp_bos_check3_typed(memset, void *, dst, int, val, len)
+#define stpcpy(dst, src) __ssp_bos_check2(stpcpy, dst, src)
+#define stpncpy(dst, src, len) __ssp_bos_check3(stpncpy, dst, src, len)
+#define strcpy(dst, src) __ssp_bos_check2(strcpy, dst, src)
+#define strcat(dst, src) __ssp_bos_check2(strcat, dst, src)
+#define strncpy(dst, src, len) __ssp_bos_check3(strncpy, dst, src, len)
+#define strncat(dst, src, len) __ssp_bos_check3(strncat, dst, src, len)
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_STRING_H_ */
diff --git a/include/ssp/strings.h b/include/ssp/strings.h
new file mode 100644
index 000000000000..06c9c7cc0a09
--- /dev/null
+++ b/include/ssp/strings.h
@@ -0,0 +1,67 @@
+/*=C2=A0=C2=A0=C2=A0 $NetBSD: strings.h,v 1.3 2008/04/28 20:22:54 martin E=
xp $=C2=A0=C2=A0=C2=A0 */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.
+ */
+#ifndef _SSP_STRINGS_H_
+#define _SSP_STRINGS_H_
+
+#include <ssp/ssp.h>
+#include <string.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#define _ssp_bcopy(srcvar, src, dstvar, dst, lenvar,=C2=A0 len) ({=C2=A0=
=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 const void *srcvar =3D (src);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 void *dstvar =3D (dst);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 size_t lenvar =3D (len);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 ((__ssp_bos0(dstvar) !=3D (size_t)-1) ?=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __builtin___memmove_chk(dstvar, srcvar, lenvar,=C2=A0=C2=A0=
=C2=A0 \
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __ssp_bos0(dstvar)) :=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __memmove_ichk(dstvar, srcvar, lenvar));=C2=A0=C2=A0=C2=A0 \
+})
+
+#define=C2=A0=C2=A0=C2=A0 bcopy(src, dst, len)=C2=A0=C2=A0=C2=A0 =C2=A0=C2=
=A0=C2=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 _ssp_bcopy(__ssp_var(srcv), src, __ssp_var(dstv), dst, __ssp=
_var(lenv), len)
+
+#define _ssp_bzero(dstvar, dst, lenvar, len) ({=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 void *dstvar =3D (dst);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 size_t lenvar =3D (len);=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 ((__ssp_bos0(dstvar) !=3D (size_t)-1) ?=C2=A0=C2=A0=C2=A0 \
+=C2=A0 =C2=A0 __builtin___memset_chk(dstvar, 0, lenvar,=C2=A0=C2=A0=C2=A0 =
\
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 __ssp_bos0(dstvar)) : \
+=C2=A0 =C2=A0 __memset_ichk(dstvar, 0, lenvar));=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 \
+})
+
+#define=C2=A0=C2=A0=C2=A0 bzero(dst, len)=C2=A0=C2=A0=C2=A0 _ssp_bzero(__s=
sp_var(dstv), dst, __ssp_var(lenv), len)
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_STRINGS_H_ */
diff --git a/include/ssp/unistd.h b/include/ssp/unistd.h
new file mode 100644
index 000000000000..2414e2baa96b
--- /dev/null
+++ b/include/ssp/unistd.h
@@ -0,0 +1,54 @@
+/*=C2=A0=C2=A0=C2=A0 $NetBSD: unistd.h,v 1.7 2015/06/25 18:41:03 joerg Exp=
 $=C2=A0=C2=A0=C2=A0 */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.
+ */
+#ifndef _SSP_UNISTD_H_
+#define _SSP_UNISTD_H_
+
+#include <ssp/ssp.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+__BEGIN_DECLS
+
+__ssp_redirect0(ssize_t, read, (int __fd, void *__buf, size_t __len), \
+=C2=A0 =C2=A0 (__fd, __buf, __len));
+
+__ssp_redirect(ssize_t, readlink, (const char *__restrict __path, \
+=C2=A0 =C2=A0 char *__restrict __buf, size_t __len), (__path, __buf, __len=
));
+
+__ssp_redirect_raw(char *, getcwd, getcwd, (char *__buf, size_t __len),
+=C2=A0 =C2=A0 (__buf, __len), __buf !=3D 0, __ssp_bos);
+
+__END_DECLS
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_UNISTD_H_ */
diff --git a/lib/libc/secure/Makefile.inc b/lib/libc/secure/Makefile.inc
index 8574c5a05dc5..3b1ad879c715 100644
--- a/lib/libc/secure/Makefile.inc
+++ b/lib/libc/secure/Makefile.inc
@@ -3,6 +3,17 @@
=20
 .PATH: ${LIBC_SRCTOP}/secure
=20
+# _FORTIFY_SOURCE
+SRCS+=3D=C2=A0=C2=A0=C2=A0 gets_chk.c fgets_chk.c memcpy_chk.c memmove_chk=
.c memset_chk.c \
+=C2=A0=C2=A0=C2=A0 snprintf_chk.c sprintf_chk.c stpcpy_chk.c stpncpy_chk.c=
 \
+=C2=A0=C2=A0=C2=A0 strcat_chk.c strcpy_chk.c strncat_chk.c strncpy_chk.c \
+=C2=A0=C2=A0=C2=A0 vsnprintf_chk.c vsprintf_chk.c
+
+CFLAGS.snprintf_chk.c+=3D=C2=A0=C2=A0=C2=A0 -Wno-unused-parameter
+CFLAGS.sprintf_chk.c+=3D=C2=A0=C2=A0=C2=A0 -Wno-unused-parameter
+CFLAGS.vsnprintf_chk.c+=3D=C2=A0=C2=A0=C2=A0 -Wno-unused-parameter
+CFLAGS.vsprintf_chk.c+=3D=C2=A0=C2=A0=C2=A0 -Wno-unused-parameter
+
 # Sources common to both syscall interfaces:
 SRCS+=3D=C2=A0=C2=A0=C2=A0 stack_protector.c \
 =C2=A0=C2=A0=C2=A0 stack_protector_compat.c
diff --git a/lib/libc/secure/Symbol.map b/lib/libc/secure/Symbol.map
index 641f451b5421..7859fcee3821 100644
--- a/lib/libc/secure/Symbol.map
+++ b/lib/libc/secure/Symbol.map
@@ -3,3 +3,21 @@ FBSD_1.0 {
 =C2=A0=C2=A0=C2=A0 __stack_chk_fail;
 =C2=A0=C2=A0=C2=A0 __stack_chk_guard;
 };
+
+FBSD_1.8 {
+=C2=A0=C2=A0=C2=A0 __gets_chk;
+=C2=A0=C2=A0=C2=A0 __fgets_chk;
+=C2=A0=C2=A0=C2=A0 __memcpy_chk;
+=C2=A0=C2=A0=C2=A0 __memmove_chk;
+=C2=A0=C2=A0=C2=A0 __memset_chk;
+=C2=A0=C2=A0=C2=A0 __snprintf_chk;
+=C2=A0=C2=A0=C2=A0 __sprintf_chk;
+=C2=A0=C2=A0=C2=A0 __stpcpy_chk;
+=C2=A0=C2=A0=C2=A0 __stpncpy_chk;
+=C2=A0=C2=A0=C2=A0 __strcat_chk;
+=C2=A0=C2=A0=C2=A0 __strcpy_chk;
+=C2=A0=C2=A0=C2=A0 __strncat_chk;
+=C2=A0=C2=A0=C2=A0 __strncpy_chk;
+=C2=A0=C2=A0=C2=A0 __vsnprintf_chk;
+=C2=A0=C2=A0=C2=A0 __vsprintf_chk;
+};
diff --git a/lib/libc/secure/fgets_chk.c b/lib/libc/secure/fgets_chk.c
new file mode 100644
index 000000000000..72aa1d816ce1
--- /dev/null
+++ b/lib/libc/secure/fgets_chk.c
@@ -0,0 +1,54 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: fgets_chk.c,v 1.6 2009/02/05 05:41:51 lukem Exp $");
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <ssp/stdio.h>
+#include <ssp/string.h>
+#undef fgets
+
+char *
+__fgets_chk(char * __restrict buf, int len, size_t slen, FILE *fp)
+{
+=C2=A0=C2=A0=C2=A0 if (slen >=3D (size_t)INT_MAX)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return (fgets(buf, len, fp));
+
+=C2=A0=C2=A0=C2=A0 if (len >=3D 0 && (size_t)len > slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+
+=C2=A0=C2=A0=C2=A0 return (fgets(buf, len, fp));
+}
diff --git a/lib/libc/secure/gets_chk.c b/lib/libc/secure/gets_chk.c
new file mode 100644
index 000000000000..18c1e2d18f43
--- /dev/null
+++ b/lib/libc/secure/gets_chk.c
@@ -0,0 +1,74 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: gets_chk.c,v 1.7 2013/10/04 20:49:16 christos Exp $");
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <ssp/stdio.h>
+#include <ssp/string.h>
+
+char *__gets_unsafe(char *);
+
+char *
+__gets_chk(char * __restrict buf, size_t slen)
+{
+=C2=A0=C2=A0=C2=A0 char *abuf;
+=C2=A0=C2=A0=C2=A0 size_t len;
+
+=C2=A0=C2=A0=C2=A0 if (slen >=3D (size_t)INT_MAX)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return (__gets_unsafe(buf));
+
+=C2=A0=C2=A0=C2=A0 if ((abuf =3D malloc(slen + 1)) =3D=3D NULL)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return (__gets_unsafe(buf));
+
+=C2=A0=C2=A0=C2=A0 if (fgets(abuf, (int)(slen + 1), stdin) =3D=3D NULL) {
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 free(abuf);
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return (NULL);
+=C2=A0=C2=A0=C2=A0 }
+
+=C2=A0=C2=A0=C2=A0 len =3D strlen(abuf);
+=C2=A0=C2=A0=C2=A0 if (len > 0 && abuf[len - 1] =3D=3D '\n')
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 --len;
+
+=C2=A0=C2=A0=C2=A0 if (len >=3D slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+
+=C2=A0=C2=A0=C2=A0 (void)memcpy(buf, abuf, len);
+
+=C2=A0=C2=A0=C2=A0 buf[len] =3D '\0';
+=C2=A0=C2=A0=C2=A0 free(abuf);
+=C2=A0=C2=A0=C2=A0 return (buf);
+}
diff --git a/lib/libc/secure/memcpy_chk.c b/lib/libc/secure/memcpy_chk.c
new file mode 100644
index 000000000000..99cf2d5f13ff
--- /dev/null
+++ b/lib/libc/secure/memcpy_chk.c
@@ -0,0 +1,53 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: memcpy_chk.c,v 1.7 2015/05/13 19:57:16 joerg Exp $");
+
+#include <string.h>
+
+#include <ssp/string.h>
+#undef memcpy
+
+#include "ssp_internal.h"
+
+void *
+__memcpy_chk(void * __restrict dst, const void * __restrict src, size_t le=
n,
+=C2=A0 =C2=A0 size_t slen)
+{
+=C2=A0=C2=A0=C2=A0 if (len > slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+
+=C2=A0=C2=A0=C2=A0 if (__ssp_overlap((const char *)src, (const char *)dst,=
 len))
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+
+=C2=A0=C2=A0=C2=A0 return (memcpy(dst, src, len));
+}
diff --git a/lib/libc/secure/memmove_chk.c b/lib/libc/secure/memmove_chk.c
new file mode 100644
index 000000000000..07f965d608fc
--- /dev/null
+++ b/lib/libc/secure/memmove_chk.c
@@ -0,0 +1,47 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: memmove_chk.c,v 1.6 2020/09/05 13:37:59 mrg Exp $");
+
+#include <string.h>
+
+#include <ssp/string.h>
+#undef memmove
+
+void *
+__memmove_chk(void *dst, const void *src, size_t len,
+=C2=A0 =C2=A0 size_t slen)
+{
+=C2=A0=C2=A0=C2=A0 if (len > slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+=C2=A0=C2=A0=C2=A0 return (memmove(dst, src, len));
+}
diff --git a/lib/libc/secure/memset_chk.c b/lib/libc/secure/memset_chk.c
new file mode 100644
index 000000000000..f337be98b46d
--- /dev/null
+++ b/lib/libc/secure/memset_chk.c
@@ -0,0 +1,46 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: memset_chk.c,v 1.5 2014/09/17 00:39:28 joerg Exp $");
+
+#include <string.h>
+
+#include <ssp/string.h>
+#undef memset
+
+void *
+__memset_chk(void * __restrict dst, int val, size_t len, size_t slen)
+{
+=C2=A0=C2=A0=C2=A0 if (len > slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+=C2=A0=C2=A0=C2=A0 return (memset(dst, val, len));
+}
diff --git a/lib/libc/secure/snprintf_chk.c b/lib/libc/secure/snprintf_chk.=
c
new file mode 100644
index 000000000000..52ef874ede5b
--- /dev/null
+++ b/lib/libc/secure/snprintf_chk.c
@@ -0,0 +1,56 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *=C2=A0 =C2=A0 notice, this list of conditions and the following disclaim=
er in the
+ *=C2=A0 =C2=A0 documentation and/or other materials provided with the dis=
tribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.=C2=A0 IN NO EVENT SHALL THE FOUNDATION OR CONTR=
IBUTORS
+ * 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 BUSINES=
S
+ * 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: snprintf_chk.c,v 1.5 2008/04/28 20:23:00 martin Exp $");
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <ssp/stdio.h>
+#undef vsnprintf
+
+int
+__snprintf_chk(char * __restrict buf, size_t len, int flags, size_t slen,
+=C2=A0 =C2=A0 const char * __restrict fmt, ...)
+{
+=C2=A0=C2=A0=C2=A0 va_list ap;
+=C2=A0=C2=A0=C2=A0 int rv;
+
+=C2=A0=C2=A0=C2=A0 if (len > slen)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 __chk_fail();
+
+=C2=A0=C2=A0=C2=A0 va_start(ap, fmt);
+=C2=A0=C2=A0=C2=A0 rv =3D vsnprintf(buf, len, fmt, ap);
+=C2=A0=C2=A0=C2=A0 va_end(ap);
+
+=C2=A0=C2=A0=C2=A0 return (rv);
+}
diff --git a/lib/libc/secure/sprintf_chk.c b/lib/libc/secure/sprintf_chk.c
new file mode 100644
index 000000000000..d4c42ccba3ce
--- /dev/null
+++ b/lib/libc/secure/sprintf_chk.c
@@ -0,0 +1,61 @@
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
*** 1063 LINES SKIPPED ***
 =20

 =20
------=_Part_1638477_2102893408.1716080957796
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html><head></head><body><div class=3D"ydp4d23c449yahoo-style-wrap" style=
=3D"font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px=
;"><div></div>
        <div dir=3D"ltr" data-setdir=3D"false">(sorry for top posting .. my=
 mailer just sucks)</div><div dir=3D"ltr" data-setdir=3D"false">Hi;</div><d=
iv dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=3D"ltr" data-setdir=
=3D"false">I used to like the limited static checking FORTIFY_SOURCE provid=
es and when I ran it over FreeBSD it did find a couple of minor issues. It =
only works for GCC though.</div><div dir=3D"ltr" data-setdir=3D"false"><br>=
</div><div dir=3D"ltr" data-setdir=3D"false">I guess it doesn't really hurt=
 to have FORTIFY_SOURCE around and NetBSD had the least intrusive implement=
ation the last time I checked but I would certainly request it should never=
 be activated by default, specially with clang. The GCC version has seen mo=
re development on glibc but I still think its a dead end.</div><div dir=3D"=
ltr" data-setdir=3D"false"><br></div><div dir=3D"ltr" data-setdir=3D"false"=
>What I would like to see working on FreeBSD is Safestack as a replacement =
for the stack protector, which we were so very slow to adopt even when it w=
as originally developed in FreeBSD. I think other projects based on FreeBSD=
 (Chimera and hardenedBSD) have been using it but I don't know the details.=
</div><div><br></div><div dir=3D"ltr" data-setdir=3D"false">This is just al=
l my $0.02</div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=
=3D"ltr" data-setdir=3D"false">Pedro.</div><div dir=3D"ltr" data-setdir=3D"=
false"><br></div>
       =20
        </div><div id=3D"ydp793a6df0yahoo_quoted_6958103340" class=3D"ydp79=
3a6df0yahoo_quoted">
            <div style=3D"font-family:'Helvetica Neue', Helvetica, Arial, s=
ans-serif;font-size:13px;color:#26282a;">
               =20
                <div>
                        On Saturday, May 18, 2024 at 05:54:42 PM GMT-5, Kyl=
e Evans &lt;kaevans@fastmail.com&gt; wrote:
                    </div>
                    <div><br></div>
                    <div><br></div>
               =20
               =20
                <div><div id=3D"ydp793a6df0yiv2863220514"><div><div><div><b=
r clear=3D"none"><div class=3D"ydp793a6df0yiv2863220514gmail_extra"><br cle=
ar=3D"none"><div class=3D"ydp793a6df0yiv2863220514gmail_quote">On May 18, 2=
024 13:42, Pedro Giffuni &lt;pfg@freebsd.org&gt; wrote:<br clear=3D"none"><=
blockquote style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-le=
ft:1ex;" class=3D"ydp793a6df0yiv2863220514quote"><div><div style=3D"font-fa=
mily:'helvetica neue' , 'helvetica' , 'arial' , sans-serif;font-size:16px;"=
><div></div>
        <div dir=3D"ltr">Oh no .. please not...</div><div dir=3D"ltr"><br c=
lear=3D"none"></div><div dir=3D"ltr">We went into that in a GSoC:</div><div=
 dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr"><a shape=3D"rect" hr=
ef=3D"https://wiki.freebsd.org/SummerOfCode2015/FreeBSDLibcSecurityExtensio=
ns" rel=3D"nofollow" target=3D"_blank">https://wiki.freebsd.org/SummerOfCod=
e2015/FreeBSDLibcSecurityExtensions</a><br clear=3D"none"></div><div><br cl=
ear=3D"none"></div><div><br clear=3D"none"></div><div dir=3D"ltr">Ultimatel=
y it proved to be useless since stack-protector-strong.</div></div></div></=
blockquote></div></div></div><div><br clear=3D"none"></div><div>Respectfull=
y, I disagree with your conclusion here:</div><div><br clear=3D"none"></div=
><div>1.) _FORTIFY_SOURCE provides more granular detection of overflow; I d=
on't have to overflow all the way into the canary at the end of the frame t=
o be detected, so my minor bug now can be caught before something causes th=
e stack frame to be rearranged and turn it into a security issue later</div=
><div><br clear=3D"none"></div><div>2.) __builtin_object_size doesn't work =
on heap objects, but it actually can work on subobjects from a heap allocat=
ion (e.g., &amp;foo-&gt;name), so the coverage extends beyond the stack int=
o starting to detect other kinds of overflow&nbsp;</div><div><br clear=3D"n=
one"></div><div>While the security value over stack-protector-strong may be=
 marginal (I won't debate this specifically), the feature still has value i=
n general.</div><div><br clear=3D"none"></div><div>Thanks,</div><div><br cl=
ear=3D"none"></div><div>Kyle Evans</div><div><br clear=3D"none"></div><div>=
<div class=3D"ydp793a6df0yiv2863220514gmail_extra"><div class=3D"ydp793a6df=
0yiv2863220514gmail_quote"><blockquote style=3D"margin:0 0 0 .8ex;border-le=
ft:1px #ccc solid;padding-left:1ex;" class=3D"ydp793a6df0yiv2863220514quote=
"><div><div style=3D"font-family:'helvetica neue' , 'helvetica' , 'arial' ,=
 sans-serif;font-size:16px;"><div dir=3D"ltr">The NetBSD code was not well =
adapted to clang either.</div><div dir=3D"ltr"><br clear=3D"none"></div><di=
v dir=3D"ltr">Ask me more if you really want to dig into it, but we don't w=
ant this.</div><div dir=3D"ltr"><br clear=3D"none"></div><div dir=3D"ltr">P=
edro.</div><div><br clear=3D"none"></div><div><br clear=3D"none"></div>
       =20
        </div><div id=3D"ydp793a6df0yiv2863220514yqt25928" class=3D"ydp793a=
6df0yiv2863220514yqt0317471617"><div>
            <div style=3D"font-family:'helvetica neue' , 'helvetica' , 'ari=
al' , sans-serif;font-size:13px;color:#26282a;">
               =20
                <div>
                        On Monday, May 13, 2024 at 12:24:13 AM GMT-5, Kyle =
Evans &lt;kevans@freebsd.org&gt; wrote:
                    </div>
                    <div><br clear=3D"none"></div>
                    <div><br clear=3D"none"></div>
               =20
               =20
                <div><div dir=3D"ltr">The branch main has been updated by k=
evans:<br clear=3D"none"></div><div dir=3D"ltr"><br clear=3D"none"></div><d=
iv dir=3D"ltr">URL: <a shape=3D"rect" href=3D"https://cgit.FreeBSD.org/src/=
commit/?id=3Dbe04fec42638f30f50b5b55fd8e3634c0fb89928" rel=3D"nofollow" tar=
get=3D"_blank">https://cgit.FreeBSD.org/src/commit/?id=3Dbe04fec42638f30f50=
b5b55fd8e3634c0fb89928</a><br clear=3D"none"></div><div dir=3D"ltr"><br cle=
ar=3D"none"></div><div dir=3D"ltr">commit be04fec42638f30f50b5b55fd8e3634c0=
fb89928<br clear=3D"none"></div><div dir=3D"ltr">Author:&nbsp; &nbsp;  Kyle=
 Evans &lt;<a shape=3D"rect" href=3D"mailto:kevans@FreeBSD.org" rel=3D"nofo=
llow" target=3D"_blank">kevans@FreeBSD.org</a>&gt;<br clear=3D"none"></div>=
<div dir=3D"ltr">AuthorDate: 2024-05-13 05:23:49 +0000<br clear=3D"none"></=
div><div dir=3D"ltr">Commit:&nbsp; &nbsp;  Kyle Evans &lt;<a shape=3D"rect"=
 href=3D"mailto:kevans@FreeBSD.org" rel=3D"nofollow" target=3D"_blank">keva=
ns@FreeBSD.org</a>&gt;<br clear=3D"none"></div><div dir=3D"ltr">CommitDate:=
 2024-05-13 05:23:49 +0000<br clear=3D"none"></div><div dir=3D"ltr"><br cle=
ar=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp; Import _FORTIFY_SOURCE imp=
lementation from NetBSD<br clear=3D"none"></div><div dir=3D"ltr">&nbsp; &nb=
sp; <br clear=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp; This is a mostl=
y-unmodified copy of the various *_chk implementations<br clear=3D"none"></=
div><div dir=3D"ltr">&nbsp; &nbsp; and headers from NetBSD, without yet mod=
ifying system headers to start<br clear=3D"none"></div><div dir=3D"ltr">&nb=
sp; &nbsp; actually including them.&nbsp; A future commit will also apply t=
he needed<br clear=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp; bits to fi=
x ssp/unistd.h.<br clear=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp; <br =
clear=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp; Reviewed by:&nbsp; &nbs=
p; imp, pauamma_gundo.com (both previous versions), kib<br clear=3D"none"><=
/div><div dir=3D"ltr">&nbsp; &nbsp; Sponsored by:&nbsp;  Stormshield<br cle=
ar=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp; Sponsored by:&nbsp;  Klara=
, Inc.<br clear=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp; Differential =
Revision:&nbsp; <a shape=3D"rect" href=3D"https://reviews.freebsd.org/D3230=
6" rel=3D"nofollow" target=3D"_blank">https://reviews.freebsd.org/D32306</a=
><br clear=3D"none"></div><div dir=3D"ltr">---<br clear=3D"none"></div><div=
 dir=3D"ltr"> etc/mtree/BSD.include.dist&nbsp; &nbsp; &nbsp; &nbsp;  |&nbsp=
;  2 +<br clear=3D"none"></div><div dir=3D"ltr"> include/Makefile&nbsp; &nb=
sp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |&nbsp;  2 +-<br clea=
r=3D"none"></div><div dir=3D"ltr"> include/ssp/Makefile&nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; &nbsp; &nbsp;  |&nbsp;  6 ++<br clear=3D"none"></div><div di=
r=3D"ltr"> include/ssp/ssp.h&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp=
; &nbsp; &nbsp; |&nbsp; 91 ++++++++++++++++++++++++++<br clear=3D"none"></d=
iv><div dir=3D"ltr"> include/ssp/stdio.h&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; |&nbsp; 93 ++++++++++++++++++++++++++<br clear=3D"none=
"></div><div dir=3D"ltr"> include/ssp/string.h&nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp;  | 129 ++++++++++++++++++++++++++++++++++++<br clear=3D=
"none"></div><div dir=3D"ltr"> include/ssp/strings.h&nbsp; &nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; &nbsp; |&nbsp; 67 +++++++++++++++++++<br clear=3D"none">=
</div><div dir=3D"ltr"> include/ssp/unistd.h&nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp; &nbsp;  |&nbsp; 54 +++++++++++++++<br clear=3D"none"></div><div =
dir=3D"ltr"> lib/libc/secure/Makefile.inc&nbsp; &nbsp; &nbsp;  |&nbsp; 11 +=
+++<br clear=3D"none"></div><div dir=3D"ltr"> lib/libc/secure/Symbol.map&nb=
sp; &nbsp; &nbsp; &nbsp;  |&nbsp; 18 +++++<br clear=3D"none"></div><div dir=
=3D"ltr"> lib/libc/secure/fgets_chk.c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; 54=
 +++++++++++++++<br clear=3D"none"></div><div dir=3D"ltr"> lib/libc/secure/=
gets_chk.c&nbsp; &nbsp; &nbsp; &nbsp;  |&nbsp; 74 +++++++++++++++++++++<br =
clear=3D"none"></div><div dir=3D"ltr"> lib/libc/secure/memcpy_chk.c&nbsp; &=
nbsp; &nbsp;  |&nbsp; 53 +++++++++++++++<br clear=3D"none"></div><div dir=
=3D"ltr"> lib/libc/secure/memmove_chk.c&nbsp; &nbsp; &nbsp; |&nbsp; 47 ++++=
+++++++++<br clear=3D"none"></div><div dir=3D"ltr"> lib/libc/secure/memset_=
chk.c&nbsp; &nbsp; &nbsp;  |&nbsp; 46 +++++++++++++<br clear=3D"none"></div=
><div dir=3D"ltr"> lib/libc/secure/snprintf_chk.c&nbsp; &nbsp;  |&nbsp; 56 =
++++++++++++++++<br clear=3D"none"></div><div dir=3D"ltr"> lib/libc/secure/=
sprintf_chk.c&nbsp; &nbsp; &nbsp; |&nbsp; 61 +++++++++++++++++<br clear=3D"=
none"></div><div dir=3D"ltr"> lib/libc/secure/ssp_internal.h&nbsp; &nbsp;  =
|&nbsp; 37 +++++++++++<br clear=3D"none"></div><div dir=3D"ltr"> lib/libc/s=
ecure/stpcpy_chk.c&nbsp; &nbsp; &nbsp;  |&nbsp; 55 ++++++++++++++++<br clea=
r=3D"none"></div><div dir=3D"ltr"> lib/libc/secure/stpncpy_chk.c&nbsp; &nbs=
p; &nbsp; |&nbsp; 53 +++++++++++++++<br clear=3D"none"></div><div dir=3D"lt=
r"> lib/libc/secure/strcat_chk.c&nbsp; &nbsp; &nbsp;  |&nbsp; 60 ++++++++++=
+++++++<br clear=3D"none"></div><div dir=3D"ltr"> lib/libc/secure/strcpy_ch=
k.c&nbsp; &nbsp; &nbsp;  |&nbsp; 54 +++++++++++++++<br clear=3D"none"></div=
><div dir=3D"ltr"> lib/libc/secure/strncat_chk.c&nbsp; &nbsp; &nbsp; |&nbsp=
; 70 ++++++++++++++++++++<br clear=3D"none"></div><div dir=3D"ltr"> lib/lib=
c/secure/strncpy_chk.c&nbsp; &nbsp; &nbsp; |&nbsp; 53 +++++++++++++++<br cl=
ear=3D"none"></div><div dir=3D"ltr"> lib/libc/secure/vsnprintf_chk.c&nbsp; =
&nbsp; |&nbsp; 49 ++++++++++++++<br clear=3D"none"></div><div dir=3D"ltr"> =
lib/libc/secure/vsprintf_chk.c&nbsp; &nbsp;  |&nbsp; 58 ++++++++++++++++<br=
 clear=3D"none"></div><div dir=3D"ltr"> lib/libssp/Makefile&nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; 20 +++++-<br clear=3D"none"=
></div><div dir=3D"ltr"> lib/libssp/Symbol.map&nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; |&nbsp; 12 ++--<br clear=3D"none"></div><div dir=3D"ltr=
"> lib/libssp/Versions.def&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp;=
  5 ++<br clear=3D"none"></div><div dir=3D"ltr"> lib/libssp/__builtin_objec=
t_size.3 | 110 +++++++++++++++++++++++++++++++<br clear=3D"none"></div><div=
 dir=3D"ltr"> lib/libssp/fortify_stubs.c&nbsp; &nbsp; &nbsp; &nbsp;  | 131 =
-------------------------------------<br clear=3D"none"></div><div dir=3D"l=
tr"> lib/libssp/ssp.3&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp=
; &nbsp;  | 130 ++++++++++++++++++++++++++++++++++++<br clear=3D"none"></di=
v><div dir=3D"ltr"> 32 files changed, 1621 insertions(+), 140 deletions(-)<=
br clear=3D"none"></div><div dir=3D"ltr"><br clear=3D"none"></div><div dir=
=3D"ltr">diff --git a/etc/mtree/BSD.include.dist b/etc/mtree/BSD.include.di=
st<br clear=3D"none"></div><div dir=3D"ltr">index a6bd5880bf61..f8c83d6dde7=
a 100644<br clear=3D"none"></div><div dir=3D"ltr">--- a/etc/mtree/BSD.inclu=
de.dist<br clear=3D"none"></div><div dir=3D"ltr">+++ b/etc/mtree/BSD.includ=
e.dist<br clear=3D"none"></div><div dir=3D"ltr">@@ -372,6 +372,8 @@<br clea=
r=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp; &nbsp; &nbsp;  mac_veriexec=
<br clear=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp; &nbsp; &nbsp;  ..<b=
r clear=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp;  ..<br clear=3D"none"=
></div><div dir=3D"ltr">+&nbsp; &nbsp; ssp<br clear=3D"none"></div><div dir=
=3D"ltr">+&nbsp; &nbsp; ..<br clear=3D"none"></div><div dir=3D"ltr">&nbsp; =
&nbsp;  sys<br clear=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp; &nbsp; &=
nbsp;  disk<br clear=3D"none"></div><div dir=3D"ltr">&nbsp; &nbsp; &nbsp; &=
nbsp;  ..<br clear=3D"none"></div><div dir=3D"ltr">diff --git a/include/Mak=
efile b/include/Makefile<br clear=3D"none"></div><div dir=3D"ltr">index 19e=
6beb95203..32774419f162 100644<br clear=3D"none"></div><div dir=3D"ltr">---=
 a/include/Makefile<br clear=3D"none"></div><div dir=3D"ltr">+++ b/include/=
Makefile<br clear=3D"none"></div><div dir=3D"ltr">@@ -4,7 +4,7 @@<br clear=
=3D"none"></div><div dir=3D"ltr"> <br clear=3D"none"></div><div dir=3D"ltr"=
> PACKAGE=3Dclibs<br clear=3D"none"></div><div dir=3D"ltr"> CLEANFILES=3D o=
sreldate.h version<br clear=3D"none"></div><div dir=3D"ltr">-SUBDIR=3D arpa=
 protocols rpcsvc rpc xlocale<br clear=3D"none"></div><div dir=3D"ltr">+SUB=
DIR=3D arpa protocols rpcsvc rpc ssp xlocale<br clear=3D"none"></div><div d=
ir=3D"ltr"> .if ${MACHINE_CPUARCH} =3D=3D "amd64"<br clear=3D"none"></div><=
div dir=3D"ltr"> SUBDIR+=3D&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i386<br cl=
ear=3D"none"></div><div dir=3D"ltr"> INCLUDE_SUBDIRS+=3D&nbsp;&nbsp;&nbsp; =
i386<br clear=3D"none"></div><div dir=3D"ltr">diff --git a/include/ssp/Make=
file b/include/ssp/Makefile<br clear=3D"none"></div><div dir=3D"ltr">new fi=
le mode 100644<br clear=3D"none"></div><div dir=3D"ltr">index 000000000000.=
.dff19f43c920<br clear=3D"none"></div><div dir=3D"ltr">--- /dev/null<br cle=
ar=3D"none"></div><div dir=3D"ltr">+++ b/include/ssp/Makefile<br clear=3D"n=
one"></div><div dir=3D"ltr">@@ -0,0 +1,6 @@<br clear=3D"none"></div><div di=
r=3D"ltr">+# $FreeBSD$<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=
=3D"none"></div><div dir=3D"ltr">+INCS=3D&nbsp;&nbsp;&nbsp; ssp.h stdio.h s=
tring.h strings.h unistd.h<br clear=3D"none"></div><div dir=3D"ltr">+INCSDI=
R=3D&nbsp;&nbsp;&nbsp; ${INCLUDEDIR}/ssp<br clear=3D"none"></div><div dir=
=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+.include &lt;bsd.prog.=
mk&gt;<br clear=3D"none"></div><div dir=3D"ltr">diff --git a/include/ssp/ss=
p.h b/include/ssp/ssp.h<br clear=3D"none"></div><div dir=3D"ltr">new file m=
ode 100644<br clear=3D"none"></div><div dir=3D"ltr">index 000000000000..35a=
9aeee02df<br clear=3D"none"></div><div dir=3D"ltr">--- /dev/null<br clear=
=3D"none"></div><div dir=3D"ltr">+++ b/include/ssp/ssp.h<br clear=3D"none">=
</div><div dir=3D"ltr">@@ -0,0 +1,91 @@<br clear=3D"none"></div><div dir=3D=
"ltr">+/*&nbsp;&nbsp;&nbsp; $NetBSD: ssp.h,v 1.13 2015/09/03 20:43:47 plunk=
y Exp $&nbsp;&nbsp;&nbsp; */<br clear=3D"none"></div><div dir=3D"ltr">+<br =
clear=3D"none"></div><div dir=3D"ltr">+/*-<br clear=3D"none"></div><div dir=
=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * SPDX-License-Iden=
tifier: BSD-2-Clause<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=
=3D"none"></div><div dir=3D"ltr">+ * Copyright (c) 2006, 2011 The NetBSD Fo=
undation, Inc.<br clear=3D"none"></div><div dir=3D"ltr">+ * All rights rese=
rved.<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div>=
<div dir=3D"ltr">+ * This code is derived from software contributed to The =
NetBSD Foundation<br clear=3D"none"></div><div dir=3D"ltr">+ * by Christos =
Zoulas.<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></di=
v><div dir=3D"ltr">+ * Redistribution and use in source and binary forms, w=
ith or without<br clear=3D"none"></div><div dir=3D"ltr">+ * modification, a=
re permitted provided that the following conditions<br clear=3D"none"></div=
><div dir=3D"ltr">+ * are met:<br clear=3D"none"></div><div dir=3D"ltr">+ *=
 1. Redistributions of source code must retain the above copyright<br clear=
=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of cond=
itions and the following disclaimer.<br clear=3D"none"></div><div dir=3D"lt=
r">+ * 2. Redistributions in binary form must reproduce the above copyright=
<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this lis=
t of conditions and the following disclaimer in the<br clear=3D"none"></div=
><div dir=3D"ltr">+ *&nbsp; &nbsp; documentation and/or other materials pro=
vided with the distribution.<br clear=3D"none"></div><div dir=3D"ltr">+ *<b=
r clear=3D"none"></div><div dir=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY TH=
E NETBSD FOUNDATION, INC. AND CONTRIBUTORS<br clear=3D"none"></div><div dir=
=3D"ltr">+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BU=
T NOT LIMITED<br clear=3D"none"></div><div dir=3D"ltr">+ * TO, THE IMPLIED =
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR<br clear=3D"none=
"></div><div dir=3D"ltr">+ * PURPOSE ARE DISCLAIMED.&nbsp; IN NO EVENT SHAL=
L THE FOUNDATION OR CONTRIBUTORS<br clear=3D"none"></div><div dir=3D"ltr">+=
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<b=
r clear=3D"none"></div><div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDIN=
G, BUT NOT LIMITED TO, PROCUREMENT OF<br clear=3D"none"></div><div dir=3D"l=
tr">+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUS=
INESS<br clear=3D"none"></div><div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CA=
USED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br clear=3D"none"></div><di=
v dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE=
 OR OTHERWISE)<br clear=3D"none"></div><div dir=3D"ltr">+ * ARISING IN ANY =
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br clear=3D"non=
e"></div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br clear=3D"none"=
></div><div dir=3D"ltr">+ */<br clear=3D"none"></div><div dir=3D"ltr">+#ifn=
def _SSP_SSP_H_<br clear=3D"none"></div><div dir=3D"ltr">+#define _SSP_SSP_=
H_<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div =
dir=3D"ltr">+#include &lt;sys/cdefs.h&gt;<br clear=3D"none"></div><div dir=
=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#if !defined(__cpluspl=
us)<br clear=3D"none"></div><div dir=3D"ltr">+# if defined(_FORTIFY_SOURCE)=
 &amp;&amp; _FORTIFY_SOURCE &gt; 0 &amp;&amp; \<br clear=3D"none"></div><di=
v dir=3D"ltr">+&nbsp; &nbsp;  (__OPTIMIZE__ &gt; 0 || defined(__clang__))<b=
r clear=3D"none"></div><div dir=3D"ltr">+#&nbsp; if _FORTIFY_SOURCE &gt; 1<=
br clear=3D"none"></div><div dir=3D"ltr">+#&nbsp;  define __SSP_FORTIFY_LEV=
EL 2<br clear=3D"none"></div><div dir=3D"ltr">+#&nbsp; else<br clear=3D"non=
e"></div><div dir=3D"ltr">+#&nbsp;  define __SSP_FORTIFY_LEVEL 1<br clear=
=3D"none"></div><div dir=3D"ltr">+#&nbsp; endif<br clear=3D"none"></div><di=
v dir=3D"ltr">+# else<br clear=3D"none"></div><div dir=3D"ltr">+#&nbsp; def=
ine __SSP_FORTIFY_LEVEL 0<br clear=3D"none"></div><div dir=3D"ltr">+# endif=
<br clear=3D"none"></div><div dir=3D"ltr">+#else<br clear=3D"none"></div><d=
iv dir=3D"ltr">+# define __SSP_FORTIFY_LEVEL 0<br clear=3D"none"></div><div=
 dir=3D"ltr">+#endif<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D=
"none"></div><div dir=3D"ltr">+#define&nbsp;&nbsp;&nbsp; __ssp_var(type)&nb=
sp;&nbsp;&nbsp; __CONCAT(__ssp_ ## type, __COUNTER__)<br clear=3D"none"></d=
iv><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+/* __ssp_re=
al is used by the implementation in libc */<br clear=3D"none"></div><div di=
r=3D"ltr">+#if __SSP_FORTIFY_LEVEL =3D=3D 0<br clear=3D"none"></div><div di=
r=3D"ltr">+#define __ssp_real_(fun)&nbsp;&nbsp;&nbsp; fun<br clear=3D"none"=
></div><div dir=3D"ltr">+#else<br clear=3D"none"></div><div dir=3D"ltr">+#d=
efine __ssp_real_(fun)&nbsp;&nbsp;&nbsp; __ssp_real_ ## fun<br clear=3D"non=
e"></div><div dir=3D"ltr">+#endif<br clear=3D"none"></div><div dir=3D"ltr">=
+#define __ssp_real(fun)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __ssp_real_(f=
un)<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div=
 dir=3D"ltr">+#define __ssp_inline static __inline __attribute__((__always_=
inline__))<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></d=
iv><div dir=3D"ltr">+#define __ssp_bos(ptr) __builtin_object_size(ptr, __SS=
P_FORTIFY_LEVEL &gt; 1)<br clear=3D"none"></div><div dir=3D"ltr">+#define _=
_ssp_bos0(ptr) __builtin_object_size(ptr, 0)<br clear=3D"none"></div><div d=
ir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#define __ssp_check(=
buf, len, bos) \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbs=
p; if (bos(buf) !=3D (size_t)-1 &amp;&amp; len &gt; bos(buf)) \<br clear=3D=
"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __chk_=
fail()<br clear=3D"none"></div><div dir=3D"ltr">+#define __ssp_redirect_raw=
(rtype, fun, symbol, args, call, cond, bos) \<br clear=3D"none"></div><div =
dir=3D"ltr">+rtype __ssp_real_(fun) args __RENAME(symbol); \<br clear=3D"no=
ne"></div><div dir=3D"ltr">+__ssp_inline rtype fun args __RENAME(__ssp_prot=
ected_ ## fun); \<br clear=3D"none"></div><div dir=3D"ltr">+__ssp_inline rt=
ype fun args { \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbs=
p; if (cond) \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp; __ssp_check(__buf, __len, bos); \<br clear=3D"none"></d=
iv><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; return __ssp_real_(fun) call; \<br =
clear=3D"none"></div><div dir=3D"ltr">+}<br clear=3D"none"></div><div dir=
=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#define __ssp_redirect=
(rtype, fun, args, call) \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;=
 &nbsp; __ssp_redirect_raw(rtype, fun, fun, args, call, 1, __ssp_bos)<br cl=
ear=3D"none"></div><div dir=3D"ltr">+#define __ssp_redirect0(rtype, fun, ar=
gs, call) \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __ssp_r=
edirect_raw(rtype, fun, fun, args, call, 1, __ssp_bos0)<br clear=3D"none"><=
/div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+__BEGIN_D=
ECLS<br clear=3D"none"></div><div dir=3D"ltr">+void __stack_chk_fail(void) =
__dead2;<br clear=3D"none"></div><div dir=3D"ltr">+void __chk_fail(void) __=
dead2;<br clear=3D"none"></div><div dir=3D"ltr">+__END_DECLS<br clear=3D"no=
ne"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#end=
if /* _SSP_SSP_H_ */<br clear=3D"none"></div><div dir=3D"ltr">diff --git a/=
include/ssp/stdio.h b/include/ssp/stdio.h<br clear=3D"none"></div><div dir=
=3D"ltr">new file mode 100644<br clear=3D"none"></div><div dir=3D"ltr">inde=
x 000000000000..72e3236eac80<br clear=3D"none"></div><div dir=3D"ltr">--- /=
dev/null<br clear=3D"none"></div><div dir=3D"ltr">+++ b/include/ssp/stdio.h=
<br clear=3D"none"></div><div dir=3D"ltr">@@ -0,0 +1,93 @@<br clear=3D"none=
"></div><div dir=3D"ltr">+/*&nbsp;&nbsp;&nbsp; $NetBSD: stdio.h,v 1.5 2011/=
07/17 20:54:34 joerg Exp $&nbsp;&nbsp;&nbsp; */<br clear=3D"none"></div><di=
v dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+/*-<br clear=3D"n=
one"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ =
* SPDX-License-Identifier: BSD-2-Clause<br clear=3D"none"></div><div dir=3D=
"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * Copyright (c) 2006 T=
he NetBSD Foundation, Inc.<br clear=3D"none"></div><div dir=3D"ltr">+ * All=
 rights reserved.<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"=
none"></div><div dir=3D"ltr">+ * This code is derived from software contrib=
uted to The NetBSD Foundation<br clear=3D"none"></div><div dir=3D"ltr">+ * =
by Christos Zoulas.<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=
=3D"none"></div><div dir=3D"ltr">+ * Redistribution and use in source and b=
inary forms, with or without<br clear=3D"none"></div><div dir=3D"ltr">+ * m=
odification, are permitted provided that the following conditions<br clear=
=3D"none"></div><div dir=3D"ltr">+ * are met:<br clear=3D"none"></div><div =
dir=3D"ltr">+ * 1. Redistributions of source code must retain the above cop=
yright<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, th=
is list of conditions and the following disclaimer.<br clear=3D"none"></div=
><div dir=3D"ltr">+ * 2. Redistributions in binary form must reproduce the =
above copyright<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; n=
otice, this list of conditions and the following disclaimer in the<br clear=
=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; documentation and/or othe=
r materials provided with the distribution.<br clear=3D"none"></div><div di=
r=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * THIS SOFTWARE IS=
 PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS<br clear=3D"none"=
></div><div dir=3D"ltr">+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES=
, INCLUDING, BUT NOT LIMITED<br clear=3D"none"></div><div dir=3D"ltr">+ * T=
O, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR<b=
r clear=3D"none"></div><div dir=3D"ltr">+ * PURPOSE ARE DISCLAIMED.&nbsp; I=
N NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS<br clear=3D"none"></div><di=
v dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, =
EXEMPLARY, OR<br clear=3D"none"></div><div dir=3D"ltr">+ * CONSEQUENTIAL DA=
MAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br clear=3D"none"></di=
v><div dir=3D"ltr">+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR =
PROFITS; OR BUSINESS<br clear=3D"none"></div><div dir=3D"ltr">+ * INTERRUPT=
ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br clear=3D"=
none"></div><div dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLU=
DING NEGLIGENCE OR OTHERWISE)<br clear=3D"none"></div><div dir=3D"ltr">+ * =
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<=
br clear=3D"none"></div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br=
 clear=3D"none"></div><div dir=3D"ltr">+ */<br clear=3D"none"></div><div di=
r=3D"ltr">+#ifndef _SSP_STDIO_H_<br clear=3D"none"></div><div dir=3D"ltr">+=
#define _SSP_STDIO_H_<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=
=3D"none"></div><div dir=3D"ltr">+#include &lt;ssp/ssp.h&gt;<br clear=3D"no=
ne"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+__BE=
GIN_DECLS<br clear=3D"none"></div><div dir=3D"ltr">+int __sprintf_chk(char =
*__restrict, int, size_t, const char *__restrict, ...)<br clear=3D"none"></=
div><div dir=3D"ltr">+&nbsp; &nbsp; __printflike(4, 5);<br clear=3D"none"><=
/div><div dir=3D"ltr">+int __vsprintf_chk(char *__restrict, int, size_t, co=
nst char *__restrict,<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbs=
p; __va_list)<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __pri=
ntflike(4, 0);<br clear=3D"none"></div><div dir=3D"ltr">+int __snprintf_chk=
(char *__restrict, size_t, int, size_t,<br clear=3D"none"></div><div dir=3D=
"ltr">+&nbsp; &nbsp; const char *__restrict, ...)<br clear=3D"none"></div><=
div dir=3D"ltr">+&nbsp; &nbsp; __printflike(5, 6);<br clear=3D"none"></div>=
<div dir=3D"ltr">+int __vsnprintf_chk(char *__restrict, size_t, int, size_t=
,<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp;  const char *__re=
strict, __va_list)<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; =
__printflike(5, 0);<br clear=3D"none"></div><div dir=3D"ltr">+char *__gets_=
chk(char *, size_t);<br clear=3D"none"></div><div dir=3D"ltr">+char *__fget=
s_chk(char *, int, size_t, FILE *);<br clear=3D"none"></div><div dir=3D"ltr=
">+__END_DECLS<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"=
></div><div dir=3D"ltr">+#if __SSP_FORTIFY_LEVEL &gt; 0<br clear=3D"none"><=
/div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#define s=
printf(str, ...) ({&nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D=
"ltr">+&nbsp; &nbsp; char *_ssp_str =3D (str);&nbsp;&nbsp;&nbsp; \<br clear=
=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __builtin___sprintf_chk(_ss=
p_str, 0, __ssp_bos(_ssp_str),&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br cl=
ear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; __VA_ARGS_=
_); \<br clear=3D"none"></div><div dir=3D"ltr">+})<br clear=3D"none"></div>=
<div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#define vsprin=
tf(str, fmt, ap) ({&nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D=
"ltr">+&nbsp; &nbsp; char *_ssp_str =3D (str);&nbsp;&nbsp;&nbsp; &nbsp;&nbs=
p;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __builti=
n___vsprintf_chk(_ssp_str, 0, __ssp_bos(_ssp_str), fmt,&nbsp;&nbsp;&nbsp; \=
<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; ap);=
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=
 \<br clear=3D"none"></div><div dir=3D"ltr">+})<br clear=3D"none"></div><di=
v dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#define snprintf(=
str, len, ...) ({&nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"l=
tr">+&nbsp; &nbsp; char *_ssp_str =3D (str);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=
&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __builtin_=
__snprintf_chk(_ssp_str, len, 0, __ssp_bos(_ssp_str),&nbsp;&nbsp;&nbsp; \<b=
r clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; __VA_A=
RGS__);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=
=3D"none"></div><div dir=3D"ltr">+})<br clear=3D"none"></div><div dir=3D"lt=
r">+<br clear=3D"none"></div><div dir=3D"ltr">+#define vsnprintf(str, len, =
fmt, ap) ({&nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&=
nbsp; &nbsp; char *_ssp_str =3D (str);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=
 \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __builtin___vsnp=
rintf_chk(_ssp_str, len, 0, __ssp_bos(_ssp_str),&nbsp;&nbsp;&nbsp; \<br cle=
ar=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; fmt, ap);&n=
bsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"none">=
</div><div dir=3D"ltr">+})<br clear=3D"none"></div><div dir=3D"ltr">+<br cl=
ear=3D"none"></div><div dir=3D"ltr">+#define gets(str) ({&nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=
=3D"ltr">+&nbsp;  char *_ssp_str =3D (str);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&=
nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __gets_chk(=
_ssp_str, __ssp_bos(_ssp_str));&nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div=
><div dir=3D"ltr">+})<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=
=3D"none"></div><div dir=3D"ltr">+#define fgets(str, len, fp) ({&nbsp;&nbsp=
;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbs=
p; &nbsp; char *_ssp_str =3D (str);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<=
br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __fgets_chk(_ssp_st=
r, len, __ssp_bos(_ssp_str), fp);&nbsp;&nbsp;&nbsp; \<br clear=3D"none"></d=
iv><div dir=3D"ltr">+})<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=
=3D"none"></div><div dir=3D"ltr">+#endif /* __SSP_FORTIFY_LEVEL &gt; 0 */<b=
r clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=
=3D"ltr">+#endif /* _SSP_STDIO_H_ */<br clear=3D"none"></div><div dir=3D"lt=
r">diff --git a/include/ssp/string.h b/include/ssp/string.h<br clear=3D"non=
e"></div><div dir=3D"ltr">new file mode 100644<br clear=3D"none"></div><div=
 dir=3D"ltr">index 000000000000..996020fda778<br clear=3D"none"></div><div =
dir=3D"ltr">--- /dev/null<br clear=3D"none"></div><div dir=3D"ltr">+++ b/in=
clude/ssp/string.h<br clear=3D"none"></div><div dir=3D"ltr">@@ -0,0 +1,129 =
@@<br clear=3D"none"></div><div dir=3D"ltr">+/*&nbsp;&nbsp;&nbsp; $NetBSD: =
string.h,v 1.14 2020/09/05 13:37:59 mrg Exp $&nbsp;&nbsp;&nbsp; */<br clear=
=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr"=
>+/*-<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div>=
<div dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br clear=3D"none=
"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * C=
opyright (c) 2006 The NetBSD Foundation, Inc.<br clear=3D"none"></div><div =
dir=3D"ltr">+ * All rights reserved.<br clear=3D"none"></div><div dir=3D"lt=
r">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * This code is derived fr=
om software contributed to The NetBSD Foundation<br clear=3D"none"></div><d=
iv dir=3D"ltr">+ * by Christos Zoulas.<br clear=3D"none"></div><div dir=3D"=
ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * Redistribution and us=
e in source and binary forms, with or without<br clear=3D"none"></div><div =
dir=3D"ltr">+ * modification, are permitted provided that the following con=
ditions<br clear=3D"none"></div><div dir=3D"ltr">+ * are met:<br clear=3D"n=
one"></div><div dir=3D"ltr">+ * 1. Redistributions of source code must reta=
in the above copyright<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &=
nbsp; notice, this list of conditions and the following disclaimer.<br clea=
r=3D"none"></div><div dir=3D"ltr">+ * 2. Redistributions in binary form mus=
t reproduce the above copyright<br clear=3D"none"></div><div dir=3D"ltr">+ =
*&nbsp; &nbsp; notice, this list of conditions and the following disclaimer=
 in the<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; documenta=
tion and/or other materials provided with the distribution.<br clear=3D"non=
e"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * =
THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS<b=
r clear=3D"none"></div><div dir=3D"ltr">+ * ``AS IS'' AND ANY EXPRESS OR IM=
PLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<br clear=3D"none"></div><div d=
ir=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FO=
R A PARTICULAR<br clear=3D"none"></div><div dir=3D"ltr">+ * PURPOSE ARE DIS=
CLAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS<br clear=3D=
"none"></div><div dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCID=
ENTAL, SPECIAL, EXEMPLARY, OR<br clear=3D"none"></div><div dir=3D"ltr">+ * =
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br cle=
ar=3D"none"></div><div dir=3D"ltr">+ * SUBSTITUTE GOODS OR SERVICES; LOSS O=
F USE, DATA, OR PROFITS; OR BUSINESS<br clear=3D"none"></div><div dir=3D"lt=
r">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER=
 IN<br clear=3D"none"></div><div dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY=
, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br clear=3D"none"></div><div =
dir=3D"ltr">+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
 ADVISED OF THE<br clear=3D"none"></div><div dir=3D"ltr">+ * POSSIBILITY OF=
 SUCH DAMAGE.<br clear=3D"none"></div><div dir=3D"ltr">+ */<br clear=3D"non=
e"></div><div dir=3D"ltr">+#ifndef _SSP_STRING_H_<br clear=3D"none"></div><=
div dir=3D"ltr">+#define _SSP_STRING_H_<br clear=3D"none"></div><div dir=3D=
"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#include &lt;ssp/ssp.h&gt=
;<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div d=
ir=3D"ltr">+__BEGIN_DECLS<br clear=3D"none"></div><div dir=3D"ltr">+void *_=
_memcpy_chk(void *, const void *, size_t, size_t);<br clear=3D"none"></div>=
<div dir=3D"ltr">+void *__memmove_chk(void *, const void *, size_t, size_t)=
;<br clear=3D"none"></div><div dir=3D"ltr">+void *__memset_chk(void *, int,=
 size_t, size_t);<br clear=3D"none"></div><div dir=3D"ltr">+char *__stpcpy_=
chk(char *, const char *, size_t);<br clear=3D"none"></div><div dir=3D"ltr"=
>+char *__stpncpy_chk(char *, const char *, size_t, size_t);<br clear=3D"no=
ne"></div><div dir=3D"ltr">+char *__strcat_chk(char *, const char *, size_t=
);<br clear=3D"none"></div><div dir=3D"ltr">+char *__strcpy_chk(char *, con=
st char *, size_t);<br clear=3D"none"></div><div dir=3D"ltr">+char *__strnc=
at_chk(char *, const char *, size_t, size_t);<br clear=3D"none"></div><div =
dir=3D"ltr">+char *__strncpy_chk(char *, const char *, size_t, size_t);<br =
clear=3D"none"></div><div dir=3D"ltr">+__END_DECLS<br clear=3D"none"></div>=
<div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#if __SSP_FORT=
IFY_LEVEL &gt; 0<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"non=
e"></div><div dir=3D"ltr">+#define __ssp_bos_check3_typed_var(fun, dsttype,=
 dsrvar, dst, srctype, srcvar, \<br clear=3D"none"></div><div dir=3D"ltr">+=
&nbsp; &nbsp; src, lenvar, len) ({&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nb=
sp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"lt=
r">+&nbsp; &nbsp; srctype srcvar =3D (src);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&=
nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div =
dir=3D"ltr">+&nbsp; &nbsp; dsttype dstvar =3D (dst);&nbsp;&nbsp;&nbsp; &nbs=
p;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"none"></=
div><div dir=3D"ltr">+&nbsp; &nbsp; size_t lenvar =3D (len);&nbsp;&nbsp;&nb=
sp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"=
none"></div><div dir=3D"ltr">+&nbsp; &nbsp; ((__ssp_bos0(dstvar) !=3D (size=
_t)-1) ?&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><di=
v dir=3D"ltr">+&nbsp; &nbsp; __builtin___ ## fun ## _chk(dstvar, srcvar, le=
nvar,&nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; =
&nbsp; &nbsp; &nbsp; __ssp_bos0(dstvar)) :&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&n=
bsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div d=
ir=3D"ltr">+&nbsp; &nbsp; __ ## fun ## _ichk(dstvar, srcvar, lenvar));&nbsp=
;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+})<br clear=3D"no=
ne"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#def=
ine __ssp_bos_check3_typed(fun, dsttype, dst, srctype, src, len)&nbsp;&nbsp=
;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __ssp_bos=
_check3_typed_var(fun, dsttype, __ssp_var(dstv), dst,&nbsp;&nbsp;&nbsp; \<b=
r clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; srctyp=
e, __ssp_var(srcv), src, __ssp_var(lenv), len)<br clear=3D"none"></div><div=
 dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#define __ssp_bos_=
check3(fun, dst, src, len)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=
=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __ssp_bos_check3_typed_var(=
fun, void *, __ssp_var(dstv), dst,&nbsp;&nbsp;&nbsp; \<br clear=3D"none"></=
div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; const void *, __ssp_var(s=
rcv), src, __ssp_var(lenv), len)<br clear=3D"none"></div><div dir=3D"ltr">+=
<br clear=3D"none"></div><div dir=3D"ltr">+#define __ssp_bos_check2_var(fun=
, dstvar, dst, srcvar, src) ({&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br cl=
ear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; const void *srcvar =3D (=
src);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&=
nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; void *dstva=
r =3D (dst);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;=
&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; ((__=
ssp_bos0(dstvar) !=3D (size_t)-1) ?&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<=
br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __builtin___ ## fun=
 ## _chk(dstvar, srcvar,&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D=
"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; __ssp_bos0(dstva=
r)) :&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&=
nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __ ## fun #=
# _ichk(dstvar, srcvar));&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=
=3D"none"></div><div dir=3D"ltr">+})<br clear=3D"none"></div><div dir=3D"lt=
r">+<br clear=3D"none"></div><div dir=3D"ltr">+#define __ssp_bos_check2(fun=
, dst, src)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br cl=
ear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __ssp_bos_check2_var(fun=
, __ssp_var(dstv), dst, __ssp_var(srcv), src)<br clear=3D"none"></div><div =
dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#define __ssp_bos_i=
check3_restrict(fun, type1, type2) \<br clear=3D"none"></div><div dir=3D"lt=
r">+static __inline type1 __ ## fun ## _ichk(type1 __restrict, type2 __rest=
rict, size_t); \<br clear=3D"none"></div><div dir=3D"ltr">+static __inline =
__attribute__((__always_inline__)) type1 \<br clear=3D"none"></div><div dir=
=3D"ltr">+__ ## fun ## _ichk(type1 __restrict dst, type2 __restrict src, si=
ze_t len) { \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; =
return __builtin___ ## fun ## _chk(dst, src, len, __ssp_bos0(dst)); \<br cl=
ear=3D"none"></div><div dir=3D"ltr">+}<br clear=3D"none"></div><div dir=3D"=
ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#define __ssp_bos_icheck3(=
fun, type1, type2) \<br clear=3D"none"></div><div dir=3D"ltr">+static __inl=
ine type1 __ ## fun ## _ichk(type1, type2, size_t); \<br clear=3D"none"></d=
iv><div dir=3D"ltr">+static __inline __attribute__((__always_inline__)) typ=
e1 \<br clear=3D"none"></div><div dir=3D"ltr">+__ ## fun ## _ichk(type1 dst=
, type2 src, size_t len) { \<br clear=3D"none"></div><div dir=3D"ltr">+&nbs=
p;&nbsp;&nbsp; return __builtin___ ## fun ## _chk(dst, src, len, __ssp_bos0=
(dst)); \<br clear=3D"none"></div><div dir=3D"ltr">+}<br clear=3D"none"></d=
iv><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#define __s=
sp_bos_icheck2_restrict(fun, type1, type2) \<br clear=3D"none"></div><div d=
ir=3D"ltr">+static __inline type1 __ ## fun ## _ichk(type1, type2); \<br cl=
ear=3D"none"></div><div dir=3D"ltr">+static __inline __attribute__((__alway=
s_inline__)) type1 \<br clear=3D"none"></div><div dir=3D"ltr">+__ ## fun ##=
 _ichk(type1 __restrict dst, type2 __restrict src) { \<br clear=3D"none"></=
div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; return __builtin___ ## fun ## _chk=
(dst, src, __ssp_bos0(dst)); \<br clear=3D"none"></div><div dir=3D"ltr">+}<=
br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=
=3D"ltr">+__BEGIN_DECLS<br clear=3D"none"></div><div dir=3D"ltr">+__ssp_bos=
_icheck3_restrict(memcpy, void *, const void *)<br clear=3D"none"></div><di=
v dir=3D"ltr">+__ssp_bos_icheck3(memmove, void *, const void *)<br clear=3D=
"none"></div><div dir=3D"ltr">+__ssp_bos_icheck3(memset, void *, int)<br cl=
ear=3D"none"></div><div dir=3D"ltr">+__ssp_bos_icheck2_restrict(stpcpy, cha=
r *, const char *)<br clear=3D"none"></div><div dir=3D"ltr">+__ssp_bos_iche=
ck3_restrict(stpncpy, char *, const char *)<br clear=3D"none"></div><div di=
r=3D"ltr">+__ssp_bos_icheck2_restrict(strcpy, char *, const char *)<br clea=
r=3D"none"></div><div dir=3D"ltr">+__ssp_bos_icheck2_restrict(strcat, char =
*, const char *)<br clear=3D"none"></div><div dir=3D"ltr">+__ssp_bos_icheck=
3_restrict(strncpy, char *, const char *)<br clear=3D"none"></div><div dir=
=3D"ltr">+__ssp_bos_icheck3_restrict(strncat, char *, const char *)<br clea=
r=3D"none"></div><div dir=3D"ltr">+__END_DECLS<br clear=3D"none"></div><div=
 dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#define memcpy(dst=
, src, len) __ssp_bos_check3(memcpy, dst, src, len)<br clear=3D"none"></div=
><div dir=3D"ltr">+#define memmove(dst, src, len) __ssp_bos_check3(memmove,=
 dst, src, len)<br clear=3D"none"></div><div dir=3D"ltr">+#define memset(ds=
t, val, len) \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __ss=
p_bos_check3_typed(memset, void *, dst, int, val, len)<br clear=3D"none"></=
div><div dir=3D"ltr">+#define stpcpy(dst, src) __ssp_bos_check2(stpcpy, dst=
, src)<br clear=3D"none"></div><div dir=3D"ltr">+#define stpncpy(dst, src, =
len) __ssp_bos_check3(stpncpy, dst, src, len)<br clear=3D"none"></div><div =
dir=3D"ltr">+#define strcpy(dst, src) __ssp_bos_check2(strcpy, dst, src)<br=
 clear=3D"none"></div><div dir=3D"ltr">+#define strcat(dst, src) __ssp_bos_=
check2(strcat, dst, src)<br clear=3D"none"></div><div dir=3D"ltr">+#define =
strncpy(dst, src, len) __ssp_bos_check3(strncpy, dst, src, len)<br clear=3D=
"none"></div><div dir=3D"ltr">+#define strncat(dst, src, len) __ssp_bos_che=
ck3(strncat, dst, src, len)<br clear=3D"none"></div><div dir=3D"ltr">+<br c=
lear=3D"none"></div><div dir=3D"ltr">+#endif /* __SSP_FORTIFY_LEVEL &gt; 0 =
*/<br clear=3D"none"></div><div dir=3D"ltr">+#endif /* _SSP_STRING_H_ */<br=
 clear=3D"none"></div><div dir=3D"ltr">diff --git a/include/ssp/strings.h b=
/include/ssp/strings.h<br clear=3D"none"></div><div dir=3D"ltr">new file mo=
de 100644<br clear=3D"none"></div><div dir=3D"ltr">index 000000000000..06c9=
c7cc0a09<br clear=3D"none"></div><div dir=3D"ltr">--- /dev/null<br clear=3D=
"none"></div><div dir=3D"ltr">+++ b/include/ssp/strings.h<br clear=3D"none"=
></div><div dir=3D"ltr">@@ -0,0 +1,67 @@<br clear=3D"none"></div><div dir=
=3D"ltr">+/*&nbsp;&nbsp;&nbsp; $NetBSD: strings.h,v 1.3 2008/04/28 20:22:54=
 martin Exp $&nbsp;&nbsp;&nbsp; */<br clear=3D"none"></div><div dir=3D"ltr"=
>+<br clear=3D"none"></div><div dir=3D"ltr">+/*-<br clear=3D"none"></div><d=
iv dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * SPDX-Licens=
e-Identifier: BSD-2-Clause<br clear=3D"none"></div><div dir=3D"ltr">+ *<br =
clear=3D"none"></div><div dir=3D"ltr">+ * Copyright (c) 2007 The NetBSD Fou=
ndation, Inc.<br clear=3D"none"></div><div dir=3D"ltr">+ * All rights reser=
ved.<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><=
div dir=3D"ltr">+ * This code is derived from software contributed to The N=
etBSD Foundation<br clear=3D"none"></div><div dir=3D"ltr">+ * by Christos Z=
oulas.<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div=
><div dir=3D"ltr">+ * Redistribution and use in source and binary forms, wi=
th or without<br clear=3D"none"></div><div dir=3D"ltr">+ * modification, ar=
e permitted provided that the following conditions<br clear=3D"none"></div>=
<div dir=3D"ltr">+ * are met:<br clear=3D"none"></div><div dir=3D"ltr">+ * =
1. Redistributions of source code must retain the above copyright<br clear=
=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of cond=
itions and the following disclaimer.<br clear=3D"none"></div><div dir=3D"lt=
r">+ * 2. Redistributions in binary form must reproduce the above copyright=
<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this lis=
t of conditions and the following disclaimer in the<br clear=3D"none"></div=
><div dir=3D"ltr">+ *&nbsp; &nbsp; documentation and/or other materials pro=
vided with the distribution.<br clear=3D"none"></div><div dir=3D"ltr">+ *<b=
r clear=3D"none"></div><div dir=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY TH=
E NETBSD FOUNDATION, INC. AND CONTRIBUTORS<br clear=3D"none"></div><div dir=
=3D"ltr">+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BU=
T NOT LIMITED<br clear=3D"none"></div><div dir=3D"ltr">+ * TO, THE IMPLIED =
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR<br clear=3D"none=
"></div><div dir=3D"ltr">+ * PURPOSE ARE DISCLAIMED.&nbsp; IN NO EVENT SHAL=
L THE FOUNDATION OR CONTRIBUTORS<br clear=3D"none"></div><div dir=3D"ltr">+=
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<b=
r clear=3D"none"></div><div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDIN=
G, BUT NOT LIMITED TO, PROCUREMENT OF<br clear=3D"none"></div><div dir=3D"l=
tr">+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUS=
INESS<br clear=3D"none"></div><div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CA=
USED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br clear=3D"none"></div><di=
v dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE=
 OR OTHERWISE)<br clear=3D"none"></div><div dir=3D"ltr">+ * ARISING IN ANY =
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br clear=3D"non=
e"></div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br clear=3D"none"=
></div><div dir=3D"ltr">+ */<br clear=3D"none"></div><div dir=3D"ltr">+#ifn=
def _SSP_STRINGS_H_<br clear=3D"none"></div><div dir=3D"ltr">+#define _SSP_=
STRINGS_H_<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></d=
iv><div dir=3D"ltr">+#include &lt;ssp/ssp.h&gt;<br clear=3D"none"></div><di=
v dir=3D"ltr">+#include &lt;string.h&gt;<br clear=3D"none"></div><div dir=
=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#if __SSP_FORTIFY_LEVE=
L &gt; 0<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div=
><div dir=3D"ltr">+#define _ssp_bcopy(srcvar, src, dstvar, dst, lenvar,&nbs=
p; len) ({&nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&n=
bsp; &nbsp; const void *srcvar =3D (src);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nb=
sp; &nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &=
nbsp; void *dstvar =3D (dst);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&n=
bsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; size_t=
 lenvar =3D (len);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
\<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; ((__ssp_bos0(dstv=
ar) !=3D (size_t)-1) ?&nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=
=3D"ltr">+&nbsp; &nbsp; __builtin___memmove_chk(dstvar, srcvar, lenvar,&nbs=
p;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; &n=
bsp; &nbsp; __ssp_bos0(dstvar)) :&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbs=
p;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __=
memmove_ichk(dstvar, srcvar, lenvar));&nbsp;&nbsp;&nbsp; \<br clear=3D"none=
"></div><div dir=3D"ltr">+})<br clear=3D"none"></div><div dir=3D"ltr">+<br =
clear=3D"none"></div><div dir=3D"ltr">+#define&nbsp;&nbsp;&nbsp; bcopy(src,=
 dst, len)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br cle=
ar=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; _ssp_bcopy(__ssp_var(srcv=
), src, __ssp_var(dstv), dst, __ssp_var(lenv), len)<br clear=3D"none"></div=
><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#define _ssp_=
bzero(dstvar, dst, lenvar, len) ({&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<b=
r clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; void *dstvar =3D (ds=
t);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"n=
one"></div><div dir=3D"ltr">+&nbsp; &nbsp; size_t lenvar =3D (len);&nbsp;&n=
bsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"none"></div>=
<div dir=3D"ltr">+&nbsp; &nbsp; ((__ssp_bos0(dstvar) !=3D (size_t)-1) ?&nbs=
p;&nbsp;&nbsp; \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __=
builtin___memset_chk(dstvar, 0, lenvar,&nbsp;&nbsp;&nbsp; \<br clear=3D"non=
e"></div><div dir=3D"ltr">+&nbsp; &nbsp; &nbsp; &nbsp; __ssp_bos0(dstvar)) =
: \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; __memset_ichk(d=
stvar, 0, lenvar));&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \<br clear=3D"none=
"></div><div dir=3D"ltr">+})<br clear=3D"none"></div><div dir=3D"ltr">+<br =
clear=3D"none"></div><div dir=3D"ltr">+#define&nbsp;&nbsp;&nbsp; bzero(dst,=
 len)&nbsp;&nbsp;&nbsp; _ssp_bzero(__ssp_var(dstv), dst, __ssp_var(lenv), l=
en)<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div=
 dir=3D"ltr">+#endif /* __SSP_FORTIFY_LEVEL &gt; 0 */<br clear=3D"none"></d=
iv><div dir=3D"ltr">+#endif /* _SSP_STRINGS_H_ */<br clear=3D"none"></div><=
div dir=3D"ltr">diff --git a/include/ssp/unistd.h b/include/ssp/unistd.h<br=
 clear=3D"none"></div><div dir=3D"ltr">new file mode 100644<br clear=3D"non=
e"></div><div dir=3D"ltr">index 000000000000..2414e2baa96b<br clear=3D"none=
"></div><div dir=3D"ltr">--- /dev/null<br clear=3D"none"></div><div dir=3D"=
ltr">+++ b/include/ssp/unistd.h<br clear=3D"none"></div><div dir=3D"ltr">@@=
 -0,0 +1,54 @@<br clear=3D"none"></div><div dir=3D"ltr">+/*&nbsp;&nbsp;&nbs=
p; $NetBSD: unistd.h,v 1.7 2015/06/25 18:41:03 joerg Exp $&nbsp;&nbsp;&nbsp=
; */<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><di=
v dir=3D"ltr">+/*-<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D=
"none"></div><div dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br =
clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=
=3D"ltr">+ * Copyright (c) 2006 The NetBSD Foundation, Inc.<br clear=3D"non=
e"></div><div dir=3D"ltr">+ * All rights reserved.<br clear=3D"none"></div>=
<div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * This code=
 is derived from software contributed to The NetBSD Foundation<br clear=3D"=
none"></div><div dir=3D"ltr">+ * by Christos Zoulas.<br clear=3D"none"></di=
v><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * Redistr=
ibution and use in source and binary forms, with or without<br clear=3D"non=
e"></div><div dir=3D"ltr">+ * modification, are permitted provided that the=
 following conditions<br clear=3D"none"></div><div dir=3D"ltr">+ * are met:=
<br clear=3D"none"></div><div dir=3D"ltr">+ * 1. Redistributions of source =
code must retain the above copyright<br clear=3D"none"></div><div dir=3D"lt=
r">+ *&nbsp; &nbsp; notice, this list of conditions and the following discl=
aimer.<br clear=3D"none"></div><div dir=3D"ltr">+ * 2. Redistributions in b=
inary form must reproduce the above copyright<br clear=3D"none"></div><div =
dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditions and the follow=
ing disclaimer in the<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &n=
bsp; documentation and/or other materials provided with the distribution.<b=
r clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div di=
r=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND =
CONTRIBUTORS<br clear=3D"none"></div><div dir=3D"ltr">+ * ``AS IS'' AND ANY=
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<br clear=3D"none=
"></div><div dir=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY =
AND FITNESS FOR A PARTICULAR<br clear=3D"none"></div><div dir=3D"ltr">+ * P=
URPOSE ARE DISCLAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTO=
RS<br clear=3D"none"></div><div dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, I=
NDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br clear=3D"none"></div><div di=
r=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCURE=
MENT OF<br clear=3D"none"></div><div dir=3D"ltr">+ * SUBSTITUTE GOODS OR SE=
RVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br clear=3D"none"></div>=
<div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIAB=
ILITY, WHETHER IN<br clear=3D"none"></div><div dir=3D"ltr">+ * CONTRACT, ST=
RICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br clear=3D"non=
e"></div><div dir=3D"ltr">+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOF=
TWARE, EVEN IF ADVISED OF THE<br clear=3D"none"></div><div dir=3D"ltr">+ * =
POSSIBILITY OF SUCH DAMAGE.<br clear=3D"none"></div><div dir=3D"ltr">+ */<b=
r clear=3D"none"></div><div dir=3D"ltr">+#ifndef _SSP_UNISTD_H_<br clear=3D=
"none"></div><div dir=3D"ltr">+#define _SSP_UNISTD_H_<br clear=3D"none"></d=
iv><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#include &l=
t;ssp/ssp.h&gt;<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none=
"></div><div dir=3D"ltr">+#if __SSP_FORTIFY_LEVEL &gt; 0<br clear=3D"none">=
</div><div dir=3D"ltr">+__BEGIN_DECLS<br clear=3D"none"></div><div dir=3D"l=
tr">+<br clear=3D"none"></div><div dir=3D"ltr">+__ssp_redirect0(ssize_t, re=
ad, (int __fd, void *__buf, size_t __len), \<br clear=3D"none"></div><div d=
ir=3D"ltr">+&nbsp; &nbsp; (__fd, __buf, __len));<br clear=3D"none"></div><d=
iv dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+__ssp_redirect(s=
size_t, readlink, (const char *__restrict __path, \<br clear=3D"none"></div=
><div dir=3D"ltr">+&nbsp; &nbsp; char *__restrict __buf, size_t __len), (__=
path, __buf, __len));<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=
=3D"none"></div><div dir=3D"ltr">+__ssp_redirect_raw(char *, getcwd, getcwd=
, (char *__buf, size_t __len),<br clear=3D"none"></div><div dir=3D"ltr">+&n=
bsp; &nbsp; (__buf, __len), __buf !=3D 0, __ssp_bos);<br clear=3D"none"></d=
iv><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+__END_DECLS=
<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div di=
r=3D"ltr">+#endif /* __SSP_FORTIFY_LEVEL &gt; 0 */<br clear=3D"none"></div>=
<div dir=3D"ltr">+#endif /* _SSP_UNISTD_H_ */<br clear=3D"none"></div><div =
dir=3D"ltr">diff --git a/lib/libc/secure/Makefile.inc b/lib/libc/secure/Mak=
efile.inc<br clear=3D"none"></div><div dir=3D"ltr">index 8574c5a05dc5..3b1a=
d879c715 100644<br clear=3D"none"></div><div dir=3D"ltr">--- a/lib/libc/sec=
ure/Makefile.inc<br clear=3D"none"></div><div dir=3D"ltr">+++ b/lib/libc/se=
cure/Makefile.inc<br clear=3D"none"></div><div dir=3D"ltr">@@ -3,6 +3,17 @@=
<br clear=3D"none"></div><div dir=3D"ltr"> <br clear=3D"none"></div><div di=
r=3D"ltr"> .PATH: ${LIBC_SRCTOP}/secure<br clear=3D"none"></div><div dir=3D=
"ltr"> <br clear=3D"none"></div><div dir=3D"ltr">+# _FORTIFY_SOURCE<br clea=
r=3D"none"></div><div dir=3D"ltr">+SRCS+=3D&nbsp;&nbsp;&nbsp; gets_chk.c fg=
ets_chk.c memcpy_chk.c memmove_chk.c memset_chk.c \<br clear=3D"none"></div=
><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; snprintf_chk.c sprintf_chk.c stpcpy_c=
hk.c stpncpy_chk.c \<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;=
&nbsp; strcat_chk.c strcpy_chk.c strncat_chk.c strncpy_chk.c \<br clear=3D"=
none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; vsnprintf_chk.c vsprintf_c=
hk.c<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><di=
v dir=3D"ltr">+CFLAGS.snprintf_chk.c+=3D&nbsp;&nbsp;&nbsp; -Wno-unused-para=
meter<br clear=3D"none"></div><div dir=3D"ltr">+CFLAGS.sprintf_chk.c+=3D&nb=
sp;&nbsp;&nbsp; -Wno-unused-parameter<br clear=3D"none"></div><div dir=3D"l=
tr">+CFLAGS.vsnprintf_chk.c+=3D&nbsp;&nbsp;&nbsp; -Wno-unused-parameter<br =
clear=3D"none"></div><div dir=3D"ltr">+CFLAGS.vsprintf_chk.c+=3D&nbsp;&nbsp=
;&nbsp; -Wno-unused-parameter<br clear=3D"none"></div><div dir=3D"ltr">+<br=
 clear=3D"none"></div><div dir=3D"ltr"> # Sources common to both syscall in=
terfaces:<br clear=3D"none"></div><div dir=3D"ltr"> SRCS+=3D&nbsp;&nbsp;&nb=
sp; stack_protector.c \<br clear=3D"none"></div><div dir=3D"ltr"> &nbsp;&nb=
sp;&nbsp; stack_protector_compat.c<br clear=3D"none"></div><div dir=3D"ltr"=
>diff --git a/lib/libc/secure/Symbol.map b/lib/libc/secure/Symbol.map<br cl=
ear=3D"none"></div><div dir=3D"ltr">index 641f451b5421..7859fcee3821 100644=
<br clear=3D"none"></div><div dir=3D"ltr">--- a/lib/libc/secure/Symbol.map<=
br clear=3D"none"></div><div dir=3D"ltr">+++ b/lib/libc/secure/Symbol.map<b=
r clear=3D"none"></div><div dir=3D"ltr">@@ -3,3 +3,21 @@ FBSD_1.0 {<br clea=
r=3D"none"></div><div dir=3D"ltr"> &nbsp;&nbsp;&nbsp; __stack_chk_fail;<br =
clear=3D"none"></div><div dir=3D"ltr"> &nbsp;&nbsp;&nbsp; __stack_chk_guard=
;<br clear=3D"none"></div><div dir=3D"ltr"> };<br clear=3D"none"></div><div=
 dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+FBSD_1.8 {<br clea=
r=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __gets_chk;<br clear=
=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __fgets_chk;<br clear=
=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __memcpy_chk;<br clear=
=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __memmove_chk;<br clea=
r=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __memset_chk;<br clea=
r=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __snprintf_chk;<br cl=
ear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __sprintf_chk;<br c=
lear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __stpcpy_chk;<br c=
lear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __stpncpy_chk;<br =
clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __strcat_chk;<br =
clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __strcpy_chk;<br =
clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __strncat_chk;<br=
 clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __strncpy_chk;<b=
r clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __vsnprintf_chk=
;<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; __vsprintf_c=
hk;<br clear=3D"none"></div><div dir=3D"ltr">+};<br clear=3D"none"></div><d=
iv dir=3D"ltr">diff --git a/lib/libc/secure/fgets_chk.c b/lib/libc/secure/f=
gets_chk.c<br clear=3D"none"></div><div dir=3D"ltr">new file mode 100644<br=
 clear=3D"none"></div><div dir=3D"ltr">index 000000000000..72aa1d816ce1<br =
clear=3D"none"></div><div dir=3D"ltr">--- /dev/null<br clear=3D"none"></div=
><div dir=3D"ltr">+++ b/lib/libc/secure/fgets_chk.c<br clear=3D"none"></div=
><div dir=3D"ltr">@@ -0,0 +1,54 @@<br clear=3D"none"></div><div dir=3D"ltr"=
>+/*-<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div>=
<div dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br clear=3D"none=
"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * C=
opyright (c) 2006 The NetBSD Foundation, Inc.<br clear=3D"none"></div><div =
dir=3D"ltr">+ * All rights reserved.<br clear=3D"none"></div><div dir=3D"lt=
r">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * This code is derived fr=
om software contributed to The NetBSD Foundation<br clear=3D"none"></div><d=
iv dir=3D"ltr">+ * by Christos Zoulas.<br clear=3D"none"></div><div dir=3D"=
ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * Redistribution and us=
e in source and binary forms, with or without<br clear=3D"none"></div><div =
dir=3D"ltr">+ * modification, are permitted provided that the following con=
ditions<br clear=3D"none"></div><div dir=3D"ltr">+ * are met:<br clear=3D"n=
one"></div><div dir=3D"ltr">+ * 1. Redistributions of source code must reta=
in the above copyright<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &=
nbsp; notice, this list of conditions and the following disclaimer.<br clea=
r=3D"none"></div><div dir=3D"ltr">+ * 2. Redistributions in binary form mus=
t reproduce the above copyright<br clear=3D"none"></div><div dir=3D"ltr">+ =
*&nbsp; &nbsp; notice, this list of conditions and the following disclaimer=
 in the<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; documenta=
tion and/or other materials provided with the distribution.<br clear=3D"non=
e"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * =
THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS<b=
r clear=3D"none"></div><div dir=3D"ltr">+ * ``AS IS'' AND ANY EXPRESS OR IM=
PLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<br clear=3D"none"></div><div d=
ir=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FO=
R A PARTICULAR<br clear=3D"none"></div><div dir=3D"ltr">+ * PURPOSE ARE DIS=
CLAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS<br clear=3D=
"none"></div><div dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCID=
ENTAL, SPECIAL, EXEMPLARY, OR<br clear=3D"none"></div><div dir=3D"ltr">+ * =
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br cle=
ar=3D"none"></div><div dir=3D"ltr">+ * SUBSTITUTE GOODS OR SERVICES; LOSS O=
F USE, DATA, OR PROFITS; OR BUSINESS<br clear=3D"none"></div><div dir=3D"lt=
r">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER=
 IN<br clear=3D"none"></div><div dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY=
, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br clear=3D"none"></div><div =
dir=3D"ltr">+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
 ADVISED OF THE<br clear=3D"none"></div><div dir=3D"ltr">+ * POSSIBILITY OF=
 SUCH DAMAGE.<br clear=3D"none"></div><div dir=3D"ltr">+ */<br clear=3D"non=
e"></div><div dir=3D"ltr">+#include &lt;sys/cdefs.h&gt;<br clear=3D"none"><=
/div><div dir=3D"ltr">+__RCSID("$NetBSD: fgets_chk.c,v 1.6 2009/02/05 05:41=
:51 lukem Exp $");<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"n=
one"></div><div dir=3D"ltr">+#include &lt;limits.h&gt;<br clear=3D"none"></=
div><div dir=3D"ltr">+#include &lt;stdio.h&gt;<br clear=3D"none"></div><div=
 dir=3D"ltr">+#include &lt;stdlib.h&gt;<br clear=3D"none"></div><div dir=3D=
"ltr">+#include &lt;string.h&gt;<br clear=3D"none"></div><div dir=3D"ltr">+=
<br clear=3D"none"></div><div dir=3D"ltr">+#include &lt;ssp/stdio.h&gt;<br =
clear=3D"none"></div><div dir=3D"ltr">+#include &lt;ssp/string.h&gt;<br cle=
ar=3D"none"></div><div dir=3D"ltr">+#undef fgets<br clear=3D"none"></div><d=
iv dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+char *<br clear=
=3D"none"></div><div dir=3D"ltr">+__fgets_chk(char * __restrict buf, int le=
n, size_t slen, FILE *fp)<br clear=3D"none"></div><div dir=3D"ltr">+{<br cl=
ear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if (slen &gt;=3D (s=
ize_t)INT_MAX)<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp; return (fgets(buf, len, fp));<br clear=3D"none"></div><=
div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nb=
sp; if (len &gt;=3D 0 &amp;&amp; (size_t)len &gt; slen)<br clear=3D"none"><=
/div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __chk_fail();<=
br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=
=3D"ltr">+&nbsp;&nbsp;&nbsp; return (fgets(buf, len, fp));<br clear=3D"none=
"></div><div dir=3D"ltr">+}<br clear=3D"none"></div><div dir=3D"ltr">diff -=
-git a/lib/libc/secure/gets_chk.c b/lib/libc/secure/gets_chk.c<br clear=3D"=
none"></div><div dir=3D"ltr">new file mode 100644<br clear=3D"none"></div><=
div dir=3D"ltr">index 000000000000..18c1e2d18f43<br clear=3D"none"></div><d=
iv dir=3D"ltr">--- /dev/null<br clear=3D"none"></div><div dir=3D"ltr">+++ b=
/lib/libc/secure/gets_chk.c<br clear=3D"none"></div><div dir=3D"ltr">@@ -0,=
0 +1,74 @@<br clear=3D"none"></div><div dir=3D"ltr">+/*-<br clear=3D"none">=
</div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * SPD=
X-License-Identifier: BSD-2-Clause<br clear=3D"none"></div><div dir=3D"ltr"=
>+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * Copyright (c) 2006 The Ne=
tBSD Foundation, Inc.<br clear=3D"none"></div><div dir=3D"ltr">+ * All righ=
ts reserved.<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"=
></div><div dir=3D"ltr">+ * This code is derived from software contributed =
to The NetBSD Foundation<br clear=3D"none"></div><div dir=3D"ltr">+ * by Ch=
ristos Zoulas.<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"non=
e"></div><div dir=3D"ltr">+ * Redistribution and use in source and binary f=
orms, with or without<br clear=3D"none"></div><div dir=3D"ltr">+ * modifica=
tion, are permitted provided that the following conditions<br clear=3D"none=
"></div><div dir=3D"ltr">+ * are met:<br clear=3D"none"></div><div dir=3D"l=
tr">+ * 1. Redistributions of source code must retain the above copyright<b=
r clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list =
of conditions and the following disclaimer.<br clear=3D"none"></div><div di=
r=3D"ltr">+ * 2. Redistributions in binary form must reproduce the above co=
pyright<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, t=
his list of conditions and the following disclaimer in the<br clear=3D"none=
"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; documentation and/or other materi=
als provided with the distribution.<br clear=3D"none"></div><div dir=3D"ltr=
">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * THIS SOFTWARE IS PROVIDE=
D BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS<br clear=3D"none"></div><=
div dir=3D"ltr">+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUD=
ING, BUT NOT LIMITED<br clear=3D"none"></div><div dir=3D"ltr">+ * TO, THE I=
MPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR<br clear=
=3D"none"></div><div dir=3D"ltr">+ * PURPOSE ARE DISCLAIMED.&nbsp; IN NO EV=
ENT SHALL THE FOUNDATION OR CONTRIBUTORS<br clear=3D"none"></div><div dir=
=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMP=
LARY, OR<br clear=3D"none"></div><div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES=
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br clear=3D"none"></div><di=
v dir=3D"ltr">+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFI=
TS; OR BUSINESS<br clear=3D"none"></div><div dir=3D"ltr">+ * INTERRUPTION) =
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br clear=3D"none"=
></div><div dir=3D"ltr">+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING =
NEGLIGENCE OR OTHERWISE)<br clear=3D"none"></div><div dir=3D"ltr">+ * ARISI=
NG IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br cl=
ear=3D"none"></div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br clea=
r=3D"none"></div><div dir=3D"ltr">+ */<br clear=3D"none"></div><div dir=3D"=
ltr">+#include &lt;sys/cdefs.h&gt;<br clear=3D"none"></div><div dir=3D"ltr"=
>+__RCSID("$NetBSD: gets_chk.c,v 1.7 2013/10/04 20:49:16 christos Exp $");<=
br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=
=3D"ltr">+#include &lt;limits.h&gt;<br clear=3D"none"></div><div dir=3D"ltr=
">+#include &lt;stdio.h&gt;<br clear=3D"none"></div><div dir=3D"ltr">+#incl=
ude &lt;stdlib.h&gt;<br clear=3D"none"></div><div dir=3D"ltr">+#include &lt=
;string.h&gt;<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none">=
</div><div dir=3D"ltr">+#include &lt;ssp/stdio.h&gt;<br clear=3D"none"></di=
v><div dir=3D"ltr">+#include &lt;ssp/string.h&gt;<br clear=3D"none"></div><=
div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+char *__gets_un=
safe(char *);<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none">=
</div><div dir=3D"ltr">+char *<br clear=3D"none"></div><div dir=3D"ltr">+__=
gets_chk(char * __restrict buf, size_t slen)<br clear=3D"none"></div><div d=
ir=3D"ltr">+{<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; =
char *abuf;<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; si=
ze_t len;<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></di=
v><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if (slen &gt;=3D (size_t)INT_MAX)<br=
 clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbs=
p; return (__gets_unsafe(buf));<br clear=3D"none"></div><div dir=3D"ltr">+<=
br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if ((abuf =3D =
malloc(slen + 1)) =3D=3D NULL)<br clear=3D"none"></div><div dir=3D"ltr">+&n=
bsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return (__gets_unsafe(buf));<br clear=
=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr"=
>+&nbsp;&nbsp;&nbsp; if (fgets(abuf, (int)(slen + 1), stdin) =3D=3D NULL) {=
<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&=
nbsp; free(abuf);<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nb=
sp; &nbsp;&nbsp;&nbsp; return (NULL);<br clear=3D"none"></div><div dir=3D"l=
tr">+&nbsp;&nbsp;&nbsp; }<br clear=3D"none"></div><div dir=3D"ltr">+<br cle=
ar=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; len =3D strlen(abuf)=
;<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if (len &gt;=
 0 &amp;&amp; abuf[len - 1] =3D=3D '\n')<br clear=3D"none"></div><div dir=
=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; --len;<br clear=3D"none"></=
div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbs=
p;&nbsp; if (len &gt;=3D slen)<br clear=3D"none"></div><div dir=3D"ltr">+&n=
bsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __chk_fail();<br clear=3D"none"></div><=
div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nb=
sp; (void)memcpy(buf, abuf, len);<br clear=3D"none"></div><div dir=3D"ltr">=
+<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; buf[len] =3D=
 '\0';<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; free(ab=
uf);<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; return (b=
uf);<br clear=3D"none"></div><div dir=3D"ltr">+}<br clear=3D"none"></div><d=
iv dir=3D"ltr">diff --git a/lib/libc/secure/memcpy_chk.c b/lib/libc/secure/=
memcpy_chk.c<br clear=3D"none"></div><div dir=3D"ltr">new file mode 100644<=
br clear=3D"none"></div><div dir=3D"ltr">index 000000000000..99cf2d5f13ff<b=
r clear=3D"none"></div><div dir=3D"ltr">--- /dev/null<br clear=3D"none"></d=
iv><div dir=3D"ltr">+++ b/lib/libc/secure/memcpy_chk.c<br clear=3D"none"></=
div><div dir=3D"ltr">@@ -0,0 +1,53 @@<br clear=3D"none"></div><div dir=3D"l=
tr">+/*-<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></d=
iv><div dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br clear=3D"n=
one"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ =
* Copyright (c) 2006 The NetBSD Foundation, Inc.<br clear=3D"none"></div><d=
iv dir=3D"ltr">+ * All rights reserved.<br clear=3D"none"></div><div dir=3D=
"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * This code is derived=
 from software contributed to The NetBSD Foundation<br clear=3D"none"></div=
><div dir=3D"ltr">+ * by Christos Zoulas.<br clear=3D"none"></div><div dir=
=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * Redistribution an=
d use in source and binary forms, with or without<br clear=3D"none"></div><=
div dir=3D"ltr">+ * modification, are permitted provided that the following=
 conditions<br clear=3D"none"></div><div dir=3D"ltr">+ * are met:<br clear=
=3D"none"></div><div dir=3D"ltr">+ * 1. Redistributions of source code must=
 retain the above copyright<br clear=3D"none"></div><div dir=3D"ltr">+ *&nb=
sp; &nbsp; notice, this list of conditions and the following disclaimer.<br=
 clear=3D"none"></div><div dir=3D"ltr">+ * 2. Redistributions in binary for=
m must reproduce the above copyright<br clear=3D"none"></div><div dir=3D"lt=
r">+ *&nbsp; &nbsp; notice, this list of conditions and the following discl=
aimer in the<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; docu=
mentation and/or other materials provided with the distribution.<br clear=
=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"lt=
r">+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIB=
UTORS<br clear=3D"none"></div><div dir=3D"ltr">+ * ``AS IS'' AND ANY EXPRES=
S OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<br clear=3D"none"></div=
><div dir=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT=
NESS FOR A PARTICULAR<br clear=3D"none"></div><div dir=3D"ltr">+ * PURPOSE =
ARE DISCLAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS<br c=
lear=3D"none"></div><div dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, INDIRECT=
, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br clear=3D"none"></div><div dir=3D"lt=
r">+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF=
<br clear=3D"none"></div><div dir=3D"ltr">+ * SUBSTITUTE GOODS OR SERVICES;=
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br clear=3D"none"></div><div di=
r=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, =
WHETHER IN<br clear=3D"none"></div><div dir=3D"ltr">+ * CONTRACT, STRICT LI=
ABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br clear=3D"none"></di=
v><div dir=3D"ltr">+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, =
EVEN IF ADVISED OF THE<br clear=3D"none"></div><div dir=3D"ltr">+ * POSSIBI=
LITY OF SUCH DAMAGE.<br clear=3D"none"></div><div dir=3D"ltr">+ */<br clear=
=3D"none"></div><div dir=3D"ltr">+#include &lt;sys/cdefs.h&gt;<br clear=3D"=
none"></div><div dir=3D"ltr">+__RCSID("$NetBSD: memcpy_chk.c,v 1.7 2015/05/=
13 19:57:16 joerg Exp $");<br clear=3D"none"></div><div dir=3D"ltr">+<br cl=
ear=3D"none"></div><div dir=3D"ltr">+#include &lt;string.h&gt;<br clear=3D"=
none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#i=
nclude &lt;ssp/string.h&gt;<br clear=3D"none"></div><div dir=3D"ltr">+#unde=
f memcpy<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div=
><div dir=3D"ltr">+#include "ssp_internal.h"<br clear=3D"none"></div><div d=
ir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+void *<br clear=3D"n=
one"></div><div dir=3D"ltr">+__memcpy_chk(void * __restrict dst, const void=
 * __restrict src, size_t len,<br clear=3D"none"></div><div dir=3D"ltr">+&n=
bsp; &nbsp; size_t slen)<br clear=3D"none"></div><div dir=3D"ltr">+{<br cle=
ar=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if (len &gt; slen)<b=
r clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nb=
sp; __chk_fail();<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"no=
ne"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if (__ssp_overlap((const cha=
r *)src, (const char *)dst, len))<br clear=3D"none"></div><div dir=3D"ltr">=
+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __chk_fail();<br clear=3D"none"></di=
v><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;=
&nbsp; return (memcpy(dst, src, len));<br clear=3D"none"></div><div dir=3D"=
ltr">+}<br clear=3D"none"></div><div dir=3D"ltr">diff --git a/lib/libc/secu=
re/memmove_chk.c b/lib/libc/secure/memmove_chk.c<br clear=3D"none"></div><d=
iv dir=3D"ltr">new file mode 100644<br clear=3D"none"></div><div dir=3D"ltr=
">index 000000000000..07f965d608fc<br clear=3D"none"></div><div dir=3D"ltr"=
>--- /dev/null<br clear=3D"none"></div><div dir=3D"ltr">+++ b/lib/libc/secu=
re/memmove_chk.c<br clear=3D"none"></div><div dir=3D"ltr">@@ -0,0 +1,47 @@<=
br clear=3D"none"></div><div dir=3D"ltr">+/*-<br clear=3D"none"></div><div =
dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * SPDX-License-I=
dentifier: BSD-2-Clause<br clear=3D"none"></div><div dir=3D"ltr">+ *<br cle=
ar=3D"none"></div><div dir=3D"ltr">+ * Copyright (c) 2006 The NetBSD Founda=
tion, Inc.<br clear=3D"none"></div><div dir=3D"ltr">+ * All rights reserved=
.<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div=
 dir=3D"ltr">+ * This code is derived from software contributed to The NetB=
SD Foundation<br clear=3D"none"></div><div dir=3D"ltr">+ * by Christos Zoul=
as.<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><d=
iv dir=3D"ltr">+ * Redistribution and use in source and binary forms, with =
or without<br clear=3D"none"></div><div dir=3D"ltr">+ * modification, are p=
ermitted provided that the following conditions<br clear=3D"none"></div><di=
v dir=3D"ltr">+ * are met:<br clear=3D"none"></div><div dir=3D"ltr">+ * 1. =
Redistributions of source code must retain the above copyright<br clear=3D"=
none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditio=
ns and the following disclaimer.<br clear=3D"none"></div><div dir=3D"ltr">+=
 * 2. Redistributions in binary form must reproduce the above copyright<br =
clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp; notice, this list of=
 conditions and the following disclaimer in the<br clear=3D"none"></div><di=
v dir=3D"ltr">+ *&nbsp; &nbsp; documentation and/or other materials provide=
d with the distribution.<br clear=3D"none"></div><div dir=3D"ltr">+ *<br cl=
ear=3D"none"></div><div dir=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY THE NE=
TBSD FOUNDATION, INC. AND CONTRIBUTORS<br clear=3D"none"></div><div dir=3D"=
ltr">+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NO=
T LIMITED<br clear=3D"none"></div><div dir=3D"ltr">+ * TO, THE IMPLIED WARR=
ANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR<br clear=3D"none"></=
div><div dir=3D"ltr">+ * PURPOSE ARE DISCLAIMED.&nbsp; IN NO EVENT SHALL TH=
E FOUNDATION OR CONTRIBUTORS<br clear=3D"none"></div><div dir=3D"ltr">+ * B=
E LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br cl=
ear=3D"none"></div><div dir=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDING, B=
UT NOT LIMITED TO, PROCUREMENT OF<br clear=3D"none"></div><div dir=3D"ltr">=
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINES=
S<br clear=3D"none"></div><div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED=
 AND ON ANY THEORY OF LIABILITY, WHETHER IN<br clear=3D"none"></div><div di=
r=3D"ltr">+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR =
OTHERWISE)<br clear=3D"none"></div><div dir=3D"ltr">+ * ARISING IN ANY WAY =
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br clear=3D"none"><=
/div><div dir=3D"ltr">+ * POSSIBILITY OF SUCH DAMAGE.<br clear=3D"none"></d=
iv><div dir=3D"ltr">+ */<br clear=3D"none"></div><div dir=3D"ltr">+#include=
 &lt;sys/cdefs.h&gt;<br clear=3D"none"></div><div dir=3D"ltr">+__RCSID("$Ne=
tBSD: memmove_chk.c,v 1.6 2020/09/05 13:37:59 mrg Exp $");<br clear=3D"none=
"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#inclu=
de &lt;string.h&gt;<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"=
none"></div><div dir=3D"ltr">+#include &lt;ssp/string.h&gt;<br clear=3D"non=
e"></div><div dir=3D"ltr">+#undef memmove<br clear=3D"none"></div><div dir=
=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+void *<br clear=3D"non=
e"></div><div dir=3D"ltr">+__memmove_chk(void *dst, const void *src, size_t=
 len,<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; size_t slen)<=
br clear=3D"none"></div><div dir=3D"ltr">+{<br clear=3D"none"></div><div di=
r=3D"ltr">+&nbsp;&nbsp;&nbsp; if (len &gt; slen)<br clear=3D"none"></div><d=
iv dir=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __chk_fail();<br clea=
r=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; return (memmove(dst, =
src, len));<br clear=3D"none"></div><div dir=3D"ltr">+}<br clear=3D"none"><=
/div><div dir=3D"ltr">diff --git a/lib/libc/secure/memset_chk.c b/lib/libc/=
secure/memset_chk.c<br clear=3D"none"></div><div dir=3D"ltr">new file mode =
100644<br clear=3D"none"></div><div dir=3D"ltr">index 000000000000..f337be9=
8b46d<br clear=3D"none"></div><div dir=3D"ltr">--- /dev/null<br clear=3D"no=
ne"></div><div dir=3D"ltr">+++ b/lib/libc/secure/memset_chk.c<br clear=3D"n=
one"></div><div dir=3D"ltr">@@ -0,0 +1,46 @@<br clear=3D"none"></div><div d=
ir=3D"ltr">+/*-<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"no=
ne"></div><div dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br cle=
ar=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"=
ltr">+ * Copyright (c) 2006 The NetBSD Foundation, Inc.<br clear=3D"none"><=
/div><div dir=3D"ltr">+ * All rights reserved.<br clear=3D"none"></div><div=
 dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * This code is =
derived from software contributed to The NetBSD Foundation<br clear=3D"none=
"></div><div dir=3D"ltr">+ * by Christos Zoulas.<br clear=3D"none"></div><d=
iv dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * Redistribut=
ion and use in source and binary forms, with or without<br clear=3D"none"><=
/div><div dir=3D"ltr">+ * modification, are permitted provided that the fol=
lowing conditions<br clear=3D"none"></div><div dir=3D"ltr">+ * are met:<br =
clear=3D"none"></div><div dir=3D"ltr">+ * 1. Redistributions of source code=
 must retain the above copyright<br clear=3D"none"></div><div dir=3D"ltr">+=
 *&nbsp; &nbsp; notice, this list of conditions and the following disclaime=
r.<br clear=3D"none"></div><div dir=3D"ltr">+ * 2. Redistributions in binar=
y form must reproduce the above copyright<br clear=3D"none"></div><div dir=
=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditions and the following=
 disclaimer in the<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp=
; documentation and/or other materials provided with the distribution.<br c=
lear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=
=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND C=
ONTRIBUTORS<br clear=3D"none"></div><div dir=3D"ltr">+ * ``AS IS'' AND ANY =
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<br clear=3D"none"=
></div><div dir=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY A=
ND FITNESS FOR A PARTICULAR<br clear=3D"none"></div><div dir=3D"ltr">+ * PU=
RPOSE ARE DISCLAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTOR=
S<br clear=3D"none"></div><div dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, IN=
DIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br clear=3D"none"></div><div dir=
=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREM=
ENT OF<br clear=3D"none"></div><div dir=3D"ltr">+ * SUBSTITUTE GOODS OR SER=
VICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br clear=3D"none"></div><=
div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABI=
LITY, WHETHER IN<br clear=3D"none"></div><div dir=3D"ltr">+ * CONTRACT, STR=
ICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br clear=3D"none=
"></div><div dir=3D"ltr">+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFT=
WARE, EVEN IF ADVISED OF THE<br clear=3D"none"></div><div dir=3D"ltr">+ * P=
OSSIBILITY OF SUCH DAMAGE.<br clear=3D"none"></div><div dir=3D"ltr">+ */<br=
 clear=3D"none"></div><div dir=3D"ltr">+#include &lt;sys/cdefs.h&gt;<br cle=
ar=3D"none"></div><div dir=3D"ltr">+__RCSID("$NetBSD: memset_chk.c,v 1.5 20=
14/09/17 00:39:28 joerg Exp $");<br clear=3D"none"></div><div dir=3D"ltr">+=
<br clear=3D"none"></div><div dir=3D"ltr">+#include &lt;string.h&gt;<br cle=
ar=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"lt=
r">+#include &lt;ssp/string.h&gt;<br clear=3D"none"></div><div dir=3D"ltr">=
+#undef memset<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"=
></div><div dir=3D"ltr">+void *<br clear=3D"none"></div><div dir=3D"ltr">+_=
_memset_chk(void * __restrict dst, int val, size_t len, size_t slen)<br cle=
ar=3D"none"></div><div dir=3D"ltr">+{<br clear=3D"none"></div><div dir=3D"l=
tr">+&nbsp;&nbsp;&nbsp; if (len &gt; slen)<br clear=3D"none"></div><div dir=
=3D"ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __chk_fail();<br clear=3D"n=
one"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; return (memset(dst, val, le=
n));<br clear=3D"none"></div><div dir=3D"ltr">+}<br clear=3D"none"></div><d=
iv dir=3D"ltr">diff --git a/lib/libc/secure/snprintf_chk.c b/lib/libc/secur=
e/snprintf_chk.c<br clear=3D"none"></div><div dir=3D"ltr">new file mode 100=
644<br clear=3D"none"></div><div dir=3D"ltr">index 000000000000..52ef874ede=
5b<br clear=3D"none"></div><div dir=3D"ltr">--- /dev/null<br clear=3D"none"=
></div><div dir=3D"ltr">+++ b/lib/libc/secure/snprintf_chk.c<br clear=3D"no=
ne"></div><div dir=3D"ltr">@@ -0,0 +1,56 @@<br clear=3D"none"></div><div di=
r=3D"ltr">+/*-<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"non=
e"></div><div dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br clea=
r=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"l=
tr">+ * Copyright (c) 2006 The NetBSD Foundation, Inc.<br clear=3D"none"></=
div><div dir=3D"ltr">+ * All rights reserved.<br clear=3D"none"></div><div =
dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * This code is d=
erived from software contributed to The NetBSD Foundation<br clear=3D"none"=
></div><div dir=3D"ltr">+ * by Christos Zoulas.<br clear=3D"none"></div><di=
v dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * Redistributi=
on and use in source and binary forms, with or without<br clear=3D"none"></=
div><div dir=3D"ltr">+ * modification, are permitted provided that the foll=
owing conditions<br clear=3D"none"></div><div dir=3D"ltr">+ * are met:<br c=
lear=3D"none"></div><div dir=3D"ltr">+ * 1. Redistributions of source code =
must retain the above copyright<br clear=3D"none"></div><div dir=3D"ltr">+ =
*&nbsp; &nbsp; notice, this list of conditions and the following disclaimer=
.<br clear=3D"none"></div><div dir=3D"ltr">+ * 2. Redistributions in binary=
 form must reproduce the above copyright<br clear=3D"none"></div><div dir=
=3D"ltr">+ *&nbsp; &nbsp; notice, this list of conditions and the following=
 disclaimer in the<br clear=3D"none"></div><div dir=3D"ltr">+ *&nbsp; &nbsp=
; documentation and/or other materials provided with the distribution.<br c=
lear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=
=3D"ltr">+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND C=
ONTRIBUTORS<br clear=3D"none"></div><div dir=3D"ltr">+ * ``AS IS'' AND ANY =
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED<br clear=3D"none"=
></div><div dir=3D"ltr">+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY A=
ND FITNESS FOR A PARTICULAR<br clear=3D"none"></div><div dir=3D"ltr">+ * PU=
RPOSE ARE DISCLAIMED.&nbsp; IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTOR=
S<br clear=3D"none"></div><div dir=3D"ltr">+ * BE LIABLE FOR ANY DIRECT, IN=
DIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br clear=3D"none"></div><div dir=
=3D"ltr">+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREM=
ENT OF<br clear=3D"none"></div><div dir=3D"ltr">+ * SUBSTITUTE GOODS OR SER=
VICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br clear=3D"none"></div><=
div dir=3D"ltr">+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABI=
LITY, WHETHER IN<br clear=3D"none"></div><div dir=3D"ltr">+ * CONTRACT, STR=
ICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br clear=3D"none=
"></div><div dir=3D"ltr">+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFT=
WARE, EVEN IF ADVISED OF THE<br clear=3D"none"></div><div dir=3D"ltr">+ * P=
OSSIBILITY OF SUCH DAMAGE.<br clear=3D"none"></div><div dir=3D"ltr">+ */<br=
 clear=3D"none"></div><div dir=3D"ltr">+#include &lt;sys/cdefs.h&gt;<br cle=
ar=3D"none"></div><div dir=3D"ltr">+__RCSID("$NetBSD: snprintf_chk.c,v 1.5 =
2008/04/28 20:23:00 martin Exp $");<br clear=3D"none"></div><div dir=3D"ltr=
">+<br clear=3D"none"></div><div dir=3D"ltr">+#include &lt;stdarg.h&gt;<br =
clear=3D"none"></div><div dir=3D"ltr">+#include &lt;stdio.h&gt;<br clear=3D=
"none"></div><div dir=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+#=
include &lt;ssp/stdio.h&gt;<br clear=3D"none"></div><div dir=3D"ltr">+#unde=
f vsnprintf<br clear=3D"none"></div><div dir=3D"ltr">+<br clear=3D"none"></=
div><div dir=3D"ltr">+int<br clear=3D"none"></div><div dir=3D"ltr">+__snpri=
ntf_chk(char * __restrict buf, size_t len, int flags, size_t slen,<br clear=
=3D"none"></div><div dir=3D"ltr">+&nbsp; &nbsp; const char * __restrict fmt=
, ...)<br clear=3D"none"></div><div dir=3D"ltr">+{<br clear=3D"none"></div>=
<div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; va_list ap;<br clear=3D"none"></div><d=
iv dir=3D"ltr">+&nbsp;&nbsp;&nbsp; int rv;<br clear=3D"none"></div><div dir=
=3D"ltr">+<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; if =
(len &gt; slen)<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp=
; &nbsp;&nbsp;&nbsp; __chk_fail();<br clear=3D"none"></div><div dir=3D"ltr"=
>+<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; va_start(ap=
, fmt);<br clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; rv =3D=
 vsnprintf(buf, len, fmt, ap);<br clear=3D"none"></div><div dir=3D"ltr">+&n=
bsp;&nbsp;&nbsp; va_end(ap);<br clear=3D"none"></div><div dir=3D"ltr">+<br =
clear=3D"none"></div><div dir=3D"ltr">+&nbsp;&nbsp;&nbsp; return (rv);<br c=
lear=3D"none"></div><div dir=3D"ltr">+}<br clear=3D"none"></div><div dir=3D=
"ltr">diff --git a/lib/libc/secure/sprintf_chk.c b/lib/libc/secure/sprintf_=
chk.c<br clear=3D"none"></div><div dir=3D"ltr">new file mode 100644<br clea=
r=3D"none"></div><div dir=3D"ltr">index 000000000000..d4c42ccba3ce<br clear=
=3D"none"></div><div dir=3D"ltr">--- /dev/null<br clear=3D"none"></div><div=
 dir=3D"ltr">+++ b/lib/libc/secure/sprintf_chk.c<br clear=3D"none"></div><d=
iv dir=3D"ltr">@@ -0,0 +1,61 @@<br clear=3D"none"></div><div dir=3D"ltr">+/=
*-<br clear=3D"none"></div><div dir=3D"ltr">+ *<br clear=3D"none"></div><di=
v dir=3D"ltr">+ * SPDX-License-Identifier: BSD-2-Clause<br clear=3D"none"><=
/div><div dir=3D"ltr">+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * Copy=
right (c) 2006 The NetBSD Foundation, Inc.<br clear=3D"none"></div><div dir=
=3D"ltr">+ * All rights reserved.<br clear=3D"none"></div><div dir=3D"ltr">=
+ *<br clear=3D"none"></div><div dir=3D"ltr">+ * This code is derived from =
software contributed to The NetBSD Foundation<br clear=3D"none"></div><div =
dir=3D"ltr">*** 1063 LINES SKIPPED ***<br clear=3D"none"></div></div>
            </div>
        </div></div></div></blockquote></div><br clear=3D"none"></div></div=
></div></div></div></div>
            </div>
        </div></body></html>
------=_Part_1638477_2102893408.1716080957796--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?999469960.1638478.1716080957814>