fortify: use WARN instead of BUG for now
Subsystems (4)
[email protected]
maintainerPATCH 8/16 fortify: use WARN instead of BUG for now
From: Kees Cook <[email protected]>
Subject: fortify: use WARN instead of BUG for now
While CONFIG_FORTIFY_SOURCE continues to shake out, don't unconditionally use BUG(), opting instead for WARN(). This also renames fortify_panic() to fortify_overflow() which better matches what it is being called for.
---
arch/x86/boot/compressed/misc.c | 2 +- include/linux/string.h | 30 +++++++++++++++--------------- lib/string.c | 7 +++---- tools/objtool/check.c | 1 - 4 files changed, 19 insertions(+), 21 deletions(-)
arch/x86/boot/compressed/misc.c renamed from arch/x86/boot/compressed/misc.c~fortify-use-warn-instead-of-bug-for-now +1 -1
@@ -412,7 +412,7 @@ asmlinkage __visible void *extract_kernereturn output; } -void fortify_panic (const char *name) +void fortify_overflow (const char *name) {error ("detected buffer overflow" ); }
include/linux/string.h renamed from include/linux/string.h~fortify-use-warn-instead-of-bug-for-now +15 -15
@@ -197,7 +197,7 @@ static inline const char *kbasename(cons#define __FORTIFY_INLINE extern __always_inline __attribute__((gnu_inline))#define __RENAME (x) __asm__(#x) -void fortify_panic (const char *name)__noreturn __cold ; +void fortify_overflow (const char *name)__cold ; void __read_overflow(void) __compiletime_error("detected read beyond size of object passed as 1st parameter"); void __read_overflow2(void) __compiletime_error("detected read beyond size of object passed as 2nd parameter"); void __write_overflow(void) __compiletime_error("detected write beyond size of object passed as 1st parameter");
@@ -209,7 +209,7 @@ __FORTIFY_INLINE char *strncpy(char *p,if (__builtin_constant_p (size) && p_size < size)__write_overflow ();if (p_size < size) -fortify_panic (__func__); +fortify_overflow (__func__);return __builtin_strncpy (p, q, size); }
@@ -219,7 +219,7 @@ __FORTIFY_INLINE char *strcat(char *p, cif (p_size == (size_t )-1 )return __builtin_strcat (p, q);if (strlcat (p, q, p_size) >= p_size) -fortify_panic (__func__); +fortify_overflow (__func__);return p; }
@@ -231,7 +231,7 @@ __FORTIFY_INLINE __kernel_size_t strlen(return __builtin_strlen (p); ret =strnlen (p, p_size);if (p_size <= ret) -fortify_panic (__func__); +fortify_overflow (__func__);return ret; }
@@ -241,7 +241,7 @@ __FORTIFY_INLINE __kernel_size_t strnlensize_t p_size =__builtin_object_size (p,0 );__kernel_size_t ret =__real_strnlen (p, maxlen < p_size ? maxlen : p_size);if (p_size <= ret && maxlen != ret) -fortify_panic (__func__); +fortify_overflow (__func__);return ret; }
@@ -260,7 +260,7 @@ __FORTIFY_INLINE size_t strlcpy(char *p,if (__builtin_constant_p (len) && len >= p_size)__write_overflow ();if (len >= p_size) -fortify_panic (__func__); +fortify_overflow (__func__);__builtin_memcpy (p, q, len); p[len] ='\0' ; }
@@ -278,7 +278,7 @@ __FORTIFY_INLINE char *strncat(char *p, p_len =strlen (p); copy_len =strnlen (q, count);if (p_size < p_len + copy_len +1 ) -fortify_panic (__func__); +fortify_overflow (__func__);__builtin_memcpy (p + p_len, q, copy_len); p[p_len + copy_len] ='\0' ;return p;
@@ -290,7 +290,7 @@ __FORTIFY_INLINE void *memset(void *p, iif (__builtin_constant_p (size) && p_size < size)__write_overflow ();if (p_size < size) -fortify_panic (__func__); +fortify_overflow (__func__);return __builtin_memset (p, c, size); }
@@ -305,7 +305,7 @@ __FORTIFY_INLINE void *memcpy(void *p, c__read_overflow2 (); }if (p_size < size || q_size < size) -fortify_panic (__func__); +fortify_overflow (__func__);return __builtin_memcpy (p, q, size); }
@@ -320,7 +320,7 @@ __FORTIFY_INLINE void *memmove(void *p,__read_overflow2 (); }if (p_size < size || q_size < size) -fortify_panic (__func__); +fortify_overflow (__func__);return __builtin_memmove (p, q, size); }
@@ -331,7 +331,7 @@ __FORTIFY_INLINE void *memscan(void *p,if (__builtin_constant_p (size) && p_size < size)__read_overflow ();if (p_size < size) -fortify_panic (__func__); +fortify_overflow (__func__);return __real_memscan (p, c, size); }
@@ -346,7 +346,7 @@ __FORTIFY_INLINE int memcmp(const void *__read_overflow2 (); }if (p_size < size || q_size < size) -fortify_panic (__func__); +fortify_overflow (__func__);return __builtin_memcmp (p, q, size); }
@@ -356,7 +356,7 @@ __FORTIFY_INLINE void *memchr(const voidif (__builtin_constant_p (size) && p_size < size)__read_overflow ();if (p_size < size) -fortify_panic (__func__); +fortify_overflow (__func__);return __builtin_memchr (p, c, size); }
@@ -367,7 +367,7 @@ __FORTIFY_INLINE void *memchr_inv(constif (__builtin_constant_p (size) && p_size < size)__read_overflow ();if (p_size < size) -fortify_panic (__func__); +fortify_overflow (__func__);return __real_memchr_inv (p, c, size); }
@@ -378,7 +378,7 @@ __FORTIFY_INLINE void *kmemdup(const voiif (__builtin_constant_p (size) && p_size < size)__read_overflow ();if (p_size < size) -fortify_panic (__func__); +fortify_overflow (__func__);return __real_kmemdup (p, size, gfp); }
lib/string.c renamed from lib/string.c~fortify-use-warn-instead-of-bug-for-now +3 -4
@@ -979,9 +979,8 @@ char *strreplace(char *s, char old, char }EXPORT_SYMBOL (strreplace); -void fortify_panic (const char *name) +void fortify_overflow (const char *name) { -pr_emerg ("detected buffer overflow in %s\n" , name); -BUG (); +WARN (1 ,"detected buffer overflow in %s\n" , name); } -EXPORT_SYMBOL (fortify_panic); +EXPORT_SYMBOL (fortify_overflow);
tools/objtool/check.c renamed from tools/objtool/check.c~fortify-use-warn-instead-of-bug-for-now +0 -1
@@ -156,7 +156,6 @@ static int __dead_end_function(struct ob"kvm_spurious_fault" ,"__reiserfs_panic" , "lbug_with_loc", - "fortify_panic", };if (func->bind ==STB_WEAK )
_
A message that is not in the archive (sent off-list or not yet received): CA+55aFxnjNNYHG6HVUoL9WQ5wKcqnXxdC=Z_TkcfaCaHJSMtnw@mail.gmail.com
Andrew Morton
maintainerQuoted 25 lines · On Wed, 2 Aug 2017 16:40:44 -0700 Linus Torvalds…
Quoted 6 lines · On Wed, Aug 2, 2017 at 1:32 PM, <[email protected]> wrote:
From: Kees Cook <[email protected]>
Subject: fortify: use WARN instead of BUG for nowWhile
CONFIG_FORTIFY_SOURCEcontinues to shake out, don't unconditionally useBUG(), opting instead forWARN(). This also renamesfortify_panic()tofortify_overflow()which better matches what it is being called for.This does not build for me. I get:
In file included from ./include/linux/bitmap.h:8:0, from ./include/linux/cpumask.h:11, from ./arch/x86/include/asm/cpumask.h:4, from ./arch/x86/include/asm/msr.h:10, from ./arch/x86/include/asm/processor.h:20, from ./arch/x86/include/asm/cpufeature.h:4, from ./arch/x86/include/asm/thread_info.h:52, from ./include/linux/thread_info.h:37, from ./arch/x86/include/asm/preempt.h:6, from ./include/linux/preempt.h:80, from ./include/linux/spinlock.h:50, from ./include/linux/wait.h:8, from ./include/linux/wait_bit.h:7, from ./include/linux/fs.h:5, from ./include/linux/buffer_head.h:11,
Quoted 8 lines
from fs/adfs/dir_f.c:12:
In function ___memcpy___,
inlined from _____adfs_dir_put___ at fs/adfs/dir_f.c:318:2,
inlined from ___adfs_f_update___ at fs/adfs/dir_f.c:403:2:
./include/linux/string.h:305:4: error: call to _____read_overflow2___
declared with attribute error: detected read beyond size of object
passed as 2nd parameter
__read_overflow2();oops. I have an adfs fix. Let me send...