aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Kbuild.include8
-rw-r--r--scripts/Makefile.build2
-rw-r--r--scripts/Makefile.extrawarn3
-rw-r--r--scripts/Makefile.gcc-plugins10
-rwxr-xr-xscripts/faddr2line2
-rw-r--r--scripts/gcc-plugins/Kconfig51
-rw-r--r--scripts/gcc-plugins/stackleak_plugin.c429
-rw-r--r--scripts/kconfig/Makefile16
-rw-r--r--scripts/kconfig/conf.c7
-rwxr-xr-xscripts/kconfig/merge_config.sh11
-rwxr-xr-xscripts/package/builddeb6
-rwxr-xr-xscripts/package/mkdebian7
-rwxr-xr-xscripts/package/mkspec11
-rwxr-xr-xscripts/setlocalversion2
-rwxr-xr-xscripts/spdxcheck.py1
-rw-r--r--scripts/unifdef.c4
16 files changed, 519 insertions, 51 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index ca21a35fa244..bb015551c2d9 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -140,17 +140,9 @@ cc-option-yn = $(call try-run,\
140cc-disable-warning = $(call try-run,\ 140cc-disable-warning = $(call try-run,\
141 $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) 141 $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
142 142
143# cc-name
144# Expands to either gcc or clang
145cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)
146
147# cc-version 143# cc-version
148cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) 144cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
149 145
150# cc-fullversion
151cc-fullversion = $(shell $(CONFIG_SHELL) \
152 $(srctree)/scripts/gcc-version.sh -p $(CC))
153
154# cc-ifversion 146# cc-ifversion
155# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) 147# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
156cc-ifversion = $(shell [ $(cc-version) $(1) $(2) ] && echo $(3) || echo $(4)) 148cc-ifversion = $(shell [ $(cc-version) $(1) $(2) ] && echo $(3) || echo $(4))
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index a8e7ba9f73e8..6a6be9f440cf 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -236,10 +236,8 @@ ifdef CONFIG_GCOV_KERNEL
236objtool_args += --no-unreachable 236objtool_args += --no-unreachable
237endif 237endif
238ifdef CONFIG_RETPOLINE 238ifdef CONFIG_RETPOLINE
239ifneq ($(RETPOLINE_CFLAGS),)
240 objtool_args += --retpoline 239 objtool_args += --retpoline
241endif 240endif
242endif
243 241
244 242
245ifdef CONFIG_MODVERSIONS 243ifdef CONFIG_MODVERSIONS
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 24b2fb1d1297..768306add591 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -29,6 +29,7 @@ warning-1 += $(call cc-option, -Wmissing-include-dirs)
29warning-1 += $(call cc-option, -Wunused-but-set-variable) 29warning-1 += $(call cc-option, -Wunused-but-set-variable)
30warning-1 += $(call cc-option, -Wunused-const-variable) 30warning-1 += $(call cc-option, -Wunused-const-variable)
31warning-1 += $(call cc-option, -Wpacked-not-aligned) 31warning-1 += $(call cc-option, -Wpacked-not-aligned)
32warning-1 += $(call cc-option, -Wstringop-truncation)
32warning-1 += $(call cc-disable-warning, missing-field-initializers) 33warning-1 += $(call cc-disable-warning, missing-field-initializers)
33warning-1 += $(call cc-disable-warning, sign-compare) 34warning-1 += $(call cc-disable-warning, sign-compare)
34 35
@@ -64,7 +65,7 @@ endif
64KBUILD_CFLAGS += $(warning) 65KBUILD_CFLAGS += $(warning)
65else 66else
66 67
67ifeq ($(cc-name),clang) 68ifdef CONFIG_CC_IS_CLANG
68KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides) 69KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
69KBUILD_CFLAGS += $(call cc-disable-warning, unused-value) 70KBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
70KBUILD_CFLAGS += $(call cc-disable-warning, format) 71KBUILD_CFLAGS += $(call cc-disable-warning, format)
diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index 0a482f341576..46c5c6809806 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -26,6 +26,16 @@ gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) \
26gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) \ 26gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) \
27 += -fplugin-arg-randomize_layout_plugin-performance-mode 27 += -fplugin-arg-randomize_layout_plugin-performance-mode
28 28
29gcc-plugin-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak_plugin.so
30gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
31 += -DSTACKLEAK_PLUGIN
32gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
33 += -fplugin-arg-stackleak_plugin-track-min-size=$(CONFIG_STACKLEAK_TRACK_MIN_SIZE)
34ifdef CONFIG_GCC_PLUGIN_STACKLEAK
35 DISABLE_STACKLEAK_PLUGIN += -fplugin-arg-stackleak_plugin-disable
36endif
37export DISABLE_STACKLEAK_PLUGIN
38
29# All the plugin CFLAGS are collected here in case a build target needs to 39# All the plugin CFLAGS are collected here in case a build target needs to
30# filter them out of the KBUILD_CFLAGS. 40# filter them out of the KBUILD_CFLAGS.
31GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) 41GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y))
diff --git a/scripts/faddr2line b/scripts/faddr2line
index a0149db00be7..6c6439f69a72 100755
--- a/scripts/faddr2line
+++ b/scripts/faddr2line
@@ -71,7 +71,7 @@ die() {
71 71
72# Try to figure out the source directory prefix so we can remove it from the 72# Try to figure out the source directory prefix so we can remove it from the
73# addr2line output. HACK ALERT: This assumes that start_kernel() is in 73# addr2line output. HACK ALERT: This assumes that start_kernel() is in
74# kernel/init.c! This only works for vmlinux. Otherwise it falls back to 74# init/main.c! This only works for vmlinux. Otherwise it falls back to
75# printing the absolute path. 75# printing the absolute path.
76find_dir_prefix() { 76find_dir_prefix() {
77 local objfile=$1 77 local objfile=$1
diff --git a/scripts/gcc-plugins/Kconfig b/scripts/gcc-plugins/Kconfig
index cb0c889e13aa..0d5c799688f0 100644
--- a/scripts/gcc-plugins/Kconfig
+++ b/scripts/gcc-plugins/Kconfig
@@ -139,4 +139,55 @@ config GCC_PLUGIN_RANDSTRUCT_PERFORMANCE
139 in structures. This reduces the performance hit of RANDSTRUCT 139 in structures. This reduces the performance hit of RANDSTRUCT
140 at the cost of weakened randomization. 140 at the cost of weakened randomization.
141 141
142config GCC_PLUGIN_STACKLEAK
143 bool "Erase the kernel stack before returning from syscalls"
144 depends on GCC_PLUGINS
145 depends on HAVE_ARCH_STACKLEAK
146 help
147 This option makes the kernel erase the kernel stack before
148 returning from system calls. That reduces the information which
149 kernel stack leak bugs can reveal and blocks some uninitialized
150 stack variable attacks.
151
152 The tradeoff is the performance impact: on a single CPU system kernel
153 compilation sees a 1% slowdown, other systems and workloads may vary
154 and you are advised to test this feature on your expected workload
155 before deploying it.
156
157 This plugin was ported from grsecurity/PaX. More information at:
158 * https://grsecurity.net/
159 * https://pax.grsecurity.net/
160
161config STACKLEAK_TRACK_MIN_SIZE
162 int "Minimum stack frame size of functions tracked by STACKLEAK"
163 default 100
164 range 0 4096
165 depends on GCC_PLUGIN_STACKLEAK
166 help
167 The STACKLEAK gcc plugin instruments the kernel code for tracking
168 the lowest border of the kernel stack (and for some other purposes).
169 It inserts the stackleak_track_stack() call for the functions with
170 a stack frame size greater than or equal to this parameter.
171 If unsure, leave the default value 100.
172
173config STACKLEAK_METRICS
174 bool "Show STACKLEAK metrics in the /proc file system"
175 depends on GCC_PLUGIN_STACKLEAK
176 depends on PROC_FS
177 help
178 If this is set, STACKLEAK metrics for every task are available in
179 the /proc file system. In particular, /proc/<pid>/stack_depth
180 shows the maximum kernel stack consumption for the current and
181 previous syscalls. Although this information is not precise, it
182 can be useful for estimating the STACKLEAK performance impact for
183 your workloads.
184
185config STACKLEAK_RUNTIME_DISABLE
186 bool "Allow runtime disabling of kernel stack erasing"
187 depends on GCC_PLUGIN_STACKLEAK
188 help
189 This option provides 'stack_erasing' sysctl, which can be used in
190 runtime to control kernel stack erasing for kernels built with
191 CONFIG_GCC_PLUGIN_STACKLEAK.
192
142endif 193endif
diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c
new file mode 100644
index 000000000000..dbd37460c573
--- /dev/null
+++ b/scripts/gcc-plugins/stackleak_plugin.c
@@ -0,0 +1,429 @@
1/*
2 * Copyright 2011-2017 by the PaX Team <pageexec@freemail.hu>
3 * Modified by Alexander Popov <alex.popov@linux.com>
4 * Licensed under the GPL v2
5 *
6 * Note: the choice of the license means that the compilation process is
7 * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
8 * but for the kernel it doesn't matter since it doesn't link against
9 * any of the gcc libraries
10 *
11 * This gcc plugin is needed for tracking the lowest border of the kernel stack.
12 * It instruments the kernel code inserting stackleak_track_stack() calls:
13 * - after alloca();
14 * - for the functions with a stack frame size greater than or equal
15 * to the "track-min-size" plugin parameter.
16 *
17 * This plugin is ported from grsecurity/PaX. For more information see:
18 * https://grsecurity.net/
19 * https://pax.grsecurity.net/
20 *
21 * Debugging:
22 * - use fprintf() to stderr, debug_generic_expr(), debug_gimple_stmt(),
23 * print_rtl() and print_simple_rtl();
24 * - add "-fdump-tree-all -fdump-rtl-all" to the plugin CFLAGS in
25 * Makefile.gcc-plugins to see the verbose dumps of the gcc passes;
26 * - use gcc -E to understand the preprocessing shenanigans;
27 * - use gcc with enabled CFG/GIMPLE/SSA verification (--enable-checking).
28 */
29
30#include "gcc-common.h"
31
32__visible int plugin_is_GPL_compatible;
33
34static int track_frame_size = -1;
35static const char track_function[] = "stackleak_track_stack";
36
37/*
38 * Mark these global variables (roots) for gcc garbage collector since
39 * they point to the garbage-collected memory.
40 */
41static GTY(()) tree track_function_decl;
42
43static struct plugin_info stackleak_plugin_info = {
44 .version = "201707101337",
45 .help = "track-min-size=nn\ttrack stack for functions with a stack frame size >= nn bytes\n"
46 "disable\t\tdo not activate the plugin\n"
47};
48
49static void stackleak_add_track_stack(gimple_stmt_iterator *gsi, bool after)
50{
51 gimple stmt;
52 gcall *stackleak_track_stack;
53 cgraph_node_ptr node;
54 int frequency;
55 basic_block bb;
56
57 /* Insert call to void stackleak_track_stack(void) */
58 stmt = gimple_build_call(track_function_decl, 0);
59 stackleak_track_stack = as_a_gcall(stmt);
60 if (after) {
61 gsi_insert_after(gsi, stackleak_track_stack,
62 GSI_CONTINUE_LINKING);
63 } else {
64 gsi_insert_before(gsi, stackleak_track_stack, GSI_SAME_STMT);
65 }
66
67 /* Update the cgraph */
68 bb = gimple_bb(stackleak_track_stack);
69 node = cgraph_get_create_node(track_function_decl);
70 gcc_assert(node);
71 frequency = compute_call_stmt_bb_frequency(current_function_decl, bb);
72 cgraph_create_edge(cgraph_get_node(current_function_decl), node,
73 stackleak_track_stack, bb->count, frequency);
74}
75
76static bool is_alloca(gimple stmt)
77{
78 if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
79 return true;
80
81#if BUILDING_GCC_VERSION >= 4007
82 if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
83 return true;
84#endif
85
86 return false;
87}
88
89/*
90 * Work with the GIMPLE representation of the code. Insert the
91 * stackleak_track_stack() call after alloca() and into the beginning
92 * of the function if it is not instrumented.
93 */
94static unsigned int stackleak_instrument_execute(void)
95{
96 basic_block bb, entry_bb;
97 bool prologue_instrumented = false, is_leaf = true;
98 gimple_stmt_iterator gsi;
99
100 /*
101 * ENTRY_BLOCK_PTR is a basic block which represents possible entry
102 * point of a function. This block does not contain any code and
103 * has a CFG edge to its successor.
104 */
105 gcc_assert(single_succ_p(ENTRY_BLOCK_PTR_FOR_FN(cfun)));
106 entry_bb = single_succ(ENTRY_BLOCK_PTR_FOR_FN(cfun));
107
108 /*
109 * Loop through the GIMPLE statements in each of cfun basic blocks.
110 * cfun is a global variable which represents the function that is
111 * currently processed.
112 */
113 FOR_EACH_BB_FN(bb, cfun) {
114 for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
115 gimple stmt;
116
117 stmt = gsi_stmt(gsi);
118
119 /* Leaf function is a function which makes no calls */
120 if (is_gimple_call(stmt))
121 is_leaf = false;
122
123 if (!is_alloca(stmt))
124 continue;
125
126 /* Insert stackleak_track_stack() call after alloca() */
127 stackleak_add_track_stack(&gsi, true);
128 if (bb == entry_bb)
129 prologue_instrumented = true;
130 }
131 }
132
133 if (prologue_instrumented)
134 return 0;
135
136 /*
137 * Special cases to skip the instrumentation.
138 *
139 * Taking the address of static inline functions materializes them,
140 * but we mustn't instrument some of them as the resulting stack
141 * alignment required by the function call ABI will break other
142 * assumptions regarding the expected (but not otherwise enforced)
143 * register clobbering ABI.
144 *
145 * Case in point: native_save_fl on amd64 when optimized for size
146 * clobbers rdx if it were instrumented here.
147 *
148 * TODO: any more special cases?
149 */
150 if (is_leaf &&
151 !TREE_PUBLIC(current_function_decl) &&
152 DECL_DECLARED_INLINE_P(current_function_decl)) {
153 return 0;
154 }
155
156 if (is_leaf &&
157 !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)),
158 "_paravirt_", 10)) {
159 return 0;
160 }
161
162 /* Insert stackleak_track_stack() call at the function beginning */
163 bb = entry_bb;
164 if (!single_pred_p(bb)) {
165 /* gcc_assert(bb_loop_depth(bb) ||
166 (bb->flags & BB_IRREDUCIBLE_LOOP)); */
167 split_edge(single_succ_edge(ENTRY_BLOCK_PTR_FOR_FN(cfun)));
168 gcc_assert(single_succ_p(ENTRY_BLOCK_PTR_FOR_FN(cfun)));
169 bb = single_succ(ENTRY_BLOCK_PTR_FOR_FN(cfun));
170 }
171 gsi = gsi_after_labels(bb);
172 stackleak_add_track_stack(&gsi, false);
173
174 return 0;
175}
176
177static bool large_stack_frame(void)
178{
179#if BUILDING_GCC_VERSION >= 8000
180 return maybe_ge(get_frame_size(), track_frame_size);
181#else
182 return (get_frame_size() >= track_frame_size);
183#endif
184}
185
186/*
187 * Work with the RTL representation of the code.
188 * Remove the unneeded stackleak_track_stack() calls from the functions
189 * which don't call alloca() and don't have a large enough stack frame size.
190 */
191static unsigned int stackleak_cleanup_execute(void)
192{
193 rtx_insn *insn, *next;
194
195 if (cfun->calls_alloca)
196 return 0;
197
198 if (large_stack_frame())
199 return 0;
200
201 /*
202 * Find stackleak_track_stack() calls. Loop through the chain of insns,
203 * which is an RTL representation of the code for a function.
204 *
205 * The example of a matching insn:
206 * (call_insn 8 4 10 2 (call (mem (symbol_ref ("stackleak_track_stack")
207 * [flags 0x41] <function_decl 0x7f7cd3302a80 stackleak_track_stack>)
208 * [0 stackleak_track_stack S1 A8]) (0)) 675 {*call} (expr_list
209 * (symbol_ref ("stackleak_track_stack") [flags 0x41] <function_decl
210 * 0x7f7cd3302a80 stackleak_track_stack>) (expr_list (0) (nil))) (nil))
211 */
212 for (insn = get_insns(); insn; insn = next) {
213 rtx body;
214
215 next = NEXT_INSN(insn);
216
217 /* Check the expression code of the insn */
218 if (!CALL_P(insn))
219 continue;
220
221 /*
222 * Check the expression code of the insn body, which is an RTL
223 * Expression (RTX) describing the side effect performed by
224 * that insn.
225 */
226 body = PATTERN(insn);
227
228 if (GET_CODE(body) == PARALLEL)
229 body = XVECEXP(body, 0, 0);
230
231 if (GET_CODE(body) != CALL)
232 continue;
233
234 /*
235 * Check the first operand of the call expression. It should
236 * be a mem RTX describing the needed subroutine with a
237 * symbol_ref RTX.
238 */
239 body = XEXP(body, 0);
240 if (GET_CODE(body) != MEM)
241 continue;
242
243 body = XEXP(body, 0);
244 if (GET_CODE(body) != SYMBOL_REF)
245 continue;
246
247 if (SYMBOL_REF_DECL(body) != track_function_decl)
248 continue;
249
250 /* Delete the stackleak_track_stack() call */
251 delete_insn_and_edges(insn);
252#if BUILDING_GCC_VERSION >= 4007 && BUILDING_GCC_VERSION < 8000
253 if (GET_CODE(next) == NOTE &&
254 NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
255 insn = next;
256 next = NEXT_INSN(insn);
257 delete_insn_and_edges(insn);
258 }
259#endif
260 }
261
262 return 0;
263}
264
265static bool stackleak_gate(void)
266{
267 tree section;
268
269 section = lookup_attribute("section",
270 DECL_ATTRIBUTES(current_function_decl));
271 if (section && TREE_VALUE(section)) {
272 section = TREE_VALUE(TREE_VALUE(section));
273
274 if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
275 return false;
276 if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
277 return false;
278 if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
279 return false;
280 if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
281 return false;
282 }
283
284 return track_frame_size >= 0;
285}
286
287/* Build the function declaration for stackleak_track_stack() */
288static void stackleak_start_unit(void *gcc_data __unused,
289 void *user_data __unused)
290{
291 tree fntype;
292
293 /* void stackleak_track_stack(void) */
294 fntype = build_function_type_list(void_type_node, NULL_TREE);
295 track_function_decl = build_fn_decl(track_function, fntype);
296 DECL_ASSEMBLER_NAME(track_function_decl); /* for LTO */
297 TREE_PUBLIC(track_function_decl) = 1;
298 TREE_USED(track_function_decl) = 1;
299 DECL_EXTERNAL(track_function_decl) = 1;
300 DECL_ARTIFICIAL(track_function_decl) = 1;
301 DECL_PRESERVE_P(track_function_decl) = 1;
302}
303
304/*
305 * Pass gate function is a predicate function that gets executed before the
306 * corresponding pass. If the return value is 'true' the pass gets executed,
307 * otherwise, it is skipped.
308 */
309static bool stackleak_instrument_gate(void)
310{
311 return stackleak_gate();
312}
313
314#define PASS_NAME stackleak_instrument
315#define PROPERTIES_REQUIRED PROP_gimple_leh | PROP_cfg
316#define TODO_FLAGS_START TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts
317#define TODO_FLAGS_FINISH TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func \
318 | TODO_update_ssa | TODO_rebuild_cgraph_edges
319#include "gcc-generate-gimple-pass.h"
320
321static bool stackleak_cleanup_gate(void)
322{
323 return stackleak_gate();
324}
325
326#define PASS_NAME stackleak_cleanup
327#define TODO_FLAGS_FINISH TODO_dump_func
328#include "gcc-generate-rtl-pass.h"
329
330/*
331 * Every gcc plugin exports a plugin_init() function that is called right
332 * after the plugin is loaded. This function is responsible for registering
333 * the plugin callbacks and doing other required initialization.
334 */
335__visible int plugin_init(struct plugin_name_args *plugin_info,
336 struct plugin_gcc_version *version)
337{
338 const char * const plugin_name = plugin_info->base_name;
339 const int argc = plugin_info->argc;
340 const struct plugin_argument * const argv = plugin_info->argv;
341 int i = 0;
342
343 /* Extra GGC root tables describing our GTY-ed data */
344 static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
345 {
346 .base = &track_function_decl,
347 .nelt = 1,
348 .stride = sizeof(track_function_decl),
349 .cb = &gt_ggc_mx_tree_node,
350 .pchw = &gt_pch_nx_tree_node
351 },
352 LAST_GGC_ROOT_TAB
353 };
354
355 /*
356 * The stackleak_instrument pass should be executed before the
357 * "optimized" pass, which is the control flow graph cleanup that is
358 * performed just before expanding gcc trees to the RTL. In former
359 * versions of the plugin this new pass was inserted before the
360 * "tree_profile" pass, which is currently called "profile".
361 */
362 PASS_INFO(stackleak_instrument, "optimized", 1,
363 PASS_POS_INSERT_BEFORE);
364
365 /*
366 * The stackleak_cleanup pass should be executed before the "*free_cfg"
367 * pass. It's the moment when the stack frame size is already final,
368 * function prologues and epilogues are generated, and the
369 * machine-dependent code transformations are not done.
370 */
371 PASS_INFO(stackleak_cleanup, "*free_cfg", 1, PASS_POS_INSERT_BEFORE);
372
373 if (!plugin_default_version_check(version, &gcc_version)) {
374 error(G_("incompatible gcc/plugin versions"));
375 return 1;
376 }
377
378 /* Parse the plugin arguments */
379 for (i = 0; i < argc; i++) {
380 if (!strcmp(argv[i].key, "disable"))
381 return 0;
382
383 if (!strcmp(argv[i].key, "track-min-size")) {
384 if (!argv[i].value) {
385 error(G_("no value supplied for option '-fplugin-arg-%s-%s'"),
386 plugin_name, argv[i].key);
387 return 1;
388 }
389
390 track_frame_size = atoi(argv[i].value);
391 if (track_frame_size < 0) {
392 error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"),
393 plugin_name, argv[i].key, argv[i].value);
394 return 1;
395 }
396 } else {
397 error(G_("unknown option '-fplugin-arg-%s-%s'"),
398 plugin_name, argv[i].key);
399 return 1;
400 }
401 }
402
403 /* Give the information about the plugin */
404 register_callback(plugin_name, PLUGIN_INFO, NULL,
405 &stackleak_plugin_info);
406
407 /* Register to be called before processing a translation unit */
408 register_callback(plugin_name, PLUGIN_START_UNIT,
409 &stackleak_start_unit, NULL);
410
411 /* Register an extra GCC garbage collector (GGC) root table */
412 register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL,
413 (void *)&gt_ggc_r_gt_stackleak);
414
415 /*
416 * Hook into the Pass Manager to register new gcc passes.
417 *
418 * The stack frame size info is available only at the last RTL pass,
419 * when it's too late to insert complex code like a function call.
420 * So we register two gcc passes to instrument every function at first
421 * and remove the unneeded instrumentation later.
422 */
423 register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL,
424 &stackleak_instrument_pass_info);
425 register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL,
426 &stackleak_cleanup_pass_info);
427
428 return 0;
429}
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 67ed9f6ccdf8..63b609243d03 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -68,21 +68,7 @@ PHONY += $(simple-targets)
68$(simple-targets): $(obj)/conf 68$(simple-targets): $(obj)/conf
69 $< $(silent) --$@ $(Kconfig) 69 $< $(silent) --$@ $(Kconfig)
70 70
71PHONY += oldnoconfig silentoldconfig savedefconfig defconfig 71PHONY += savedefconfig defconfig
72
73# oldnoconfig is an alias of olddefconfig, because people already are dependent
74# on its behavior (sets new symbols to their default value but not 'n') with the
75# counter-intuitive name.
76oldnoconfig: olddefconfig
77 @echo " WARNING: \"oldnoconfig\" target will be removed after Linux 4.19"
78 @echo " Please use \"olddefconfig\" instead, which is an alias."
79
80# We do not expect manual invokcation of "silentoldcofig" (or "syncconfig").
81silentoldconfig: syncconfig
82 @echo " WARNING: \"silentoldconfig\" has been renamed to \"syncconfig\""
83 @echo " and is now an internal implementation detail."
84 @echo " What you want is probably \"oldconfig\"."
85 @echo " \"silentoldconfig\" will be removed after Linux 4.19"
86 72
87savedefconfig: $(obj)/conf 73savedefconfig: $(obj)/conf
88 $< $(silent) --$@=defconfig $(Kconfig) 74 $< $(silent) --$@=defconfig $(Kconfig)
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 7b2b37260669..98e0c7a34699 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -460,12 +460,6 @@ static struct option long_opts[] = {
460 {"randconfig", no_argument, NULL, randconfig}, 460 {"randconfig", no_argument, NULL, randconfig},
461 {"listnewconfig", no_argument, NULL, listnewconfig}, 461 {"listnewconfig", no_argument, NULL, listnewconfig},
462 {"olddefconfig", no_argument, NULL, olddefconfig}, 462 {"olddefconfig", no_argument, NULL, olddefconfig},
463 /*
464 * oldnoconfig is an alias of olddefconfig, because people already
465 * are dependent on its behavior(sets new symbols to their default
466 * value but not 'n') with the counter-intuitive name.
467 */
468 {"oldnoconfig", no_argument, NULL, olddefconfig},
469 {NULL, 0, NULL, 0} 463 {NULL, 0, NULL, 0}
470}; 464};
471 465
@@ -480,7 +474,6 @@ static void conf_usage(const char *progname)
480 printf(" --syncconfig Similar to oldconfig but generates configuration in\n" 474 printf(" --syncconfig Similar to oldconfig but generates configuration in\n"
481 " include/{generated/,config/}\n"); 475 " include/{generated/,config/}\n");
482 printf(" --olddefconfig Same as oldconfig but sets new symbols to their default value\n"); 476 printf(" --olddefconfig Same as oldconfig but sets new symbols to their default value\n");
483 printf(" --oldnoconfig An alias of olddefconfig\n");
484 printf(" --defconfig <file> New config with default defined in <file>\n"); 477 printf(" --defconfig <file> New config with default defined in <file>\n");
485 printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n"); 478 printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n");
486 printf(" --allnoconfig New config where all options are answered with no\n"); 479 printf(" --allnoconfig New config where all options are answered with no\n");
diff --git a/scripts/kconfig/merge_config.sh b/scripts/kconfig/merge_config.sh
index 67d131447631..0ef906499646 100755
--- a/scripts/kconfig/merge_config.sh
+++ b/scripts/kconfig/merge_config.sh
@@ -33,12 +33,15 @@ usage() {
33 echo " -n use allnoconfig instead of alldefconfig" 33 echo " -n use allnoconfig instead of alldefconfig"
34 echo " -r list redundant entries when merging fragments" 34 echo " -r list redundant entries when merging fragments"
35 echo " -O dir to put generated output files. Consider setting \$KCONFIG_CONFIG instead." 35 echo " -O dir to put generated output files. Consider setting \$KCONFIG_CONFIG instead."
36 echo
37 echo "Used prefix: '$CONFIG_PREFIX'. You can redefine it with \$CONFIG_ environment variable."
36} 38}
37 39
38RUNMAKE=true 40RUNMAKE=true
39ALLTARGET=alldefconfig 41ALLTARGET=alldefconfig
40WARNREDUN=false 42WARNREDUN=false
41OUTPUT=. 43OUTPUT=.
44CONFIG_PREFIX=${CONFIG_-CONFIG_}
42 45
43while true; do 46while true; do
44 case $1 in 47 case $1 in
@@ -99,7 +102,9 @@ if [ ! -r "$INITFILE" ]; then
99fi 102fi
100 103
101MERGE_LIST=$* 104MERGE_LIST=$*
102SED_CONFIG_EXP="s/^\(# \)\{0,1\}\(CONFIG_[a-zA-Z0-9_]*\)[= ].*/\2/p" 105SED_CONFIG_EXP1="s/^\(${CONFIG_PREFIX}[a-zA-Z0-9_]*\)=.*/\1/p"
106SED_CONFIG_EXP2="s/^# \(${CONFIG_PREFIX}[a-zA-Z0-9_]*\) is not set$/\1/p"
107
103TMP_FILE=$(mktemp ./.tmp.config.XXXXXXXXXX) 108TMP_FILE=$(mktemp ./.tmp.config.XXXXXXXXXX)
104 109
105echo "Using $INITFILE as base" 110echo "Using $INITFILE as base"
@@ -112,7 +117,7 @@ for MERGE_FILE in $MERGE_LIST ; do
112 echo "The merge file '$MERGE_FILE' does not exist. Exit." >&2 117 echo "The merge file '$MERGE_FILE' does not exist. Exit." >&2
113 exit 1 118 exit 1
114 fi 119 fi
115 CFG_LIST=$(sed -n "$SED_CONFIG_EXP" $MERGE_FILE) 120 CFG_LIST=$(sed -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $MERGE_FILE)
116 121
117 for CFG in $CFG_LIST ; do 122 for CFG in $CFG_LIST ; do
118 grep -q -w $CFG $TMP_FILE || continue 123 grep -q -w $CFG $TMP_FILE || continue
@@ -155,7 +160,7 @@ make KCONFIG_ALLCONFIG=$TMP_FILE $OUTPUT_ARG $ALLTARGET
155 160
156 161
157# Check all specified config values took (might have missed-dependency issues) 162# Check all specified config values took (might have missed-dependency issues)
158for CFG in $(sed -n "$SED_CONFIG_EXP" $TMP_FILE); do 163for CFG in $(sed -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $TMP_FILE); do
159 164
160 REQUESTED_VAL=$(grep -w -e "$CFG" $TMP_FILE) 165 REQUESTED_VAL=$(grep -w -e "$CFG" $TMP_FILE)
161 ACTUAL_VAL=$(grep -w -e "$CFG" "$KCONFIG_CONFIG") 166 ACTUAL_VAL=$(grep -w -e "$CFG" "$KCONFIG_CONFIG")
diff --git a/scripts/package/builddeb b/scripts/package/builddeb
index 90c9a8ac7adb..f43a274f4f1d 100755
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -81,11 +81,11 @@ else
81 cp System.map "$tmpdir/boot/System.map-$version" 81 cp System.map "$tmpdir/boot/System.map-$version"
82 cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version" 82 cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version"
83fi 83fi
84cp "$($MAKE -s image_name)" "$tmpdir/$installed_image_path" 84cp "$($MAKE -s -f $srctree/Makefile image_name)" "$tmpdir/$installed_image_path"
85 85
86if grep -q "^CONFIG_OF=y" $KCONFIG_CONFIG ; then 86if grep -q "^CONFIG_OF_EARLY_FLATTREE=y" $KCONFIG_CONFIG ; then
87 # Only some architectures with OF support have this target 87 # Only some architectures with OF support have this target
88 if grep -q dtbs_install "${srctree}/arch/$SRCARCH/Makefile"; then 88 if [ -d "${srctree}/arch/$SRCARCH/boot/dts" ]; then
89 $MAKE KBUILD_SRC= INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install 89 $MAKE KBUILD_SRC= INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install
90 fi 90 fi
91fi 91fi
diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian
index 663a7f343b42..edcad61fe3cd 100755
--- a/scripts/package/mkdebian
+++ b/scripts/package/mkdebian
@@ -88,6 +88,7 @@ set_debarch() {
88version=$KERNELRELEASE 88version=$KERNELRELEASE
89if [ -n "$KDEB_PKGVERSION" ]; then 89if [ -n "$KDEB_PKGVERSION" ]; then
90 packageversion=$KDEB_PKGVERSION 90 packageversion=$KDEB_PKGVERSION
91 revision=${packageversion##*-}
91else 92else
92 revision=$(cat .version 2>/dev/null||echo 1) 93 revision=$(cat .version 2>/dev/null||echo 1)
93 packageversion=$version-$revision 94 packageversion=$version-$revision
@@ -205,10 +206,12 @@ cat <<EOF > debian/rules
205#!$(command -v $MAKE) -f 206#!$(command -v $MAKE) -f
206 207
207build: 208build:
208 \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC= 209 \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \
210 KBUILD_BUILD_VERSION=${revision} KBUILD_SRC=
209 211
210binary-arch: 212binary-arch:
211 \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC= intdeb-pkg 213 \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \
214 KBUILD_BUILD_VERSION=${revision} KBUILD_SRC= intdeb-pkg
212 215
213clean: 216clean:
214 rm -rf debian/*tmp debian/files 217 rm -rf debian/*tmp debian/files
diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index e05646dc24dc..009147d4718e 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -12,6 +12,7 @@
12# how we were called determines which rpms we build and how we build them 12# how we were called determines which rpms we build and how we build them
13if [ "$1" = prebuilt ]; then 13if [ "$1" = prebuilt ]; then
14 S=DEL 14 S=DEL
15 MAKE="$MAKE -f $srctree/Makefile"
15else 16else
16 S= 17 S=
17fi 18fi
@@ -78,19 +79,19 @@ $S %prep
78$S %setup -q 79$S %setup -q
79$S 80$S
80$S %build 81$S %build
81$S make %{?_smp_mflags} KBUILD_BUILD_VERSION=%{release} 82$S $MAKE %{?_smp_mflags} KBUILD_BUILD_VERSION=%{release}
82$S 83$S
83 %install 84 %install
84 mkdir -p %{buildroot}/boot 85 mkdir -p %{buildroot}/boot
85 %ifarch ia64 86 %ifarch ia64
86 mkdir -p %{buildroot}/boot/efi 87 mkdir -p %{buildroot}/boot/efi
87 cp \$(make image_name) %{buildroot}/boot/efi/vmlinuz-$KERNELRELEASE 88 cp \$($MAKE image_name) %{buildroot}/boot/efi/vmlinuz-$KERNELRELEASE
88 ln -s efi/vmlinuz-$KERNELRELEASE %{buildroot}/boot/ 89 ln -s efi/vmlinuz-$KERNELRELEASE %{buildroot}/boot/
89 %else 90 %else
90 cp \$(make image_name) %{buildroot}/boot/vmlinuz-$KERNELRELEASE 91 cp \$($MAKE image_name) %{buildroot}/boot/vmlinuz-$KERNELRELEASE
91 %endif 92 %endif
92$M make %{?_smp_mflags} INSTALL_MOD_PATH=%{buildroot} KBUILD_SRC= modules_install 93$M $MAKE %{?_smp_mflags} INSTALL_MOD_PATH=%{buildroot} modules_install
93 make %{?_smp_mflags} INSTALL_HDR_PATH=%{buildroot}/usr KBUILD_SRC= headers_install 94 $MAKE %{?_smp_mflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
94 cp System.map %{buildroot}/boot/System.map-$KERNELRELEASE 95 cp System.map %{buildroot}/boot/System.map-$KERNELRELEASE
95 cp .config %{buildroot}/boot/config-$KERNELRELEASE 96 cp .config %{buildroot}/boot/config-$KERNELRELEASE
96 bzip2 -9 --keep vmlinux 97 bzip2 -9 --keep vmlinux
diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 79f7dd57d571..71f39410691b 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -74,7 +74,7 @@ scm_version()
74 fi 74 fi
75 75
76 # Check for uncommitted changes 76 # Check for uncommitted changes
77 if git status -uno --porcelain | grep -qv '^.. scripts/package'; then 77 if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
78 printf '%s' -dirty 78 printf '%s' -dirty
79 fi 79 fi
80 80
diff --git a/scripts/spdxcheck.py b/scripts/spdxcheck.py
index 839e190bbd7a..5056fb3b897d 100755
--- a/scripts/spdxcheck.py
+++ b/scripts/spdxcheck.py
@@ -168,7 +168,6 @@ class id_parser(object):
168 self.curline = 0 168 self.curline = 0
169 try: 169 try:
170 for line in fd: 170 for line in fd:
171 line = line.decode(locale.getpreferredencoding(False), errors='ignore')
172 self.curline += 1 171 self.curline += 1
173 if self.curline > maxlines: 172 if self.curline > maxlines:
174 break 173 break
diff --git a/scripts/unifdef.c b/scripts/unifdef.c
index 7493c0ee51cc..db00e3e30a59 100644
--- a/scripts/unifdef.c
+++ b/scripts/unifdef.c
@@ -395,7 +395,7 @@ usage(void)
395 * When we have processed a group that starts off with a known-false 395 * When we have processed a group that starts off with a known-false
396 * #if/#elif sequence (which has therefore been deleted) followed by a 396 * #if/#elif sequence (which has therefore been deleted) followed by a
397 * #elif that we don't understand and therefore must keep, we edit the 397 * #elif that we don't understand and therefore must keep, we edit the
398 * latter into a #if to keep the nesting correct. We use strncpy() to 398 * latter into a #if to keep the nesting correct. We use memcpy() to
399 * overwrite the 4 byte token "elif" with "if " without a '\0' byte. 399 * overwrite the 4 byte token "elif" with "if " without a '\0' byte.
400 * 400 *
401 * When we find a true #elif in a group, the following block will 401 * When we find a true #elif in a group, the following block will
@@ -450,7 +450,7 @@ static void Idrop (void) { Fdrop(); ignoreon(); }
450static void Itrue (void) { Ftrue(); ignoreon(); } 450static void Itrue (void) { Ftrue(); ignoreon(); }
451static void Ifalse(void) { Ffalse(); ignoreon(); } 451static void Ifalse(void) { Ffalse(); ignoreon(); }
452/* modify this line */ 452/* modify this line */
453static void Mpass (void) { strncpy(keyword, "if ", 4); Pelif(); } 453static void Mpass (void) { memcpy(keyword, "if ", 4); Pelif(); }
454static void Mtrue (void) { keywordedit("else"); state(IS_TRUE_MIDDLE); } 454static void Mtrue (void) { keywordedit("else"); state(IS_TRUE_MIDDLE); }
455static void Melif (void) { keywordedit("endif"); state(IS_FALSE_TRAILER); } 455static void Melif (void) { keywordedit("endif"); state(IS_FALSE_TRAILER); }
456static void Melse (void) { keywordedit("endif"); state(IS_FALSE_ELSE); } 456static void Melse (void) { keywordedit("endif"); state(IS_FALSE_ELSE); }