objtool: Make stack validation optional
authorJosh Poimboeuf <jpoimboe@redhat.com>
Mon, 18 Apr 2022 16:50:33 +0000 (09:50 -0700)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 22 Apr 2022 10:32:02 +0000 (12:32 +0200)
Make stack validation an explicit cmdline option so that individual
objtool features can be enabled individually by other arches.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Link: https://lkml.kernel.org/r/52da143699574d756e65ca4c9d4acaffe9b0fe5f.1650300597.git.jpoimboe@redhat.com
scripts/Makefile.build
scripts/link-vmlinux.sh
tools/objtool/builtin-check.c
tools/objtool/check.c
tools/objtool/include/objtool/builtin.h

index 116c7272b41c0fb2102a1db0e9bba84979f20ae3..d5e15ae291568bd0b9429994ede908bd753ddf3b 100644 (file)
@@ -232,6 +232,7 @@ objtool_args =                                                              \
        $(if $(CONFIG_UNWINDER_ORC), --orc)                             \
        $(if $(CONFIG_RETPOLINE), --retpoline)                          \
        $(if $(CONFIG_SLS), --sls)                                      \
+       $(if $(CONFIG_STACK_VALIDATION), --stackval)                    \
        $(if $(CONFIG_X86_SMAP), --uaccess)                             \
        $(if $(part-of-module), --module)                               \
        $(if $(CONFIG_FRAME_POINTER),, --no-fp)                         \
index f6db79b11573689c5b27a85f6184f82dad7a574b..0140bfa32c0cedd82f73750a7d51d829a9c9795b 100755 (executable)
@@ -126,6 +126,10 @@ objtool_link()
                        objtoolopt="${objtoolopt} --orc"
                fi
 
+               if is_enabled CONFIG_STACK_VALIDATION; then
+                       objtoolopt="${objtoolopt} --stackval"
+               fi
+
                objtoolopt="${objtoolopt} --lto"
        fi
 
index 6acfebd2c6ca1ad4e55778af22195ec6a07d2f70..d4e6930ad0a08d9161bec800287ceb0e09e94de9 100644 (file)
@@ -39,6 +39,7 @@ const struct option check_options[] = {
        OPT_BOOLEAN('o', "orc", &opts.orc, "generate ORC metadata"),
        OPT_BOOLEAN('r', "retpoline", &opts.retpoline, "validate and annotate retpoline usage"),
        OPT_BOOLEAN('l', "sls", &opts.sls, "validate straight-line-speculation mitigations"),
+       OPT_BOOLEAN('s', "stackval", &opts.stackval, "validate stack unwinding rules"),
        OPT_BOOLEAN('u', "uaccess", &opts.uaccess, "validate uaccess rules for SMAP"),
        OPT_CALLBACK_OPTARG(0, "dump", NULL, NULL, "orc", "dump metadata", parse_dump),
 
@@ -92,6 +93,7 @@ static bool opts_valid(void)
            opts.orc            ||
            opts.retpoline      ||
            opts.sls            ||
+           opts.stackval       ||
            opts.uaccess) {
                if (opts.dump_orc) {
                        fprintf(stderr, "--dump can't be combined with other options\n");
index 16a6c4b4f6bbca7f2ac0e09e651581e55918becc..3456eb99b06eeb77fff8bf6b2e065535b3fa226f 100644 (file)
@@ -3899,25 +3899,27 @@ int check(struct objtool_file *file)
                warnings += ret;
        }
 
-       ret = validate_functions(file);
-       if (ret < 0)
-               goto out;
-       warnings += ret;
-
-       ret = validate_unwind_hints(file, NULL);
-       if (ret < 0)
-               goto out;
-       warnings += ret;
+       if (opts.stackval || opts.orc || opts.uaccess || opts.ibt || opts.sls) {
+               ret = validate_functions(file);
+               if (ret < 0)
+                       goto out;
+               warnings += ret;
 
-       if (opts.ibt) {
-               ret = validate_ibt(file);
+               ret = validate_unwind_hints(file, NULL);
                if (ret < 0)
                        goto out;
                warnings += ret;
+
+               if (!warnings) {
+                       ret = validate_reachable_instructions(file);
+                       if (ret < 0)
+                               goto out;
+                       warnings += ret;
+               }
        }
 
-       if (!warnings) {
-               ret = validate_reachable_instructions(file);
+       if (opts.ibt) {
+               ret = validate_ibt(file);
                if (ret < 0)
                        goto out;
                warnings += ret;
index e0972fbfa09eca9362d07ce15c755a14d455b4ac..8618585bb742ccfffeca1a0a1f645329774374fd 100644 (file)
@@ -18,6 +18,7 @@ struct opts {
        bool orc;
        bool retpoline;
        bool sls;
+       bool stackval;
        bool uaccess;
 
        /* options: */