Commit cfecea6e authored by Kees Cook's avatar Kees Cook
Browse files

lib/string: Move helper functions out of string.c



The core functions of string.c are those that may be implemented by
per-architecture functions, or overloaded by FORTIFY_SOURCE. As a
result, it needs to be built with __NO_FORTIFY. Without this, macros
will collide with function declarations. This was accidentally working
due to -ffreestanding (on some architectures). Make this deterministic
by explicitly setting __NO_FORTIFY and move all the helper functions
into string_helpers.c so that they gain the fortification coverage they
had been missing.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Andy Lavr <andy.lavr@gmail.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Acked-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent c80d92fb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 * Small subset of simple string routines
 */

#define __NO_FORTIFY
#include <linux/string.h>

/*
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@
 */

#define IN_ARCH_STRING_C 1
#ifndef __NO_FORTIFY
# define __NO_FORTIFY
#endif

#include <linux/types.h>
#include <linux/string.h>
+2 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
#undef CONFIG_KASAN
#undef CONFIG_KASAN_GENERIC

#define __NO_FORTIFY

/* cpu_feature_enabled() cannot be used this early */
#define USE_EARLY_PGTABLE_L5

+2 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
#include "misc.h"
#include <linux/efi.h>
#include <asm/e820/types.h>
#include <asm/processor.h>
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
 * strings.
 */

#define __NO_FORTIFY
#include <linux/string.h>
#include <linux/export.h>

Loading