Skip to content

Commit 6337067

Browse files
keesgregkh
authored andcommitted
task_struct: only use anon struct under randstruct plugin
commit 2cfe0d3 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 28cb085 commit 6337067

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
/* Clang doesn't have a way to turn it off per-function, yet. */
2421
#ifdef __noretpoline
2522
#undef __noretpoline

include/linux/compiler-gcc.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@
229229
#ifdef RANDSTRUCT_PLUGIN
230230
#define __randomize_layout __attribute__((randomize_layout))
231231
#define __no_randomize_layout __attribute__((no_randomize_layout))
232+
/* This anon struct can add padding, so only enable it under randstruct. */
233+
#define randomized_struct_fields_start struct {
234+
#define randomized_struct_fields_end } __randomize_layout;
232235
#endif
233236

234237
#endif /* GCC_VERSION >= 40500 */
@@ -243,15 +246,6 @@
243246
*/
244247
#define __visible __attribute__((externally_visible))
245248

246-
/*
247-
* RANDSTRUCT_PLUGIN wants to use an anonymous struct, but it is only
248-
* possible since GCC 4.6. To provide as much build testing coverage
249-
* as possible, this is used for all GCC 4.6+ builds, and not just on
250-
* RANDSTRUCT_PLUGIN builds.
251-
*/
252-
#define randomized_struct_fields_start struct {
253-
#define randomized_struct_fields_end } __randomize_layout;
254-
255249
#endif /* GCC_VERSION >= 40600 */
256250

257251

0 commit comments

Comments
 (0)