Skip to content

Commit

Permalink
fortify: use WARN instead of BUG for now
Browse files Browse the repository at this point in the history
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.

Link: http://lkml.kernel.org/r/20170726185219.GA57833@beast
Signed-off-by: Kees Cook <keescook@chromium.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Daniel Micay <danielmicay@gmail.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
  • Loading branch information
kees authored and sfrothwell committed Aug 1, 2017
1 parent 7c050a3 commit 62d1034
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion arch/x86/boot/compressed/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
return output;
}

void fortify_panic(const char *name)
void fortify_overflow(const char *name)
{
error("detected buffer overflow");
}
30 changes: 15 additions & 15 deletions include/linux/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static inline const char *kbasename(const char *path)
#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");
Expand All @@ -209,7 +209,7 @@ __FORTIFY_INLINE char *strncpy(char *p, const char *q, __kernel_size_t size)
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);
}

Expand All @@ -219,7 +219,7 @@ __FORTIFY_INLINE char *strcat(char *p, const char *q)
if (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;
}

Expand All @@ -231,7 +231,7 @@ __FORTIFY_INLINE __kernel_size_t strlen(const char *p)
return __builtin_strlen(p);
ret = strnlen(p, p_size);
if (p_size <= ret)
fortify_panic(__func__);
fortify_overflow(__func__);
return ret;
}

Expand All @@ -241,7 +241,7 @@ __FORTIFY_INLINE __kernel_size_t strnlen(const char *p, __kernel_size_t maxlen)
size_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;
}

Expand All @@ -260,7 +260,7 @@ __FORTIFY_INLINE size_t strlcpy(char *p, const char *q, size_t size)
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';
}
Expand All @@ -278,7 +278,7 @@ __FORTIFY_INLINE char *strncat(char *p, const char *q, __kernel_size_t count)
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;
Expand All @@ -290,7 +290,7 @@ __FORTIFY_INLINE void *memset(void *p, int c, __kernel_size_t size)
if (__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);
}

Expand All @@ -305,7 +305,7 @@ __FORTIFY_INLINE void *memcpy(void *p, const void *q, __kernel_size_t size)
__read_overflow2();
}
if (p_size < size || q_size < size)
fortify_panic(__func__);
fortify_overflow(__func__);
return __builtin_memcpy(p, q, size);
}

Expand All @@ -320,7 +320,7 @@ __FORTIFY_INLINE void *memmove(void *p, const void *q, __kernel_size_t size)
__read_overflow2();
}
if (p_size < size || q_size < size)
fortify_panic(__func__);
fortify_overflow(__func__);
return __builtin_memmove(p, q, size);
}

Expand All @@ -331,7 +331,7 @@ __FORTIFY_INLINE void *memscan(void *p, int c, __kernel_size_t size)
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);
}

Expand All @@ -346,7 +346,7 @@ __FORTIFY_INLINE int memcmp(const void *p, const void *q, __kernel_size_t size)
__read_overflow2();
}
if (p_size < size || q_size < size)
fortify_panic(__func__);
fortify_overflow(__func__);
return __builtin_memcmp(p, q, size);
}

Expand All @@ -356,7 +356,7 @@ __FORTIFY_INLINE void *memchr(const void *p, int c, __kernel_size_t size)
if (__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);
}

Expand All @@ -367,7 +367,7 @@ __FORTIFY_INLINE void *memchr_inv(const void *p, int c, size_t size)
if (__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);
}

Expand All @@ -378,7 +378,7 @@ __FORTIFY_INLINE void *kmemdup(const void *p, size_t size, gfp_t gfp)
if (__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);
}

Expand Down
7 changes: 3 additions & 4 deletions lib/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,9 +979,8 @@ char *strreplace(char *s, char old, char new)
}
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);
2 changes: 1 addition & 1 deletion tools/objtool/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static int __dead_end_function(struct objtool_file *file, struct symbol *func,
"kvm_spurious_fault",
"__reiserfs_panic",
"lbug_with_loc",
"fortify_panic",
"fortify_overflow",
};

if (func->bind == STB_WEAK)
Expand Down

0 comments on commit 62d1034

Please sign in to comment.