Skip to content

Commit 4be240b

Browse files
committed
Merge tag 'memcpy-v5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull FORTIFY_SOURCE updates from Kees Cook: "This series consists of two halves: - strict compile-time buffer size checking under FORTIFY_SOURCE for the memcpy()-family of functions (for extensive details and rationale, see the first commit) - enabling FORTIFY_SOURCE for Clang, which has had many overlapping bugs that we've finally worked past" * tag 'memcpy-v5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: fortify: Add Clang support fortify: Make sure strlen() may still be used as a constant expression fortify: Use __diagnose_as() for better diagnostic coverage fortify: Make pointer arguments const Compiler Attributes: Add __diagnose_as for Clang Compiler Attributes: Add __overloadable for Clang Compiler Attributes: Add __pass_object_size for Clang fortify: Replace open-coded __gnu_inline attribute fortify: Update compile-time tests for Clang 14 fortify: Detect struct member overflows in memset() at compile-time fortify: Detect struct member overflows in memmove() at compile-time fortify: Detect struct member overflows in memcpy() at compile-time
2 parents 3f72821 + 281d0c9 commit 4be240b

13 files changed

+272
-56
lines changed

arch/x86/boot/compressed/misc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737
* try to define their own functions if these are not defined as macros.
3838
*/
3939
#define memzero(s, n) memset((s), 0, (n))
40+
#ifndef memmove
4041
#define memmove memmove
41-
4242
/* Functions used by the included decompressor code below. */
4343
void *memmove(void *dest, const void *src, size_t n);
44+
#endif
4445

4546
/*
4647
* This is set up by the setup-routine at boot-time

arch/x86/lib/memcpy_32.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#undef memcpy
66
#undef memset
7+
#undef memmove
78

89
__visible void *memcpy(void *to, const void *from, size_t n)
910
{

include/linux/compiler_attributes.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@
100100
# define __copy(symbol)
101101
#endif
102102

103+
/*
104+
* Optional: not supported by gcc
105+
* Optional: only supported since clang >= 14.0
106+
* Optional: not supported by icc
107+
*
108+
* clang: https://clang.llvm.org/docs/AttributeReference.html#diagnose_as_builtin
109+
*/
110+
#if __has_attribute(__diagnose_as_builtin__)
111+
# define __diagnose_as(builtin...) __attribute__((__diagnose_as_builtin__(builtin)))
112+
#else
113+
# define __diagnose_as(builtin...)
114+
#endif
115+
103116
/*
104117
* Don't. Just don't. See commit 771c035372a0 ("deprecate the '__deprecated'
105118
* attribute warnings entirely and for good") for more information.
@@ -257,12 +270,38 @@
257270
*/
258271
#define __noreturn __attribute__((__noreturn__))
259272

273+
/*
274+
* Optional: not supported by gcc.
275+
* Optional: not supported by icc.
276+
*
277+
* clang: https://clang.llvm.org/docs/AttributeReference.html#overloadable
278+
*/
279+
#if __has_attribute(__overloadable__)
280+
# define __overloadable __attribute__((__overloadable__))
281+
#else
282+
# define __overloadable
283+
#endif
284+
260285
/*
261286
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-packed-type-attribute
262287
* clang: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-packed-variable-attribute
263288
*/
264289
#define __packed __attribute__((__packed__))
265290

291+
/*
292+
* Note: the "type" argument should match any __builtin_object_size(p, type) usage.
293+
*
294+
* Optional: not supported by gcc.
295+
* Optional: not supported by icc.
296+
*
297+
* clang: https://clang.llvm.org/docs/AttributeReference.html#pass-object-size-pass-dynamic-object-size
298+
*/
299+
#if __has_attribute(__pass_object_size__)
300+
# define __pass_object_size(type) __attribute__((__pass_object_size__(type)))
301+
#else
302+
# define __pass_object_size(type)
303+
#endif
304+
266305
/*
267306
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute
268307
*/

0 commit comments

Comments
 (0)