Skip to content

Commit 072af0c

Browse files
committed
fortify: Fix dropped strcpy() compile-time write overflow check
The implementation for intra-object overflow in str*-family functions accidentally dropped compile-time write overflow checking in strcpy(), leaving it entirely to run-time. Add back the intended check. Fixes: 6a39e62 ("lib: string.h: detect intra-object overflow in fortified string functions") Cc: Daniel Axtens <[email protected]> Cc: Francis Laniel <[email protected]> Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]>
1 parent a52f8a5 commit 072af0c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

include/linux/fortify-string.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,10 @@ __FORTIFY_INLINE char *strcpy(char *p, const char *q)
287287
if (p_size == (size_t)-1 && q_size == (size_t)-1)
288288
return __underlying_strcpy(p, q);
289289
size = strlen(q) + 1;
290-
/* test here to use the more stringent object size */
290+
/* Compile-time check for const size overflow. */
291+
if (__builtin_constant_p(size) && p_size < size)
292+
__write_overflow();
293+
/* Run-time check for dynamic size overflow. */
291294
if (p_size < size)
292295
fortify_panic(__func__);
293296
memcpy(p, q, size);

0 commit comments

Comments
 (0)