Skip to content

Commit 2cfe0d3

Browse files
keestorvalds
authored andcommitted
task_struct: only use anon struct under randstruct plugin
The original intent for always adding the anonymous struct in task_struct was to make sure we had compiler coverage. However, this caused pathological padding of 40 bytes at the start of task_struct. Instead, move the anonymous struct to being only used when struct layout randomization is enabled. Link: http://lkml.kernel.org/r/20180327213609.GA2964@beast Fixes: 29e48ce ("task_struct: Allow randomized") Signed-off-by: Kees Cook <[email protected]> Reported-by: Peter Zijlstra <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d4ef8d3 commit 2cfe0d3

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

include/linux/compiler-clang.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
*/
1818
#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
1919

20-
#define randomized_struct_fields_start struct {
21-
#define randomized_struct_fields_end };
22-
2320
/* all clang versions usable with the kernel support KASAN ABI version 5 */
2421
#define KASAN_ABI_VERSION 5
2522

include/linux/compiler-gcc.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@
242242
#if defined(RANDSTRUCT_PLUGIN) && !defined(__CHECKER__)
243243
#define __randomize_layout __attribute__((randomize_layout))
244244
#define __no_randomize_layout __attribute__((no_randomize_layout))
245+
/* This anon struct can add padding, so only enable it under randstruct. */
246+
#define randomized_struct_fields_start struct {
247+
#define randomized_struct_fields_end } __randomize_layout;
245248
#endif
246249

247250
#endif /* GCC_VERSION >= 40500 */
@@ -256,15 +259,6 @@
256259
*/
257260
#define __visible __attribute__((externally_visible))
258261

259-
/*
260-
* RANDSTRUCT_PLUGIN wants to use an anonymous struct, but it is only
261-
* possible since GCC 4.6. To provide as much build testing coverage
262-
* as possible, this is used for all GCC 4.6+ builds, and not just on
263-
* RANDSTRUCT_PLUGIN builds.
264-
*/
265-
#define randomized_struct_fields_start struct {
266-
#define randomized_struct_fields_end } __randomize_layout;
267-
268262
#endif /* GCC_VERSION >= 40600 */
269263

270264

0 commit comments

Comments
 (0)