objtool: Interface overhaul
Subsystems (11)
v2 cover objtool: Interface overhaul
v2:
- extricate sls
- fix ibt regressions in v1
- fix issues found by improved ibt logic
- split '--hacks' into two
- add objdump-func script
- remove "()" in function address strings
- add '--sec-address' option
- add '--link'
Objtool's interface has some issues:
- Several features are done unconditionally, without any way to turn them off. Some of them might be surprising. This makes objtool tricky to use, and prevents porting individual features to other arches.
- The config dependencies are too coarse-grained. Objtool enablement is tied to CONFIG_STACK_VALIDATION, but it has several other features independent of that.
- The objtool subcmds ("check" and "orc") are clumsy: "check" is really a subset of "orc", so it has all the same options. The subcmd model has never really worked for objtool, as it only has a single purpose:
"do some combination of things on an object file".
- The '--lto' and '--vmlinux' options are nonsensical and have surprising behavior.
Overhaul the interface:
- get rid of subcmds
- make all features individually selectable
- remove and/or clarify confusing/obsolete options
- update the documentation
- fix some bugs found along the way
TODO: rename files...
$ tools/objtool/objtool --help
Usage: objtool <actions> [<options>] file.o
Actions:
-h, --hacks[=<jump_label,noinstr>]
patch toolchain bugs/limitations
-i, --ibt validate and annotate IBT
-l, --sls validate straight-line-speculation mitigations
-m, --mcount annotate mcount/fentry calls for ftrace
-n, --noinstr validate noinstr rules
-o, --orc generate ORC metadata
-r, --retpoline validate and annotate retpoline usage
-s, --stackval validate frame pointer rules
-t, --static-call annotate static calls
-u, --uaccess validate uaccess rules for SMAP
--dump[=<orc>] dump metadataOptions:
--backtrace unwind on error
--backup create .orig files before modification
--dry-run don't write modifications
--link object is a linked object
--module object is part of a kernel module
--no-unreachable skip 'unreachable instruction' warnings
--sec-address print section addresses in warnings
--stats print statisticsJosh Poimboeuf (25):
objtool: Enable unreachable warnings for CLANG LTO
libsubcmd: Fix OPTION_GROUP sorting
x86/static_call: Add ANNOTATE_NOENDBR to static call trampoline x86/retpoline: Add ANNOTATE_ENDBR for retpolines x86/uaccess: Add ENDBR to __put_user_nocheck*() x86/xen: Add ANNOTATE_ENDBR to startup_xen()
objtool: Reorganize cmdline options
objtool: Ditch subcommands
objtool: Don't print parentheses in function addresses
objtool: Print data address for "!ENDBR" data warnings
objtool: Use offstr() to print address of missing ENDBR
objtool: Add option to print section addresses
scripts: Create objdump-func helper script
objtool: Make stack validation optional
objtool: Rework ibt and extricate from stack validation
objtool: Extricate sls from stack validation
objtool: Add CONFIG_OBJTOOL
objtool: Make stack validation frame-pointer-specific
objtool: Make static call annotation optional
objtool: Make jump label hack optional
objtool: Make noinstr hacks optional
objtool: Rename "VMLINUX_VALIDATION" -> "NOINSTR_VALIDATION"
objtool: Add HAVE_NOINSTR_VALIDATION
objtool: Remove --lto and --vmlinux in favor of --link
objtool: Update documentation
Makefile | 2 +-
arch/Kconfig | 18 +-
arch/x86/Kconfig | 21 +-
arch/x86/Kconfig.debug | 2 +-
arch/x86/include/asm/jump_label.h | 6 +-
arch/x86/include/asm/static_call.h | 1 +
arch/x86/kernel/alternative.c | 6 +-
arch/x86/lib/putuser.S | 4 +
arch/x86/lib/retpoline.S | 2 +-
arch/x86/xen/xen-head.S | 1 +
include/linux/compiler.h | 6 +-
include/linux/instrumentation.h | 6 +-
include/linux/objtool.h | 6 +-
kernel/trace/Kconfig | 1 +
lib/Kconfig.debug | 22 +-
lib/Kconfig.kcsan | 4 +-
lib/Kconfig.ubsan | 2 +-
scripts/Makefile.build | 23 +-
scripts/link-vmlinux.sh | 66 ++-
scripts/objdump-func | 18 +
scripts/package/builddeb | 2 +-
tools/include/linux/objtool.h | 6 +-
tools/lib/subcmd/parse-options.c | 17 +-
tools/objtool/Build | 12 +-
.../{stack-validation.txt => objtool.txt} | 122 ++++-
tools/objtool/Makefile | 8 +-
tools/objtool/arch/x86/decode.c | 2 +-
tools/objtool/arch/x86/special.c | 2 +-
tools/objtool/builtin-check.c | 156 ++++--
tools/objtool/builtin-orc.c | 73 ---
tools/objtool/check.c | 456 ++++++++++--------
tools/objtool/elf.c | 11 +-
tools/objtool/include/objtool/builtin.h | 34 +-
tools/objtool/include/objtool/elf.h | 12 +-
tools/objtool/include/objtool/warn.h | 35 +-
tools/objtool/objtool.c | 103 +---
tools/objtool/weak.c | 9 +-
37 files changed, 719 insertions(+), 558 deletions(-)
create mode 100755 scripts/objdump-func
rename tools/objtool/Documentation/{stack-validation.txt => objtool.txt} (80%)
delete mode 100644 tools/objtool/builtin-orc.cSignature · 1 line
2.34.1
PATCH v2 1/25 objtool: Enable unreachable warnings for CLANG LTO
With IBT support in, objtool is now fully capable of following vmlinux code flow in LTO mode. Start reporting unreachable warnings for Clang LTO as well.
--- scripts/Makefile.build | 2 +- scripts/link-vmlinux.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
scripts/Makefile.build +1 -1
@@ -231,7 +231,7 @@ objtool_args = \ $(if $(part-of-module), --module) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ - $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\ + $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
scripts/link-vmlinux.sh +1 -1
@@ -140,7 +140,7 @@ objtool_link() if ! is_enabled CONFIG_FRAME_POINTER; then objtoolopt="${objtoolopt} --no-fp" fi - if is_enabled CONFIG_GCOV_KERNEL || is_enabled CONFIG_LTO_CLANG; then + if is_enabled CONFIG_GCOV_KERNEL; then objtoolopt="${objtoolopt} --no-unreachable" fi if is_enabled CONFIG_RETPOLINE; then
Signature · 1 line
2.34.1
[tip: x86/urgent] objtool: Enable unreachable warnings for CLANG LTO
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 4a5de9b76fcb3f477f73d5a63f6e27709e8af81f Gitweb: https://git.kernel.org/tip/4a5de9b76fcb3f477f73d5a63f6e27709e8af81f Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:20 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 19 Apr 2022 21:58:48 +02:00
objtool: Enable unreachable warnings for CLANG LTO
With IBT support in, objtool is now fully capable of following vmlinux code flow in LTO mode. Start reporting unreachable warnings for Clang LTO as well.
--- scripts/Makefile.build | 2 +- scripts/link-vmlinux.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
scripts/Makefile.build +1 -1
@@ -231,7 +231,7 @@ objtool_args = \ $(if $(part-of-module), --module) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ - $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\ + $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
scripts/link-vmlinux.sh +1 -1
@@ -140,7 +140,7 @@ objtool_link() if ! is_enabled CONFIG_FRAME_POINTER; then objtoolopt="${objtoolopt} --no-fp" fi - if is_enabled CONFIG_GCOV_KERNEL || is_enabled CONFIG_LTO_CLANG; then + if is_enabled CONFIG_GCOV_KERNEL; then objtoolopt="${objtoolopt} --no-unreachable" fi if is_enabled CONFIG_RETPOLINE; then
PATCH v2 2/25 libsubcmd: Fix OPTION_GROUP sorting
In reply to Josh PoimboeufThe OPTION_GROUP option type is a way of grouping certain options together in the printed usage text. It happens to be completely broken, thanks to the fact that the subcmd option sorting just sorts everything, without regard for grouping. Luckily, nobody uses this option anyway, though that will change shortly.
Fix it by sorting each group individually.
--- tools/lib/subcmd/parse-options.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
tools/lib/subcmd/parse-options.c +14 -3
@@ -806,9 +806,9 @@ static int option__cmp(const void *va, const void *vb)static struct option *options__order (const struct option *opts) { -int nr_opts =0 , len; +int nr_opts =0 , nr_group =0 , len;const struct option *o = opts; -struct option *ordered; +struct option *opt, *ordered, *group;for (o = opts; o->type !=OPTION_END ; o++) ++nr_opts;
@@ -819,7 +819,18 @@ static struct option *options__order(const struct option *opts) goto out;memcpy (ordered, opts, len); -qsort (ordered, nr_opts,sizeof (*o), option__cmp); +/* sort each option group individually */ +for (opt = group = ordered; opt->type !=OPTION_END ; opt++) { +if (opt->type ==OPTION_GROUP ) { +qsort (group, nr_group,sizeof (*opt), option__cmp); + group = opt +1 ; + nr_group =0 ; +continue ; + } + nr_group++; + } +qsort (group, nr_group,sizeof (*opt), option__cmp); + out:return ordered; }
Signature · 1 line
2.34.1
[tip: objtool/core] libsubcmd: Fix OPTION_GROUP sorting
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: aa3d60e050112ef1373d7216eabe0ee966615527 Gitweb: https://git.kernel.org/tip/aa3d60e050112ef1373d7216eabe0ee966615527 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:21 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:01 +02:00
libsubcmd: Fix OPTION_GROUP sorting
The OPTION_GROUP option type is a way of grouping certain options together in the printed usage text. It happens to be completely broken, thanks to the fact that the subcmd option sorting just sorts everything, without regard for grouping. Luckily, nobody uses this option anyway, though that will change shortly.
Fix it by sorting each group individually.
--- tools/lib/subcmd/parse-options.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
tools/lib/subcmd/parse-options.c +14 -3
@@ -806,9 +806,9 @@ static int option__cmp(const void *va, const void *vb)static struct option *options__order (const struct option *opts) { -int nr_opts =0 , len; +int nr_opts =0 , nr_group =0 , len;const struct option *o = opts; -struct option *ordered; +struct option *opt, *ordered, *group;for (o = opts; o->type !=OPTION_END ; o++) ++nr_opts;
@@ -819,7 +819,18 @@ static struct option *options__order(const struct option *opts) goto out;memcpy (ordered, opts, len); -qsort (ordered, nr_opts,sizeof (*o), option__cmp); +/* sort each option group individually */ +for (opt = group = ordered; opt->type !=OPTION_END ; opt++) { +if (opt->type ==OPTION_GROUP ) { +qsort (group, nr_group,sizeof (*opt), option__cmp); + group = opt +1 ; + nr_group =0 ; +continue ; + } + nr_group++; + } +qsort (group, nr_group,sizeof (*opt), option__cmp); + out:return ordered; }
PATCH v2 3/25 x86/static_call: Add ANNOTATE_NOENDBR to static call trampoline
In reply to Josh PoimboeufThe static call trampoline is never indirect-branched to, but is referenced by the static call key. Add ANNOTATE_NOENDBR.
--- arch/x86/include/asm/static_call.h | 1 + 1 file changed, 1 insertion(+)
arch/x86/include/asm/static_call.h +1 -0
@@ -26,6 +26,7 @@".align 4 \n" \ ".globl " STATIC_CALL_TRAMP_STR(name) " \n" \ STATIC_CALL_TRAMP_STR(name) ": \n" \ +ANNOTATE_NOENDBR \ insns" \n" \".byte 0x53, 0x43, 0x54 \n" \ ".type " STATIC_CALL_TRAMP_STR(name) ", @function \n" \
Signature · 1 line
2.34.1
[tip: x86/urgent] x86/static_call: Add ANNOTATE_NOENDBR to static call trampoline
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 613871cd665ab26290c5ff531dd06c3789d31319 Gitweb: https://git.kernel.org/tip/613871cd665ab26290c5ff531dd06c3789d31319 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:22 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 19 Apr 2022 21:58:48 +02:00
x86/static_call: Add ANNOTATE_NOENDBR to static call trampoline
The static call trampoline is never indirect-branched to, but is referenced by the static call key. Add ANNOTATE_NOENDBR.
--- arch/x86/include/asm/static_call.h | 1 + 1 file changed, 1 insertion(+)
arch/x86/include/asm/static_call.h +1 -0
@@ -26,6 +26,7 @@".align 4 \n" \ ".globl " STATIC_CALL_TRAMP_STR(name) " \n" \ STATIC_CALL_TRAMP_STR(name) ": \n" \ +ANNOTATE_NOENDBR \ insns" \n" \".byte 0x53, 0x43, 0x54 \n" \ ".type " STATIC_CALL_TRAMP_STR(name) ", @function \n" \
PATCH v2 4/25 x86/retpoline: Add ANNOTATE_ENDBR for retpolines
In reply to Josh PoimboeufThe retpolines are exported, so they're referenced by ksymtab sections. But they're never indirect-branched to, so add ANNOTATE_ENDBR.
--- arch/x86/lib/retpoline.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/lib/retpoline.S +1 -1
@@ -31,6 +31,7 @@ .align RETPOLINE_THUNK_SIZE SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL) UNWIND_HINT_EMPTY + ANNOTATE_NOENDBR ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \ __stringify(RETPOLINE \reg), X86_FEATURE_RETPOLINE, \
@@ -55,7 +56,6 @@ SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL) .align RETPOLINE_THUNK_SIZE SYM_CODE_START(__x86_indirect_thunk_array) - ANNOTATE_NOENDBR // apply_retpolines #define GEN(reg) THUNK reg #include <asm/GEN-for-each-reg.h>
Signature · 1 line
2.34.1
[tip: x86/urgent] x86/retpoline: Add ANNOTATE_NOENDBR for retpolines
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 1c0513dec41e4d40eb21402dff397ad84ca13a44 Gitweb: https://git.kernel.org/tip/1c0513dec41e4d40eb21402dff397ad84ca13a44 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:23 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 19 Apr 2022 21:58:49 +02:00
x86/retpoline: Add ANNOTATE_NOENDBR for retpolines
The retpolines are exported, so they're referenced by ksymtab sections. But they're never indirect-branched to, so add ANNOTATE_NOENDBR.
--- arch/x86/lib/retpoline.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/lib/retpoline.S +1 -1
@@ -31,6 +31,7 @@ .align RETPOLINE_THUNK_SIZE SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL) UNWIND_HINT_EMPTY + ANNOTATE_NOENDBR ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \ __stringify(RETPOLINE \reg), X86_FEATURE_RETPOLINE, \
@@ -55,7 +56,6 @@ SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL) .align RETPOLINE_THUNK_SIZE SYM_CODE_START(__x86_indirect_thunk_array) - ANNOTATE_NOENDBR // apply_retpolines #define GEN(reg) THUNK reg #include <asm/GEN-for-each-reg.h>
PATCH v2 5/25 x86/uaccess: Add ENDBR to __put_user_nocheck*()
In reply to Josh PoimboeufThe __put_user_nocheck*() inner labels are exported, so in keeping with the "allow exported functions to be indirectly called" policy, add ENDBR.
--- arch/x86/lib/putuser.S | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/lib/putuser.S +4 -0
@@ -48,6 +48,7 @@ SYM_FUNC_START(__put_user_1) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_1, SYM_L_GLOBAL) + ENDBR ASM_STAC 1: movb %al,(%_ASM_CX) xor %ecx,%ecx
@@ -62,6 +63,7 @@ SYM_FUNC_START(__put_user_2) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_2, SYM_L_GLOBAL) + ENDBR ASM_STAC 2: movw %ax,(%_ASM_CX) xor %ecx,%ecx
@@ -76,6 +78,7 @@ SYM_FUNC_START(__put_user_4) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_4, SYM_L_GLOBAL) + ENDBR ASM_STAC 3: movl %eax,(%_ASM_CX) xor %ecx,%ecx
@@ -90,6 +93,7 @@ SYM_FUNC_START(__put_user_8) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_8, SYM_L_GLOBAL) + ENDBR ASM_STAC 4: mov %_ASM_AX,(%_ASM_CX) #ifdef CONFIG_X86_32
Signature · 1 line
2.34.1
[tip: x86/urgent] x86/uaccess: Add ENDBR to __put_user_nocheck*()
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 7a00829f8ac3f76b3a3aa5c28ce4ddfd2f977bbe Gitweb: https://git.kernel.org/tip/7a00829f8ac3f76b3a3aa5c28ce4ddfd2f977bbe Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:24 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 19 Apr 2022 21:58:49 +02:00
x86/uaccess: Add ENDBR to __put_user_nocheck*()
The __put_user_nocheck*() inner labels are exported, so in keeping with the "allow exported functions to be indirectly called" policy, add ENDBR.
--- arch/x86/lib/putuser.S | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/lib/putuser.S +4 -0
@@ -48,6 +48,7 @@ SYM_FUNC_START(__put_user_1) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_1, SYM_L_GLOBAL) + ENDBR ASM_STAC 1: movb %al,(%_ASM_CX) xor %ecx,%ecx
@@ -62,6 +63,7 @@ SYM_FUNC_START(__put_user_2) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_2, SYM_L_GLOBAL) + ENDBR ASM_STAC 2: movw %ax,(%_ASM_CX) xor %ecx,%ecx
@@ -76,6 +78,7 @@ SYM_FUNC_START(__put_user_4) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_4, SYM_L_GLOBAL) + ENDBR ASM_STAC 3: movl %eax,(%_ASM_CX) xor %ecx,%ecx
@@ -90,6 +93,7 @@ SYM_FUNC_START(__put_user_8) cmp %_ASM_BX,%_ASM_CX jae .Lbad_put_user SYM_INNER_LABEL(__put_user_nocheck_8, SYM_L_GLOBAL) + ENDBR ASM_STAC 4: mov %_ASM_AX,(%_ASM_CX) #ifdef CONFIG_X86_32
PATCH v2 6/25 x86/xen: Add ANNOTATE_ENDBR to startup_xen()
In reply to Josh PoimboeufThe startup_xen() kernel entry point is referenced by the ".note.Xen" section, but is presumably not indirect-branched to. Add ANNOTATE_ENDBR to silence future objtool warnings.
--- arch/x86/xen/xen-head.S | 1 + 1 file changed, 1 insertion(+)
arch/x86/xen/xen-head.S +1 -0
@@ -45,6 +45,7 @@ SYM_CODE_END(hypercall_page) __INIT SYM_CODE_START(startup_xen) UNWIND_HINT_EMPTY + ANNOTATE_NOENDBR cld /* Clear .bss */
Signature · 1 line
2.34.1
Re: [PATCH v2 06/25] x86/xen: Add ANNOTATE_ENDBR to startup_xen()
Quoted 2 lines · Josh Poimboeuf
The
startup_xen()kernel entry point is referenced by the ".note.Xen" section, but is presumably not indirect-branched to.
It's the real entrypoint of the VM. It's "got to" by setting %rip during vcpu setup.
We could in principle support starting a PV VM with CET active, but that sounds like an enormous quantity of effort for very little gain. CET for Xen PV requires paravirt anyway (because the kernel runs in CPL!=0) so decisions like this can wait until someone feels like doing the work.
Quoted 8 lines
Add
ANNOTATE_ENDBR
to silence future objtool warnings.Cc Boris Ostrovsky <[email protected]>Cc Juergen Gross <[email protected]>Cc Stefano Stabellini <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>
FWIW, Reviewed-by: Andrew Cooper <[email protected]>, preferably with the commit message tweaked to remove the uncertainty.
~Andrew
Re: [PATCH v2 06/25] x86/xen: Add ANNOTATE_ENDBR to startup_xen()
Quoted 15 lines · Andrew Cooper
Quoted 2 lines · Josh Poimboeuf
The
startup_xen()kernel entry point is referenced by the ".note.Xen" section, but is presumably not indirect-branched to.It's the real entrypoint of the VM. It's "got to" by setting %rip during vcpu setup.
We could in principle support starting a PV VM with CET active, but that sounds like an enormous quantity of effort for very little gain. CET for Xen PV requires paravirt anyway (because the kernel runs in CPL!=0) so decisions like this can wait until someone feels like doing the work.
Quoted 3 lines
Add
ANNOTATE_ENDBR
to silence future objtool warnings.
Quoted 8 lines
Quoted 5 lines
Cc Boris Ostrovsky <[email protected]>Cc Juergen Gross <[email protected]>Cc Stefano Stabellini <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>FWIW, Reviewed-by: Andrew Cooper <[email protected]>, preferably with the commit message tweaked to remove the uncertainty.
Something like so then?
---
Subject: x86/xen: Add ANNOTATE_ENDBR to startup_xen()
From: Josh Poimboeuf <[email protected]>
Date: Mon, 18 Apr 2022 09:50:25 -0700
From: Josh Poimboeuf <[email protected]>
The startup_xen() kernel entry point is referenced by the ".note.Xen" section, and is the real entry point of the VM. It *will* be indirectly branched to, *however* currently Xen doesn't support PV VM with CET active.
Add ANNOTATE_ENDBR to silence future objtool warnings.
Juergen Gross
maintainerRe: [PATCH v2 06/25] x86/xen: Add ANNOTATE_ENDBR to startup_xen()
Quoted 32 lines · Peter Zijlstra
Quoted 15 lines · Andrew Cooper
Quoted 2 lines · Josh Poimboeuf
The
startup_xen()kernel entry point is referenced by the ".note.Xen" section, but is presumably not indirect-branched to.It's the real entrypoint of the VM. It's "got to" by setting %rip during vcpu setup.
We could in principle support starting a PV VM with CET active, but that sounds like an enormous quantity of effort for very little gain. CET for Xen PV requires paravirt anyway (because the kernel runs in CPL!=0) so decisions like this can wait until someone feels like doing the work.
Quoted 3 lines
Add
ANNOTATE_ENDBR
to silence future objtool warnings.Quoted 8 lines
Quoted 5 lines
Cc Boris Ostrovsky <[email protected]>Cc Juergen Gross <[email protected]>Cc Stefano Stabellini <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>FWIW, Reviewed-by: Andrew Cooper <[email protected]>, preferably with the commit message tweaked to remove the uncertainty.
Something like so then?
---
Subject: x86/xen: AddANNOTATE_ENDBRtostartup_xen()
From: Josh Poimboeuf <[email protected]>
Date: Mon, 18 Apr 2022 09:50:25 -0700
Quoted 6 lines
From: Josh Poimboeuf <[email protected]>
The
startup_xen()kernel entry point is referenced by the ".note.Xen" section, and is the real entry point of the VM. It *will* be indirectly branched to, *however* currently Xen doesn't support PV VM with CET active.
Hmm, Xen will always use IRET to activate the guest.
Juergen
Re: [PATCH v2 06/25] x86/xen: Add ANNOTATE_ENDBR to startup_xen()
In reply to Peter ZijlstraQuoted 29 lines · Peter Zijlstra
Quoted 14 lines · Andrew Cooper
Quoted 2 lines · Josh Poimboeuf
The
startup_xen()kernel entry point is referenced by the ".note.Xen" section, but is presumably not indirect-branched to.It's the real entrypoint of the VM. It's "got to" by setting %rip during vcpu setup.
We could in principle support starting a PV VM with CET active, but that sounds like an enormous quantity of effort for very little gain. CET for Xen PV requires paravirt anyway (because the kernel runs in CPL!=0) so decisions like this can wait until someone feels like doing the work.
Quoted 3 lines
Add
ANNOTATE_ENDBR
to silence future objtool warnings.Quoted 7 lines
Quoted 5 lines
Cc Boris Ostrovsky <[email protected]>Cc Juergen Gross <[email protected]>Cc Stefano Stabellini <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>FWIW, Reviewed-by: Andrew Cooper <[email protected]>, preferably with the commit message tweaked to remove the uncertainty.
Something like so then?
---
Subject: x86/xen: AddANNOTATE_ENDBRtostartup_xen()
From: Josh Poimboeuf <[email protected]>
Date: Mon, 18 Apr 2022 09:50:25 -0700
Quoted 6 lines
From: Josh Poimboeuf <[email protected]>
The
startup_xen()kernel entry point is referenced by the ".note.Xen" section, and is the real entry point of the VM. It *will* be indirectly branched to, *however* currently Xen doesn't support PV VM with CET active.
Technically it's always IRET'd to, but the point is that it's never "branched to" by the execution context of the VM.
So it would be better to say that it's never indirectly branched to. That's what the IBT checks care about.
Quoted 2 lines
Add
ANNOTATE_ENDBRto silence future objtool warnings.
Only just spotted. All text in the subject and commit message needs s/ENDBR/NOENDBR/
~Andrew
Re: [PATCH v2 06/25] x86/xen: Add ANNOTATE_ENDBR to startup_xen()
Quoted 11 lines · Andrew Cooper
Quoted 10 lines
Subject: x86/xen: Add
ANNOTATE_ENDBRtostartup_xen()
From: Josh Poimboeuf <[email protected]>
Date: Mon, 18 Apr 2022 09:50:25 -0700From: Josh Poimboeuf <[email protected]>
The
startup_xen()kernel entry point is referenced by the ".note.Xen" section, and is the real entry point of the VM. It *will* be indirectly branched to, *however* currently Xen doesn't support PV VM with CET active.
Quoted 5 lines
Technically it's always IRET'd to, but the point is that it's never "branched to" by the execution context of the VM.
So it would be better to say that it's never indirectly branched to. That's what the IBT checks care about.
Right, so I was thinking the IRET could set the NEED_ENDBR bit, but yeah, that might be stretching the definition of an indirect-branch a wee bit.
How about so then?
---
Subject: x86/xen: Add ANNOTATE_NOENDBR to startup_xen()
From: Josh Poimboeuf <[email protected]>
Date: Mon, 18 Apr 2022 09:50:25 -0700
From: Josh Poimboeuf <[email protected]>
The startup_xen() kernel entry point is referenced by the ".note.Xen" section, and is the real entry point of the VM. Control transfer is through IRET, which *could* set NEED_ENDBR, however Xen currently does no such thing.
Add ANNOTATE_NOENDBR to silence future objtool warnings.
Re: [PATCH v2 06/25] x86/xen: Add ANNOTATE_ENDBR to startup_xen()
Quoted 35 lines · Peter Zijlstra
Quoted 10 lines · Andrew Cooper
Quoted 10 lines
Subject: x86/xen: Add
ANNOTATE_ENDBRtostartup_xen()
From: Josh Poimboeuf <[email protected]>
Date: Mon, 18 Apr 2022 09:50:25 -0700From: Josh Poimboeuf <[email protected]>
The
startup_xen()kernel entry point is referenced by the ".note.Xen" section, and is the real entry point of the VM. It *will* be indirectly branched to, *however* currently Xen doesn't support PV VM with CET active.Quoted 5 lines
Technically it's always IRET'd to, but the point is that it's never "branched to" by the execution context of the VM.
So it would be better to say that it's never indirectly branched to. That's what the IBT checks care about.
Right, so I was thinking the IRET could set the
NEED_ENDBRbit, but yeah, that might be stretching the definition of an indirect-branch a wee bit.How about so then?
---
Subject: x86/xen: AddANNOTATE_NOENDBRtostartup_xen()
From: Josh Poimboeuf <[email protected]>
Date: Mon, 18 Apr 2022 09:50:25 -0700From: Josh Poimboeuf <[email protected]>
The
startup_xen()kernel entry point is referenced by the ".note.Xen" section, and is the real entry point of the VM. Control transfer is through IRET, which *could* setNEED_ENDBR, however Xen currently does no such thing.
Quoted 7 lines
Add
ANNOTATE_NOENDBRto silence future objtool warnings.Fixes ed53a0d97192 ("x86/alternative: Use .ibt_endbr_seal to seal indirect calls")Signed-off-by Josh Poimboeuf <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Reviewed-by Andrew Cooper <[email protected]>
LGTM.
~Andrew
[tip: x86/urgent] x86/xen: Add ANNOTATE_NOENDBR to startup_xen()
In reply to Josh PoimboeufThe following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 1ab80a0da4c4a4dd496fc14faabbc8bde61a605c Gitweb: https://git.kernel.org/tip/1ab80a0da4c4a4dd496fc14faabbc8bde61a605c Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:25 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 19 Apr 2022 21:58:49 +02:00
x86/xen: Add ANNOTATE_NOENDBR to startup_xen()
The startup_xen() kernel entry point is referenced by the ".note.Xen" section, and is the real entry point of the VM. Control transfer is through IRET, which *could* set NEED_ENDBR, however Xen currently does no such thing.
Add ANNOTATE_NOENDBR to silence future objtool warnings.
--- arch/x86/xen/xen-head.S | 1 + 1 file changed, 1 insertion(+)
arch/x86/xen/xen-head.S +1 -0
@@ -45,6 +45,7 @@ SYM_CODE_END(hypercall_page) __INIT SYM_CODE_START(startup_xen) UNWIND_HINT_EMPTY + ANNOTATE_NOENDBR cld /* Clear .bss */
PATCH v2 7/25 objtool: Reorganize cmdline options
In reply to Josh PoimboeufSplit the existing options into two groups: actions, which actually do something; and options, which modify the actions in some way.
Also there's no need to have short flags for all the non-action options. Reserve short flags for the more important actions.
While at it:
- change a few of the short flags to be more intuitive
- make option descriptions more consistently descriptive
- sort options in the source like they are when printed
- move options to a global struct
--- scripts/Makefile.build | 10 ++-- scripts/link-vmlinux.sh | 30 +++++++----- tools/objtool/arch/x86/decode.c | 2 +- tools/objtool/arch/x86/special.c | 2 +- tools/objtool/builtin-check.c | 40 ++++++++-------- tools/objtool/check.c | 62 ++++++++++++------------- tools/objtool/elf.c | 8 ++-- tools/objtool/include/objtool/builtin.h | 26 +++++++++-- tools/objtool/objtool.c | 6 +-- 9 files changed, 108 insertions(+), 78 deletions(-)
scripts/Makefile.build +5 -5
@@ -228,14 +228,14 @@ objtool := $(objtree)/tools/objtool/objtool objtool_args = \ $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ - $(if $(part-of-module), --module) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ - $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ - $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \ + $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ + $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ - $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ - $(if $(CONFIG_SLS), --sls) + $(if $(part-of-module), --module) \ + $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ + $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
scripts/link-vmlinux.sh +19 -11
@@ -117,8 +117,6 @@ objtool_link() objtoolcmd="orc generate" fi - objtoolopt="${objtoolopt} --lto" - if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt="${objtoolopt} --ibt" fi
@@ -126,6 +124,8 @@ objtool_link() if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then objtoolopt="${objtoolopt} --mcount" fi + + objtoolopt="${objtoolopt} --lto" fi if is_enabled CONFIG_VMLINUX_VALIDATION; then
@@ -133,25 +133,33 @@ objtool_link() fi if [ -n "${objtoolopt}" ]; then + if [ -z "${objtoolcmd}" ]; then objtoolcmd="check" fi - objtoolopt="${objtoolopt} --vmlinux" - if ! is_enabled CONFIG_FRAME_POINTER; then - objtoolopt="${objtoolopt} --no-fp" - fi - if is_enabled CONFIG_GCOV_KERNEL; then - objtoolopt="${objtoolopt} --no-unreachable" - fi + if is_enabled CONFIG_RETPOLINE; then objtoolopt="${objtoolopt} --retpoline" fi + + if is_enabled CONFIG_SLS; then + objtoolopt="${objtoolopt} --sls" + fi + if is_enabled CONFIG_X86_SMAP; then objtoolopt="${objtoolopt} --uaccess" fi - if is_enabled CONFIG_SLS; then - objtoolopt="${objtoolopt} --sls" + + if ! is_enabled CONFIG_FRAME_POINTER; then + objtoolopt="${objtoolopt} --no-fp" fi + + if is_enabled CONFIG_GCOV_KERNEL; then + objtoolopt="${objtoolopt} --no-unreachable" + fi + + objtoolopt="${objtoolopt} --vmlinux" + info OBJTOOL ${1} tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1} fi
tools/objtool/arch/x86/decode.c +1 -1
@@ -581,7 +581,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *secbreak ;case 0xc7 :/* mov imm, r/m */ -if (!noinstr) +if (!opts.noinstr)break ;if (insn.length ==3 +4 +4 && !strncmp (sec->name,".init.text" ,10 )) {
tools/objtool/arch/x86/special.c +1 -1
@@ -20,7 +20,7 @@ void arch_handle_alternative(unsigned short feature, struct special_alt *alt)* find paths that see the STAC but take the NOP instead of * CLAC and the other way around. */ -if (uaccess) +if (opts.uaccess) alt->skip_orig = true;else alt->skip_alt = true;
tools/objtool/builtin-check.c +21 -19
@@ -19,12 +19,10 @@#include <objtool/builtin.h> #include <objtool/objtool.h> -bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, - lto, vmlinux, mcount, noinstr, backup, sls, dryrun, - ibt; +struct opts opts;static const char *const check_usage[] = { -"objtool check [<options>] file.o" , +"objtool check <actions> [<options>] file.o" ,NULL , };
@@ -34,21 +32,25 @@ static const char * const env_usage[] = { };const struct option check_options[] = { -OPT_BOOLEAN ('f' ,"no-fp" , &no_fp,"Skip frame pointer validation" ), -OPT_BOOLEAN ('u' ,"no-unreachable" , &no_unreachable,"Skip 'unreachable instruction' warnings" ), -OPT_BOOLEAN ('r' ,"retpoline" , &retpoline,"Validate retpoline assumptions" ), -OPT_BOOLEAN ('m' ,"module" , &module,"Indicates the object will be part of a kernel module" ), -OPT_BOOLEAN ('b' ,"backtrace" , &backtrace,"unwind on error" ), -OPT_BOOLEAN ('a' ,"uaccess" , &uaccess,"enable uaccess checking" ), -OPT_BOOLEAN ('s' ,"stats" , &stats,"print statistics" ), -OPT_BOOLEAN (0 ,"lto" , <o,"whole-archive like runs" ), -OPT_BOOLEAN ('n' ,"noinstr" , &noinstr,"noinstr validation for vmlinux.o" ), -OPT_BOOLEAN ('l' ,"vmlinux" , &vmlinux,"vmlinux.o validation" ), -OPT_BOOLEAN ('M' ,"mcount" , &mcount,"generate __mcount_loc" ), -OPT_BOOLEAN ('B' ,"backup" , &backup,"create .orig files before modification" ), -OPT_BOOLEAN ('S' ,"sls" , &sls,"validate straight-line-speculation" ), -OPT_BOOLEAN (0 ,"dry-run" , &dryrun,"don't write the modifications" ), -OPT_BOOLEAN (0 ,"ibt" , &ibt,"validate ENDBR placement" ), +OPT_GROUP ("Actions:" ), +OPT_BOOLEAN ('i' ,"ibt" , &opts.ibt,"validate and annotate IBT" ), +OPT_BOOLEAN ('m' ,"mcount" , &opts.mcount,"annotate mcount/fentry calls for ftrace" ), +OPT_BOOLEAN ('n' ,"noinstr" , &opts.noinstr,"validate noinstr rules" ), +OPT_BOOLEAN ('r' ,"retpoline" , &opts.retpoline,"validate and annotate retpoline usage" ), +OPT_BOOLEAN ('l' ,"sls" , &opts.sls,"validate straight-line-speculation mitigations" ), +OPT_BOOLEAN ('u' ,"uaccess" , &opts.uaccess,"validate uaccess rules for SMAP" ), + +OPT_GROUP ("Options:" ), +OPT_BOOLEAN (0 ,"backtrace" , &opts.backtrace,"unwind on error" ), +OPT_BOOLEAN (0 ,"backup" , &opts.backup,"create .orig files before modification" ), +OPT_BOOLEAN (0 ,"dry-run" , &opts.dryrun,"don't write modifications" ), +OPT_BOOLEAN (0 ,"lto" , &opts.lto,"whole-archive like runs" ), +OPT_BOOLEAN (0 ,"module" , &opts.module,"object is part of a kernel module" ), +OPT_BOOLEAN (0 ,"no-fp" , &opts.no_fp,"skip frame pointer validation" ), +OPT_BOOLEAN (0 ,"no-unreachable" , &opts.no_unreachable,"skip 'unreachable instruction' warnings" ), +OPT_BOOLEAN (0 ,"stats" , &opts.stats,"print statistics" ), +OPT_BOOLEAN (0 ,"vmlinux" , &opts.vmlinux,"vmlinux.o validation" ), +OPT_END (), };
tools/objtool/check.c +31 -31
246 lines not on this page · raw message
tools/objtool/elf.c +4 -4
@@ -355,7 +355,7 @@ static int read_sections(struct elf *elf)elf_hash_add (section_name, &sec->name_hash,str_hash (sec->name)); } -if (stats) { +if (opts.stats) {printf ("nr_sections: %lu\n" , (unsigned long )sections_nr);printf ("section_bits: %d\n" , elf->section_bits); }
@@ -475,7 +475,7 @@ static int read_symbols(struct elf *elf)elf_add_symbol (elf, sym); } -if (stats) { +if (opts.stats) {printf ("nr_symbols: %lu\n" , (unsigned long )symbols_nr);printf ("symbol_bits: %d\n" , elf->symbol_bits); }
@@ -700,7 +700,7 @@ static int read_relocs(struct elf *elf) tot_reloc += nr_reloc; } -if (stats) { +if (opts.stats) {printf ("max_reloc: %lu\n" , max_reloc);printf ("tot_reloc: %lu\n" , tot_reloc);printf ("reloc_bits: %d\n" , elf->reloc_bits);
@@ -1079,7 +1079,7 @@ int elf_write(struct elf *elf)struct section *sec;Elf_Scn *s; -if (dryrun) +if (opts.dryrun)return 0 ;/* Update changed relocation sections and section headers: */
tools/objtool/include/objtool/builtin.h +23 -3
@@ -8,9 +8,29 @@#include <subcmd/parse-options.h> extern const struct option check_options[]; -extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, - lto, vmlinux, mcount, noinstr, backup, sls, dryrun, - ibt; + +struct opts { +/* actions: */ +bool ibt; +bool mcount; +bool noinstr; +bool retpoline; +bool sls; +bool uaccess; + +/* options: */ +bool backtrace; +bool backup; +bool dryrun; +bool lto; +bool module; +bool no_fp; +bool no_unreachable; +bool stats; +bool vmlinux; +}; + +extern struct opts opts;extern int cmd_parse_options (int argc,const char **argv,const char *const usage[]);
tools/objtool/objtool.c +3 -3
@@ -118,7 +118,7 @@ struct objtool_file *objtool_open_read(const char *_objname)if (!file.elf)return NULL ; -if (backup && !objtool_create_backup (objname)) { +if (opts.backup && !objtool_create_backup (objname)) {WARN ("can't create backup file" );return NULL ; }
@@ -129,7 +129,7 @@ struct objtool_file *objtool_open_read(const char *_objname)INIT_LIST_HEAD (&file.static_call_list);INIT_LIST_HEAD (&file.mcount_loc_list);INIT_LIST_HEAD (&file.endbr_list); - file.ignore_unreachables = no_unreachable; + file.ignore_unreachables = opts.no_unreachable; file.hints = false;return &file;
@@ -137,7 +137,7 @@ struct objtool_file *objtool_open_read(const char *_objname)void objtool_pv_add (struct objtool_file *f,int idx,struct symbol *func) { -if (!noinstr) +if (!opts.noinstr)return ;if (!f->pv_ops) {
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Reorganize cmdline options
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 2daf7faba7ded8703e4b4ebc8b161f22272fc91a Gitweb: https://git.kernel.org/tip/2daf7faba7ded8703e4b4ebc8b161f22272fc91a Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:26 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:01 +02:00
objtool: Reorganize cmdline options
Split the existing options into two groups: actions, which actually do something; and options, which modify the actions in some way.
Also there's no need to have short flags for all the non-action options. Reserve short flags for the more important actions.
While at it:
- change a few of the short flags to be more intuitive
- make option descriptions more consistently descriptive
- sort options in the source like they are when printed
- move options to a global struct
--- scripts/Makefile.build | 10 ++-- scripts/link-vmlinux.sh | 30 +++++++----- tools/objtool/arch/x86/decode.c | 2 +- tools/objtool/arch/x86/special.c | 2 +- tools/objtool/builtin-check.c | 40 +++++++-------- tools/objtool/check.c | 62 ++++++++++++------------ tools/objtool/elf.c | 8 +-- tools/objtool/include/objtool/builtin.h | 26 ++++++++-- tools/objtool/objtool.c | 6 +- 9 files changed, 108 insertions(+), 78 deletions(-)
scripts/Makefile.build +5 -5
@@ -228,14 +228,14 @@ objtool := $(objtree)/tools/objtool/objtool objtool_args = \ $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ - $(if $(part-of-module), --module) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ - $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ - $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \ + $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ + $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ - $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ - $(if $(CONFIG_SLS), --sls) + $(if $(part-of-module), --module) \ + $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ + $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
scripts/link-vmlinux.sh +19 -11
@@ -117,8 +117,6 @@ objtool_link() objtoolcmd="orc generate" fi - objtoolopt="${objtoolopt} --lto" - if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt="${objtoolopt} --ibt" fi
@@ -126,6 +124,8 @@ objtool_link() if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then objtoolopt="${objtoolopt} --mcount" fi + + objtoolopt="${objtoolopt} --lto" fi if is_enabled CONFIG_VMLINUX_VALIDATION; then
@@ -133,25 +133,33 @@ objtool_link() fi if [ -n "${objtoolopt}" ]; then + if [ -z "${objtoolcmd}" ]; then objtoolcmd="check" fi - objtoolopt="${objtoolopt} --vmlinux" - if ! is_enabled CONFIG_FRAME_POINTER; then - objtoolopt="${objtoolopt} --no-fp" - fi - if is_enabled CONFIG_GCOV_KERNEL; then - objtoolopt="${objtoolopt} --no-unreachable" - fi + if is_enabled CONFIG_RETPOLINE; then objtoolopt="${objtoolopt} --retpoline" fi + + if is_enabled CONFIG_SLS; then + objtoolopt="${objtoolopt} --sls" + fi + if is_enabled CONFIG_X86_SMAP; then objtoolopt="${objtoolopt} --uaccess" fi - if is_enabled CONFIG_SLS; then - objtoolopt="${objtoolopt} --sls" + + if ! is_enabled CONFIG_FRAME_POINTER; then + objtoolopt="${objtoolopt} --no-fp" fi + + if is_enabled CONFIG_GCOV_KERNEL; then + objtoolopt="${objtoolopt} --no-unreachable" + fi + + objtoolopt="${objtoolopt} --vmlinux" + info OBJTOOL ${1} tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1} fi
tools/objtool/arch/x86/decode.c +1 -1
@@ -581,7 +581,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *secbreak ;case 0xc7 :/* mov imm, r/m */ -if (!noinstr) +if (!opts.noinstr)break ;if (insn.length ==3 +4 +4 && !strncmp (sec->name,".init.text" ,10 )) {
tools/objtool/arch/x86/special.c +1 -1
@@ -20,7 +20,7 @@ void arch_handle_alternative(unsigned short feature, struct special_alt *alt)* find paths that see the STAC but take the NOP instead of * CLAC and the other way around. */ -if (uaccess) +if (opts.uaccess) alt->skip_orig = true;else alt->skip_alt = true;
tools/objtool/builtin-check.c +21 -19
@@ -19,12 +19,10 @@#include <objtool/builtin.h> #include <objtool/objtool.h> -bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, - lto, vmlinux, mcount, noinstr, backup, sls, dryrun, - ibt; +struct opts opts;static const char *const check_usage[] = { -"objtool check [<options>] file.o" , +"objtool check <actions> [<options>] file.o" ,NULL , };
@@ -34,21 +32,25 @@ static const char * const env_usage[] = { };const struct option check_options[] = { -OPT_BOOLEAN ('f' ,"no-fp" , &no_fp,"Skip frame pointer validation" ), -OPT_BOOLEAN ('u' ,"no-unreachable" , &no_unreachable,"Skip 'unreachable instruction' warnings" ), -OPT_BOOLEAN ('r' ,"retpoline" , &retpoline,"Validate retpoline assumptions" ), -OPT_BOOLEAN ('m' ,"module" , &module,"Indicates the object will be part of a kernel module" ), -OPT_BOOLEAN ('b' ,"backtrace" , &backtrace,"unwind on error" ), -OPT_BOOLEAN ('a' ,"uaccess" , &uaccess,"enable uaccess checking" ), -OPT_BOOLEAN ('s' ,"stats" , &stats,"print statistics" ), -OPT_BOOLEAN (0 ,"lto" , <o,"whole-archive like runs" ), -OPT_BOOLEAN ('n' ,"noinstr" , &noinstr,"noinstr validation for vmlinux.o" ), -OPT_BOOLEAN ('l' ,"vmlinux" , &vmlinux,"vmlinux.o validation" ), -OPT_BOOLEAN ('M' ,"mcount" , &mcount,"generate __mcount_loc" ), -OPT_BOOLEAN ('B' ,"backup" , &backup,"create .orig files before modification" ), -OPT_BOOLEAN ('S' ,"sls" , &sls,"validate straight-line-speculation" ), -OPT_BOOLEAN (0 ,"dry-run" , &dryrun,"don't write the modifications" ), -OPT_BOOLEAN (0 ,"ibt" , &ibt,"validate ENDBR placement" ), +OPT_GROUP ("Actions:" ), +OPT_BOOLEAN ('i' ,"ibt" , &opts.ibt,"validate and annotate IBT" ), +OPT_BOOLEAN ('m' ,"mcount" , &opts.mcount,"annotate mcount/fentry calls for ftrace" ), +OPT_BOOLEAN ('n' ,"noinstr" , &opts.noinstr,"validate noinstr rules" ), +OPT_BOOLEAN ('r' ,"retpoline" , &opts.retpoline,"validate and annotate retpoline usage" ), +OPT_BOOLEAN ('l' ,"sls" , &opts.sls,"validate straight-line-speculation mitigations" ), +OPT_BOOLEAN ('u' ,"uaccess" , &opts.uaccess,"validate uaccess rules for SMAP" ), + +OPT_GROUP ("Options:" ), +OPT_BOOLEAN (0 ,"backtrace" , &opts.backtrace,"unwind on error" ), +OPT_BOOLEAN (0 ,"backup" , &opts.backup,"create .orig files before modification" ), +OPT_BOOLEAN (0 ,"dry-run" , &opts.dryrun,"don't write modifications" ), +OPT_BOOLEAN (0 ,"lto" , &opts.lto,"whole-archive like runs" ), +OPT_BOOLEAN (0 ,"module" , &opts.module,"object is part of a kernel module" ), +OPT_BOOLEAN (0 ,"no-fp" , &opts.no_fp,"skip frame pointer validation" ), +OPT_BOOLEAN (0 ,"no-unreachable" , &opts.no_unreachable,"skip 'unreachable instruction' warnings" ), +OPT_BOOLEAN (0 ,"stats" , &opts.stats,"print statistics" ), +OPT_BOOLEAN (0 ,"vmlinux" , &opts.vmlinux,"vmlinux.o validation" ), +OPT_END (), };
tools/objtool/check.c +31 -31
246 lines not on this page · raw message
tools/objtool/elf.c +4 -4
@@ -355,7 +355,7 @@ static int read_sections(struct elf *elf)elf_hash_add (section_name, &sec->name_hash,str_hash (sec->name)); } -if (stats) { +if (opts.stats) {printf ("nr_sections: %lu\n" , (unsigned long )sections_nr);printf ("section_bits: %d\n" , elf->section_bits); }
@@ -475,7 +475,7 @@ static int read_symbols(struct elf *elf)elf_add_symbol (elf, sym); } -if (stats) { +if (opts.stats) {printf ("nr_symbols: %lu\n" , (unsigned long )symbols_nr);printf ("symbol_bits: %d\n" , elf->symbol_bits); }
@@ -843,7 +843,7 @@ static int read_relocs(struct elf *elf) tot_reloc += nr_reloc; } -if (stats) { +if (opts.stats) {printf ("max_reloc: %lu\n" , max_reloc);printf ("tot_reloc: %lu\n" , tot_reloc);printf ("reloc_bits: %d\n" , elf->reloc_bits);
@@ -1222,7 +1222,7 @@ int elf_write(struct elf *elf)struct section *sec;Elf_Scn *s; -if (dryrun) +if (opts.dryrun)return 0 ;/* Update changed relocation sections and section headers: */
tools/objtool/include/objtool/builtin.h +23 -3
@@ -8,9 +8,29 @@#include <subcmd/parse-options.h> extern const struct option check_options[]; -extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, - lto, vmlinux, mcount, noinstr, backup, sls, dryrun, - ibt; + +struct opts { +/* actions: */ +bool ibt; +bool mcount; +bool noinstr; +bool retpoline; +bool sls; +bool uaccess; + +/* options: */ +bool backtrace; +bool backup; +bool dryrun; +bool lto; +bool module; +bool no_fp; +bool no_unreachable; +bool stats; +bool vmlinux; +}; + +extern struct opts opts;extern int cmd_parse_options (int argc,const char **argv,const char *const usage[]);
tools/objtool/objtool.c +3 -3
@@ -118,7 +118,7 @@ struct objtool_file *objtool_open_read(const char *_objname)if (!file.elf)return NULL ; -if (backup && !objtool_create_backup (objname)) { +if (opts.backup && !objtool_create_backup (objname)) {WARN ("can't create backup file" );return NULL ; }
@@ -129,7 +129,7 @@ struct objtool_file *objtool_open_read(const char *_objname)INIT_LIST_HEAD (&file.static_call_list);INIT_LIST_HEAD (&file.mcount_loc_list);INIT_LIST_HEAD (&file.endbr_list); - file.ignore_unreachables = no_unreachable; + file.ignore_unreachables = opts.no_unreachable; file.hints = false;return &file;
@@ -137,7 +137,7 @@ struct objtool_file *objtool_open_read(const char *_objname)void objtool_pv_add (struct objtool_file *f,int idx,struct symbol *func) { -if (!noinstr) +if (!opts.noinstr)return ;if (!f->pv_ops) {
PATCH v2 8/25 objtool: Ditch subcommands
In reply to Josh PoimboeufObjtool has a fairly singular focus. It runs on object files and does validations and transformations which can be combined in various ways. The subcommand model has never been a good fit, making it awkward to combine and remove options.
Remove the "check" and "orc" subcommands in favor of a more traditional cmdline option model. This makes it much more flexible to use, and easier to port individual features to other arches.
--- scripts/Makefile.build | 2 +- scripts/link-vmlinux.sh | 13 ++-- tools/objtool/Build | 12 ++- tools/objtool/Makefile | 8 +- tools/objtool/builtin-check.c | 56 +++++++++++--- tools/objtool/builtin-orc.c | 73 ------------------- tools/objtool/check.c | 8 ++ tools/objtool/include/objtool/builtin.h | 5 +- tools/objtool/objtool.c | 97 +------------------------ tools/objtool/weak.c | 9 +-- 10 files changed, 72 insertions(+), 211 deletions(-) delete mode 100644 tools/objtool/builtin-orc.c
scripts/Makefile.build +1 -1
@@ -227,9 +227,9 @@ ifdef CONFIG_STACK_VALIDATION objtool := $(objtree)/tools/objtool/objtool objtool_args = \ - $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ + $(if $(CONFIG_UNWINDER_ORC), --orc) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_X86_SMAP), --uaccess) \
scripts/link-vmlinux.sh +5 -8
@@ -113,9 +113,6 @@ objtool_link() # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file. - if is_enabled CONFIG_UNWINDER_ORC; then - objtoolcmd="orc generate" - fi if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt="${objtoolopt} --ibt"
@@ -125,6 +122,10 @@ objtool_link() objtoolopt="${objtoolopt} --mcount" fi + if is_enabled CONFIG_UNWINDER_ORC; then + objtoolopt="${objtoolopt} --orc" + fi + objtoolopt="${objtoolopt} --lto" fi
@@ -134,10 +135,6 @@ objtool_link() if [ -n "${objtoolopt}" ]; then - if [ -z "${objtoolcmd}" ]; then - objtoolcmd="check" - fi - if is_enabled CONFIG_RETPOLINE; then objtoolopt="${objtoolopt} --retpoline" fi
@@ -161,7 +158,7 @@ objtool_link() objtoolopt="${objtoolopt} --vmlinux" info OBJTOOL ${1} - tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1} + tools/objtool/objtool ${objtoolopt} ${1} fi }
tools/objtool/Build +5 -7
@@ -2,17 +2,15 @@ objtool-y += arch/$(SRCARCH)/ objtool-y += weak.o -objtool-$(SUBCMD_CHECK) += check.o -objtool-$(SUBCMD_CHECK) += special.o -objtool-$(SUBCMD_ORC) += check.o -objtool-$(SUBCMD_ORC) += orc_gen.o -objtool-$(SUBCMD_ORC) += orc_dump.o - +objtool-y += check.o +objtool-y += special.o objtool-y += builtin-check.o -objtool-y += builtin-orc.o objtool-y += elf.o objtool-y += objtool.o +objtool-$(BUILD_ORC) += orc_gen.o +objtool-$(BUILD_ORC) += orc_dump.o + objtool-y += libstring.o objtool-y += libctype.o objtool-y += str_error_r.o
tools/objtool/Makefile +3 -5
@@ -39,15 +39,13 @@ CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) AWK = awk -SUBCMD_CHECK := n -SUBCMD_ORC := n +BUILD_ORC := n ifeq ($(SRCARCH),x86) - SUBCMD_CHECK := y - SUBCMD_ORC := y + BUILD_ORC := y endif -export SUBCMD_CHECK SUBCMD_ORC +export BUILD_ORC export srctree OUTPUT CFLAGS SRCARCH AWK include $(srctree)/tools/build/Makefile.include
tools/objtool/builtin-check.c +44 -12
94 lines not on this page · raw message
tools/objtool/builtin-orc.c deleted +0 -73
73 lines not on this page · raw message
tools/objtool/check.c +8 -0
@@ -3954,6 +3954,14 @@ int check(struct objtool_file *file) warnings += ret; } +if (opts.orc && !list_empty (&file->insn_list)) { + ret =orc_create (file); +if (ret <0 ) + goto out; + warnings += ret; + } + +if (opts.stats) {printf ("nr_insns_visited: %ld\n" , nr_insns_visited);printf ("nr_cfi: %ld\n" , nr_cfi);
tools/objtool/include/objtool/builtin.h +3 -2
@@ -11,9 +11,11 @@ extern const struct option check_options[];struct opts {/* actions: */ +bool dump_orc;bool ibt;bool mcount;bool noinstr; +bool orc;bool retpoline;bool sls;bool uaccess;
@@ -34,7 +36,6 @@ extern struct opts opts;extern int cmd_parse_options (int argc,const char **argv,const char *const usage[]); -extern int cmd_check (int argc,const char **argv); -extern int cmd_orc (int argc,const char **argv); +extern int objtool_run (int argc,const char **argv);#endif /* _BUILTIN_H */
tools/objtool/objtool.c +1 -96
121 lines not on this page · raw message
tools/objtool/weak.c +2 -7
@@ -15,17 +15,12 @@return ENOSYS ; \ }) -int __weak check (struct objtool_file *file) -{ -UNSUPPORTED ("check subcommand" ); -} -int __weak orc_dump (const char *_objname) { -UNSUPPORTED ("orc" ); +UNSUPPORTED ("ORC" ); }int __weak orc_create (struct objtool_file *file) { -UNSUPPORTED ("orc" ); +UNSUPPORTED ("ORC" ); }
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Ditch subcommands
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: b51277eb9775ce916f9efd2c51533e481180c1e8 Gitweb: https://git.kernel.org/tip/b51277eb9775ce916f9efd2c51533e481180c1e8 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:27 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:01 +02:00
objtool: Ditch subcommands
Objtool has a fairly singular focus. It runs on object files and does validations and transformations which can be combined in various ways. The subcommand model has never been a good fit, making it awkward to combine and remove options.
Remove the "check" and "orc" subcommands in favor of a more traditional cmdline option model. This makes it much more flexible to use, and easier to port individual features to other arches.
--- scripts/Makefile.build | 2 +- scripts/link-vmlinux.sh | 13 +-- tools/objtool/Build | 12 +-- tools/objtool/Makefile | 8 +-- tools/objtool/builtin-check.c | 56 +++++++++++--- tools/objtool/builtin-orc.c | 73 +------------------ tools/objtool/check.c | 8 ++- tools/objtool/include/objtool/builtin.h | 5 +- tools/objtool/objtool.c | 97 +------------------------ tools/objtool/weak.c | 9 +-- 10 files changed, 72 insertions(+), 211 deletions(-) delete mode 100644 tools/objtool/builtin-orc.c
scripts/Makefile.build +1 -1
@@ -227,9 +227,9 @@ ifdef CONFIG_STACK_VALIDATION objtool := $(objtree)/tools/objtool/objtool objtool_args = \ - $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ + $(if $(CONFIG_UNWINDER_ORC), --orc) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_X86_SMAP), --uaccess) \
scripts/link-vmlinux.sh +5 -8
@@ -113,9 +113,6 @@ objtool_link() # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file. - if is_enabled CONFIG_UNWINDER_ORC; then - objtoolcmd="orc generate" - fi if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt="${objtoolopt} --ibt"
@@ -125,6 +122,10 @@ objtool_link() objtoolopt="${objtoolopt} --mcount" fi + if is_enabled CONFIG_UNWINDER_ORC; then + objtoolopt="${objtoolopt} --orc" + fi + objtoolopt="${objtoolopt} --lto" fi
@@ -134,10 +135,6 @@ objtool_link() if [ -n "${objtoolopt}" ]; then - if [ -z "${objtoolcmd}" ]; then - objtoolcmd="check" - fi - if is_enabled CONFIG_RETPOLINE; then objtoolopt="${objtoolopt} --retpoline" fi
@@ -161,7 +158,7 @@ objtool_link() objtoolopt="${objtoolopt} --vmlinux" info OBJTOOL ${1} - tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1} + tools/objtool/objtool ${objtoolopt} ${1} fi }
tools/objtool/Build +5 -7
@@ -2,17 +2,15 @@ objtool-y += arch/$(SRCARCH)/ objtool-y += weak.o -objtool-$(SUBCMD_CHECK) += check.o -objtool-$(SUBCMD_CHECK) += special.o -objtool-$(SUBCMD_ORC) += check.o -objtool-$(SUBCMD_ORC) += orc_gen.o -objtool-$(SUBCMD_ORC) += orc_dump.o - +objtool-y += check.o +objtool-y += special.o objtool-y += builtin-check.o -objtool-y += builtin-orc.o objtool-y += elf.o objtool-y += objtool.o +objtool-$(BUILD_ORC) += orc_gen.o +objtool-$(BUILD_ORC) += orc_dump.o + objtool-y += libstring.o objtool-y += libctype.o objtool-y += str_error_r.o
tools/objtool/Makefile +3 -5
@@ -39,15 +39,13 @@ CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) AWK = awk -SUBCMD_CHECK := n -SUBCMD_ORC := n +BUILD_ORC := n ifeq ($(SRCARCH),x86) - SUBCMD_CHECK := y - SUBCMD_ORC := y + BUILD_ORC := y endif -export SUBCMD_CHECK SUBCMD_ORC +export BUILD_ORC export srctree OUTPUT CFLAGS SRCARCH AWK include $(srctree)/tools/build/Makefile.include
tools/objtool/builtin-check.c +44 -12
94 lines not on this page · raw message
tools/objtool/builtin-orc.c deleted +0 -73
73 lines not on this page · raw message
tools/objtool/check.c +8 -0
@@ -3949,6 +3949,14 @@ int check(struct objtool_file *file) warnings += ret; } +if (opts.orc && !list_empty (&file->insn_list)) { + ret =orc_create (file); +if (ret <0 ) + goto out; + warnings += ret; + } + +if (opts.stats) {printf ("nr_insns_visited: %ld\n" , nr_insns_visited);printf ("nr_cfi: %ld\n" , nr_cfi);
tools/objtool/include/objtool/builtin.h +3 -2
@@ -11,9 +11,11 @@ extern const struct option check_options[];struct opts {/* actions: */ +bool dump_orc;bool ibt;bool mcount;bool noinstr; +bool orc;bool retpoline;bool sls;bool uaccess;
@@ -34,7 +36,6 @@ extern struct opts opts;extern int cmd_parse_options (int argc,const char **argv,const char *const usage[]); -extern int cmd_check (int argc,const char **argv); -extern int cmd_orc (int argc,const char **argv); +extern int objtool_run (int argc,const char **argv);#endif /* _BUILTIN_H */
tools/objtool/objtool.c +1 -96
121 lines not on this page · raw message
tools/objtool/weak.c +2 -7
@@ -15,17 +15,12 @@return ENOSYS ; \ }) -int __weak check (struct objtool_file *file) -{ -UNSUPPORTED ("check subcommand" ); -} -int __weak orc_dump (const char *_objname) { -UNSUPPORTED ("orc" ); +UNSUPPORTED ("ORC" ); }int __weak orc_create (struct objtool_file *file) { -UNSUPPORTED ("orc" ); +UNSUPPORTED ("ORC" ); }
PATCH v2 9/25 objtool: Don't print parentheses in function addresses
In reply to Josh PoimboeufThe parentheses in the "func()+off" address output are inconsistent with how the kernel prints function addresses, breaking Peter's scripts. Remove them.
--- tools/objtool/include/objtool/warn.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
tools/objtool/include/objtool/warn.h +1 -5
@@ -33,11 +33,7 @@ static inline char *offstr(struct section *sec, unsigned long offset) } str =malloc (strlen (name) +20 ); - -if (func) -sprintf (str,"%s()+0x%lx" , name, name_off); -else -sprintf (str,"%s+0x%lx" , name, name_off); +sprintf (str,"%s+0x%lx" , name, name_off);return str; }
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Don't print parentheses in function addresses
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 2bc3dec7055e34c2c2e497f109da6748544c0791 Gitweb: https://git.kernel.org/tip/2bc3dec7055e34c2c2e497f109da6748544c0791 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:28 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:02 +02:00
objtool: Don't print parentheses in function addresses
The parentheses in the "func()+off" address output are inconsistent with how the kernel prints function addresses, breaking Peter's scripts. Remove them.
--- tools/objtool/include/objtool/warn.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
tools/objtool/include/objtool/warn.h +1 -5
@@ -33,11 +33,7 @@ static inline char *offstr(struct section *sec, unsigned long offset) } str =malloc (strlen (name) +20 ); - -if (func) -sprintf (str,"%s()+0x%lx" , name, name_off); -else -sprintf (str,"%s+0x%lx" , name, name_off); +sprintf (str,"%s+0x%lx" , name, name_off);return str; }
PATCH v2 10/25 objtool: Print data address for "!ENDBR" data warnings
In reply to Josh PoimboeufWhen a "!ENDBR" warning is reported for a data section, objtool just prints the text address of the relocation target twice, without giving any clues about the location of the original data reference:
vmlinux.o: warning: objtool: dcbnl_netdevice_event()+0x0: .text+0xb64680: data relocation to !ENDBR: dcbnl_netdevice_event+0x0
Instead, print the address of the data reference, in addition to the address of the relocation target.
vmlinux.o: warning: objtool: dcbnl_nb+0x0: .data..read_mostly+0xe260: data relocation to !ENDBR: dcbnl_netdevice_event+0x0
--- tools/objtool/check.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
tools/objtool/check.c +2 -5
@@ -3825,11 +3825,8 @@ static int validate_ibt(struct objtool_file *file)struct instruction *dest; dest =validate_ibt_reloc (file, reloc); -if (is_data && dest && !dest->noendbr) { -warn_noendbr ("data " , reloc->sym->sec, - reloc->sym->offset + reloc->addend, - dest); - } +if (is_data && dest && !dest->noendbr) +warn_noendbr ("data " , sec, reloc->offset, dest); } }
Signature · 1 line
2.34.1
[tip: x86/urgent] objtool: Print data address for "!ENDBR" data warnings
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 4baae989e638e9bf4b7d29bc5e36b581fddcca52 Gitweb: https://git.kernel.org/tip/4baae989e638e9bf4b7d29bc5e36b581fddcca52 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:29 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 19 Apr 2022 21:58:50 +02:00
objtool: Print data address for "!ENDBR" data warnings
When a "!ENDBR" warning is reported for a data section, objtool just prints the text address of the relocation target twice, without giving any clues about the location of the original data reference:
vmlinux.o: warning: objtool: dcbnl_netdevice_event()+0x0: .text+0xb64680: data relocation to !ENDBR: dcbnl_netdevice_event+0x0
Instead, print the address of the data reference, in addition to the address of the relocation target.
vmlinux.o: warning: objtool: dcbnl_nb+0x0: .data..read_mostly+0xe260: data relocation to !ENDBR: dcbnl_netdevice_event+0x0
--- tools/objtool/check.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
tools/objtool/check.c +2 -5
@@ -3817,11 +3817,8 @@ static int validate_ibt(struct objtool_file *file)struct instruction *dest; dest =validate_ibt_reloc (file, reloc); -if (is_data && dest && !dest->noendbr) { -warn_noendbr ("data " , reloc->sym->sec, - reloc->sym->offset + reloc->addend, - dest); - } +if (is_data && dest && !dest->noendbr) +warn_noendbr ("data " , sec, reloc->offset, dest); } }
PATCH v2 11/25 objtool: Use offstr() to print address of missing ENDBR
In reply to Josh Poimboeuf--- tools/objtool/check.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/objtool/check.c +2 -3
@@ -3219,9 +3219,8 @@ validate_ibt_reloc(struct objtool_file *file, struct reloc *reloc)static void warn_noendbr (const char *msg,struct section *sec,unsigned long offset,struct instruction *dest) { -WARN_FUNC ("%srelocation to !ENDBR: %s+0x%lx" , sec, offset, msg, - dest->func ? dest->func->name : dest->sec->name, - dest->func ? dest->offset - dest->func->offset : dest->offset); +WARN_FUNC ("%srelocation to !ENDBR: %s" , sec, offset, msg, +offstr (dest->sec, dest->offset)); } static void validate_ibt_dest(struct objtool_file *file, struct instruction *insn,
Signature · 1 line
2.34.1
[tip: x86/urgent] objtool: Use offstr() to print address of missing ENDBR
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 1d08b92fa2c41c43e4efe9787413e9ac9a434f83 Gitweb: https://git.kernel.org/tip/1d08b92fa2c41c43e4efe9787413e9ac9a434f83 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:30 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 19 Apr 2022 21:58:50 +02:00
objtool: Use offstr() to print address of missing ENDBR
--- tools/objtool/check.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/objtool/check.c +2 -3
@@ -3211,9 +3211,8 @@ validate_ibt_reloc(struct objtool_file *file, struct reloc *reloc)static void warn_noendbr (const char *msg,struct section *sec,unsigned long offset,struct instruction *dest) { -WARN_FUNC ("%srelocation to !ENDBR: %s+0x%lx" , sec, offset, msg, - dest->func ? dest->func->name : dest->sec->name, - dest->func ? dest->offset - dest->func->offset : dest->offset); +WARN_FUNC ("%srelocation to !ENDBR: %s" , sec, offset, msg, +offstr (dest->sec, dest->offset)); } static void validate_ibt_dest(struct objtool_file *file, struct instruction *insn,
PATCH v2 12/25 objtool: Add option to print section addresses
In reply to Josh PoimboeufTo help prevent objtool users from having to do math to convert function addresses to section addresses, and to help out with finding data addresses reported by IBT validation, add an option to print the section address in addition to the function address.
Normal:
vmlinux.o: warning: objtool: fixup_exception()+0x2d1: unreachable instruction
With '--sec-address':
vmlinux.o: warning: objtool: fixup_exception()+0x2d1 (.text+0x76c51): unreachable instruction
--- tools/objtool/builtin-check.c | 1 + tools/objtool/include/objtool/builtin.h | 1 + tools/objtool/include/objtool/warn.h | 31 ++++++++++++++----------- 3 files changed, 19 insertions(+), 14 deletions(-)
tools/objtool/builtin-check.c +1 -0
@@ -50,6 +50,7 @@ const struct option check_options[] = {OPT_BOOLEAN (0 ,"module" , &opts.module,"object is part of a kernel module" ),OPT_BOOLEAN (0 ,"no-fp" , &opts.no_fp,"skip frame pointer validation" ),OPT_BOOLEAN (0 ,"no-unreachable" , &opts.no_unreachable,"skip 'unreachable instruction' warnings" ), +OPT_BOOLEAN (0 ,"sec-address" , &opts.sec_address,"print section addresses in warnings" ),OPT_BOOLEAN (0 ,"stats" , &opts.stats,"print statistics" ), OPT_BOOLEAN(0, "vmlinux", &opts.vmlinux, "vmlinux.o validation"),
tools/objtool/include/objtool/builtin.h +1 -0
@@ -28,6 +28,7 @@ struct opts {bool module;bool no_fp;bool no_unreachable; +bool sec_address;bool stats;bool vmlinux; };
tools/objtool/include/objtool/warn.h +17 -14
@@ -11,30 +11,33 @@#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <objtool/builtin.h> #include <objtool/elf.h> extern const char *objname;static inline char *offstr (struct section *sec,unsigned long offset) { -struct symbol *func; -char *name, *str; -unsigned long name_off; +bool is_text = (sec->sh.sh_flags &SHF_EXECINSTR ); +struct symbol *sym =NULL ; +char *str; +int len; - func =find_func_containing (sec, offset); -if (!func) - func =find_symbol_containing (sec, offset); -if (func) { - name = func->name; - name_off = offset - func->offset; +if (is_text) + sym =find_func_containing (sec, offset); +if (!sym) + sym =find_symbol_containing (sec, offset); + +if (sym) { + str =malloc (strlen (sym->name) +strlen (sec->name) +40 ); + len =sprintf (str,"%s+0x%lx" , sym->name, offset - sym->offset); +if (opts.sec_address) +sprintf (str+len," (%s+0x%lx)" , sec->name, offset); }else { - name = sec->name; - name_off = offset; + str =malloc (strlen (sec->name) +20 ); +sprintf (str,"%s+0x%lx" , sec->name, offset); } - str =malloc (strlen (name) +20 ); -sprintf (str,"%s+0x%lx" , name, name_off); -return str; }
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Add option to print section addresses
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 99c0beb547a3e0ec3a63edeba0960c6ddf2226b0 Gitweb: https://git.kernel.org/tip/99c0beb547a3e0ec3a63edeba0960c6ddf2226b0 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:31 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:02 +02:00
objtool: Add option to print section addresses
To help prevent objtool users from having to do math to convert function addresses to section addresses, and to help out with finding data addresses reported by IBT validation, add an option to print the section address in addition to the function address.
Normal:
vmlinux.o: warning: objtool: fixup_exception()+0x2d1: unreachable instruction
With '--sec-address':
vmlinux.o: warning: objtool: fixup_exception()+0x2d1 (.text+0x76c51): unreachable instruction
--- tools/objtool/builtin-check.c | 1 +- tools/objtool/include/objtool/builtin.h | 1 +- tools/objtool/include/objtool/warn.h | 31 +++++++++++++----------- 3 files changed, 19 insertions(+), 14 deletions(-)
tools/objtool/builtin-check.c +1 -0
@@ -50,6 +50,7 @@ const struct option check_options[] = {OPT_BOOLEAN (0 ,"module" , &opts.module,"object is part of a kernel module" ),OPT_BOOLEAN (0 ,"no-fp" , &opts.no_fp,"skip frame pointer validation" ),OPT_BOOLEAN (0 ,"no-unreachable" , &opts.no_unreachable,"skip 'unreachable instruction' warnings" ), +OPT_BOOLEAN (0 ,"sec-address" , &opts.sec_address,"print section addresses in warnings" ),OPT_BOOLEAN (0 ,"stats" , &opts.stats,"print statistics" ), OPT_BOOLEAN(0, "vmlinux", &opts.vmlinux, "vmlinux.o validation"),
tools/objtool/include/objtool/builtin.h +1 -0
@@ -28,6 +28,7 @@ struct opts {bool module;bool no_fp;bool no_unreachable; +bool sec_address;bool stats;bool vmlinux; };
tools/objtool/include/objtool/warn.h +17 -14
@@ -11,30 +11,33 @@#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <objtool/builtin.h> #include <objtool/elf.h> extern const char *objname;static inline char *offstr (struct section *sec,unsigned long offset) { -struct symbol *func; -char *name, *str; -unsigned long name_off; +bool is_text = (sec->sh.sh_flags &SHF_EXECINSTR ); +struct symbol *sym =NULL ; +char *str; +int len; - func =find_func_containing (sec, offset); -if (!func) - func =find_symbol_containing (sec, offset); -if (func) { - name = func->name; - name_off = offset - func->offset; +if (is_text) + sym =find_func_containing (sec, offset); +if (!sym) + sym =find_symbol_containing (sec, offset); + +if (sym) { + str =malloc (strlen (sym->name) +strlen (sec->name) +40 ); + len =sprintf (str,"%s+0x%lx" , sym->name, offset - sym->offset); +if (opts.sec_address) +sprintf (str+len," (%s+0x%lx)" , sec->name, offset); }else { - name = sec->name; - name_off = offset; + str =malloc (strlen (sec->name) +20 ); +sprintf (str,"%s+0x%lx" , sec->name, offset); } - str =malloc (strlen (name) +20 ); -sprintf (str,"%s+0x%lx" , name, name_off); -return str; }
PATCH v2 13/25 scripts: Create objdump-func helper script
In reply to Josh PoimboeufAdd a simple script which disassembles a single function from an object file. Comes in handy for objtool warnings and kernel stack traces.
--- scripts/objdump-func | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 scripts/objdump-func
scripts/objdump-func new file +18 -0
@@ -0,0 +1,18 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Disassemble a single function. +# +# usage: objdump-func <file> <func> + +set -o errexit +set -o nounset + +OBJDUMP="${CROSS_COMPILE:-}objdump" + +command -v awk >/dev/null 2>&1 || die "awk isn't installed" + +OBJ=$1; shift +FUNC=$1; shift + +${OBJDUMP} -wdr $@ $OBJ | awk "/^\$/ { P=0; } /$FUNC[^>]*>:\$/ { P=1; O=strtonum(\"0x\" \$1); } { if (P) { o=strtonum(\"0x\" \$1); printf(\"%04x \", o-O); print \$0; } }"
Signature · 1 line
2.34.1
Peter Zijlstra
maintainerRe: [PATCH v2 13/25] scripts: Create objdump-func helper script
Quoted 37 lines · Josh Poimboeuf
Add a simple script which disassembles a single function from an object file. Comes in handy for objtool warnings and kernel stack traces.
Originally-by Peter Zijlstra <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>--- scripts/objdump-func | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 scripts/objdump-funcscripts/objdump-func new file +18
-0@@ -0,0 +1,18 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Disassemble a single function. +# +# usage: objdump-func <file> <func> + +set -o errexit +set -o nounset + +OBJDUMP="${CROSS_COMPILE:-}objdump" + +command -v awk >/dev/null 2>&1 || die "awk isn't installed" + +OBJ=$1; shift +FUNC=$1; shift + +${OBJDUMP} -wdr $@ $OBJ | awk "/^\$/ { P=0; } /$FUNC[^>]*>:\$/ { P=1; O=strtonum(\"0x\" \$1); } { if (P) { o=strtonum(\"0x\" \$1); printf(\"%04x \", o-O); print \$0; } }"Signature · 1 line
2.34.1
This might rely on awk being gawk, I'm never very careful about those things.
Re: [PATCH v2 13/25] scripts: Create objdump-func helper script
Quoted 33 lines · Peter Zijlstra
Quoted 32 lines · Josh Poimboeuf
Add a simple script which disassembles a single function from an object file. Comes in handy for objtool warnings and kernel stack traces.
Originally-by Peter Zijlstra <[email protected]>Signed-off-by Josh Poimboeuf <[email protected]>--- scripts/objdump-func | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 scripts/objdump-funcscripts/objdump-func new file +16
-0@@ -0,0 +1,18 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Disassemble a single function. +# +# usage: objdump-func <file> <func> + +set -o errexit +set -o nounset + +OBJDUMP="${CROSS_COMPILE:-}objdump" + +command -v awk >/dev/null 2>&1 || die "awk isn't installed" + +OBJ=$1; shift +FUNC=$1; shift
Quoted 8 lines
Quoted 5 lines
scripts/objdump-func new file +2
-0+ +${OBJDUMP} -wdr $@ $OBJ | awk "/^\$/ { P=0; } /$FUNC[^>]*>:\$/ { P=1; O=strtonum(\"0x\" \$1); } { if (P) { o=strtonum(\"0x\" \$1); printf(\"%04x \", o-O); print \$0; } }"Signature · 1 line
2.34.1This might rely on awk being gawk, I'm never very careful about those things.
True, running with --posix I get
awk: cmd. line:1: (FILENAME=- FNR=17142) fatal: function `strtonum' not defined
The non-gawk users always ruin the party.
Signature · 1 line
Josh
PATCH v2 14/25 objtool: Make stack validation optional
In reply to Josh PoimboeufMake stack validation an explicit cmdline option so that individual objtool features can be enabled individually by other arches.
--- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 4 ++++ tools/objtool/builtin-check.c | 2 ++ tools/objtool/check.c | 28 +++++++++++++------------ tools/objtool/include/objtool/builtin.h | 1 + 5 files changed, 23 insertions(+), 13 deletions(-)
scripts/Makefile.build +1 -0
@@ -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) \
scripts/link-vmlinux.sh +4 -0
@@ -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
tools/objtool/builtin-check.c +2 -0
@@ -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" );
tools/objtool/check.c +15 -13
@@ -3900,25 +3900,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;
tools/objtool/include/objtool/builtin.h +1 -0
@@ -18,6 +18,7 @@ struct opts {bool orc;bool retpoline;bool sls; +bool stackval;bool uaccess;/* options: */
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Make stack validation optional
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 7dce62041ac34b613a5ed1bd937117e492e06dc8 Gitweb: https://git.kernel.org/tip/7dce62041ac34b613a5ed1bd937117e492e06dc8 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:33 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:02 +02:00
objtool: Make stack validation optional
Make stack validation an explicit cmdline option so that individual objtool features can be enabled individually by other arches.
--- scripts/Makefile.build | 1 +- scripts/link-vmlinux.sh | 4 +++- tools/objtool/builtin-check.c | 2 ++- tools/objtool/check.c | 28 ++++++++++++------------ tools/objtool/include/objtool/builtin.h | 1 +- 5 files changed, 23 insertions(+), 13 deletions(-)
scripts/Makefile.build +1 -0
@@ -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) \
scripts/link-vmlinux.sh +4 -0
@@ -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
tools/objtool/builtin-check.c +2 -0
@@ -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" );
tools/objtool/check.c +15 -13
@@ -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;
tools/objtool/include/objtool/builtin.h +1 -0
@@ -18,6 +18,7 @@ struct opts {bool orc;bool retpoline;bool sls; +bool stackval;bool uaccess;/* options: */
PATCH v2 15/25 objtool: Rework ibt and extricate from stack validation
In reply to Josh PoimboeufExtricate ibt from validate_branch() so they can be executed (or ported) independently from each other.
While shuffling code around, simplify and improve the ibt logic:
- Ignore an explicit list of known sections which reference functions for reasons other than indirect branching to them. This helps prevent unnnecesary sealing.
- Warn on missing !ENDBR for all other sections, not just .data and .rodata. This finds additional warnings, because there are sections other than .[ro]data which reference function pointers. For example, the ksymtab sections which are used for exporting symbols.
--- tools/objtool/check.c | 280 ++++++++++++++++++++++-------------------- 1 file changed, 147 insertions(+), 133 deletions(-)
tools/objtool/check.c +147 -133
@@ -3183,114 +3183,6 @@ static struct instruction *next_insn_to_validate(struct objtool_file *file,return next_insn_same_sec (file, insn); } -static struct instruction * -validate_ibt_reloc (struct objtool_file *file,struct reloc *reloc) -{ -struct instruction *dest; -struct section *sec; -unsigned long off; - - sec = reloc->sym->sec; - off = reloc->sym->offset; - -if ((reloc->sec->base->sh.sh_flags &SHF_EXECINSTR ) && - (reloc->type ==R_X86_64_PC32 || reloc->type ==R_X86_64_PLT32 )) - off +=arch_dest_reloc_offset (reloc->addend); -else - off += reloc->addend; - - dest =find_insn (file, sec, off); -if (!dest) -return NULL ; - -if (dest->type ==INSN_ENDBR ) { -if (!list_empty (&dest->call_node)) -list_del_init (&dest->call_node); - -return NULL ; - } - -if (reloc->sym->static_call_tramp) -return NULL ; - -return dest; -} - -static void warn_noendbr (const char *msg,struct section *sec,unsigned long offset, -struct instruction *dest) -{ -WARN_FUNC ("%srelocation to !ENDBR: %s" , sec, offset, msg, -offstr (dest->sec, dest->offset)); -} - -static void validate_ibt_dest (struct objtool_file *file,struct instruction *insn, -struct instruction *dest) -{ -if (dest->func && dest->func == insn->func) { -/* -* Anything from->to self is either _THIS_IP_ or IRET-to-self. -* -* There is no sane way to annotate _THIS_IP_ since the compiler treats the -* relocation as a constant and is happy to fold in offsets, skewing any -* annotation we do, leading to vast amounts of false-positives. -* -* There's also compiler generated _THIS_IP_ through KCOV and -* such which we have no hope of annotating. -* -* As such, blanket accept self-references without issue. -*/ -return ; - } - -if (dest->noendbr) -return ; - -warn_noendbr ("" , insn->sec, insn->offset, dest); -} - -static void validate_ibt_insn (struct objtool_file *file,struct instruction *insn) -{ -struct instruction *dest; -struct reloc *reloc; - -switch (insn->type) { -case INSN_CALL : -case INSN_CALL_DYNAMIC : -case INSN_JUMP_CONDITIONAL : -case INSN_JUMP_UNCONDITIONAL : -case INSN_JUMP_DYNAMIC : -case INSN_JUMP_DYNAMIC_CONDITIONAL : -case INSN_RETURN : -/* -* We're looking for code references setting up indirect code -* flow. As such, ignore direct code flow and the actual -* dynamic branches. -*/ -return ; - -case INSN_NOP : -/* -* handle_group_alt() will create INSN_NOP instruction that -* don't belong to any section, ignore all NOP since they won't -* carry a (useful) relocation anyway. -*/ -return ; - -default : -break ; - } - -for (reloc =insn_reloc (file, insn); - reloc; - reloc =find_reloc_by_dest_range (file->elf, insn->sec, - reloc->offset +1 , - (insn->offset + insn->len) - (reloc->offset +1 ))) { - dest =validate_ibt_reloc (file, reloc); -if (dest) -validate_ibt_dest (file, insn, dest); - } -} -/* * Follow the branch starting at the given instruction, and recursively follow * any other branches (jumps). Meanwhile, track the frame pointer state at
@@ -3500,9 +3392,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,break ; } -if (opts.ibt) -validate_ibt_insn (file, insn); -if (insn->dead_end)return 0 ;
@@ -3788,48 +3677,173 @@ static int validate_functions(struct objtool_file *file)return warnings; } -static int validate_ibt (struct objtool_file *file) +static void mark_endbr_used (struct instruction *insn) { -struct section *sec; +if (!list_empty (&insn->call_node)) +list_del_init (&insn->call_node); +} + +static int validate_ibt_insn (struct objtool_file *file,struct instruction *insn) +{ +struct instruction *dest;struct reloc *reloc; +unsigned long off; +int warnings =0 ; -for_each_sec (file, sec) { -bool is_data; +/* +* Looking for function pointer load relocations. Ignore +* direct/indirect branches: +*/ +switch (insn->type) { +case INSN_CALL : +case INSN_CALL_DYNAMIC : +case INSN_JUMP_CONDITIONAL : +case INSN_JUMP_UNCONDITIONAL : +case INSN_JUMP_DYNAMIC : +case INSN_JUMP_DYNAMIC_CONDITIONAL : +case INSN_RETURN : +case INSN_NOP : +return 0 ; +default : +break ; + } -/* already done in validate_branch() */ -if (sec->sh.sh_flags &SHF_EXECINSTR ) -continue ; +for (reloc =insn_reloc (file, insn); + reloc; + reloc =find_reloc_by_dest_range (file->elf, insn->sec, + reloc->offset +1 , + (insn->offset + insn->len) - (reloc->offset +1 ))) { -if (!sec->reloc) +/* +* static_call_update() references the trampoline, which +* doesn't have (or need) ENDBR. Skip warning in that case. +*/ +if (reloc->sym->static_call_tramp)continue ; -if (!strncmp (sec->name,".orc" ,4 )) + off = reloc->sym->offset; +if (reloc->type ==R_X86_64_PC32 || reloc->type ==R_X86_64_PLT32 ) + off +=arch_dest_reloc_offset (reloc->addend); +else + off += reloc->addend; + + dest =find_insn (file, reloc->sym->sec, off); +if (!dest)continue ; -if (!strncmp (sec->name,".discard" ,8 )) +if (dest->type ==INSN_ENDBR ) { +mark_endbr_used (dest);continue ; + } -if (!strncmp (sec->name,".debug" ,6 )) +if (dest->func && dest->func == insn->func) { +/* +* Anything from->to self is either _THIS_IP_ or +* IRET-to-self. +* +* There is no sane way to annotate _THIS_IP_ since the +* compiler treats the relocation as a constant and is +* happy to fold in offsets, skewing any annotation we +* do, leading to vast amounts of false-positives. +* +* There's also compiler generated _THIS_IP_ through +* KCOV and such which we have no hope of annotating. +* +* As such, blanket accept self-references without +* issue. +*/ continue ; + } -if (!strcmp (sec->name,"_error_injection_whitelist" )) +if (dest->noendbr)continue ; -if (!strcmp (sec->name,"_kprobe_blacklist" )) +WARN_FUNC ("relocation to !ENDBR: %s" , + insn->sec, insn->offset, +offstr (dest->sec, dest->offset)); + + warnings++; + } + +return warnings; +} + +static int validate_ibt_data_reloc (struct objtool_file *file, +struct reloc *reloc) +{ +struct instruction *dest; + + dest =find_insn (file, reloc->sym->sec, + reloc->sym->offset + reloc->addend); +if (!dest) +return 0 ; + +if (dest->type ==INSN_ENDBR ) { +mark_endbr_used (dest); +return 0 ; + } + +if (dest->noendbr) +return 0 ; + +WARN_FUNC ("data relocation to !ENDBR: %s" , + reloc->sec->base, reloc->offset, +offstr (dest->sec, dest->offset)); + +return 1 ; +} + +/* +* Validate IBT rules and remove used ENDBR instructions from the seal list. +* Unused ENDBR instructions will be annotated for sealing (i.e., replaced with +* NOPs) later, in create_ibt_endbr_seal_sections(). +*/ +static int validate_ibt (struct objtool_file *file) +{ +struct section *sec; +struct reloc *reloc; +struct instruction *insn; +int warnings =0 ; + +for_each_insn (file, insn) + warnings +=validate_ibt_insn (file, insn); + +for_each_sec (file, sec) { + +/* Already done by validate_ibt_insn() */ +if (sec->sh.sh_flags &SHF_EXECINSTR )continue ; - is_data =strstr (sec->name,".data" ) ||strstr (sec->name,".rodata" ); +if (!sec->reloc) +continue ; -list_for_each_entry (reloc, &sec->reloc->reloc_list, list) { -struct instruction *dest; +/* +* These sections can reference text addresses, but not with +* the intent to indirect branch to them. +*/ +if (!strncmp (sec->name,".discard" ,8 ) || + !strncmp (sec->name,".debug" ,6 ) || + !strcmp (sec->name,".altinstructions" ) || + !strcmp (sec->name,".ibt_endbr_seal" ) || + !strcmp (sec->name,".orc_unwind_ip" ) || + !strcmp (sec->name,".parainstructions" ) || + !strcmp (sec->name,".retpoline_sites" ) || + !strcmp (sec->name,".smp_locks" ) || + !strcmp (sec->name,".static_call_sites" ) || + !strcmp (sec->name,"_error_injection_whitelist" ) || + !strcmp (sec->name,"_kprobe_blacklist" ) || + !strcmp (sec->name,"__bug_table" ) || + !strcmp (sec->name,"__ex_table" ) || + !strcmp (sec->name,"__jump_table" ) || + !strcmp (sec->name,"__mcount_loc" ) || + !strcmp (sec->name,"__tracepoints" )) +continue ; - dest =validate_ibt_reloc (file, reloc); -if (is_data && dest && !dest->noendbr) -warn_noendbr ("data " , sec, reloc->offset, dest); - } +list_for_each_entry (reloc, &sec->reloc->reloc_list, list) + warnings +=validate_ibt_data_reloc (file, reloc); } -return 0 ; +return warnings; }static int validate_reachable_instructions (struct objtool_file *file)
@@ -3900,7 +3914,7 @@ int check(struct objtool_file *file) warnings += ret; } -if (opts.stackval || opts.orc || opts.uaccess || opts.ibt || opts.sls) { +if (opts.stackval || opts.orc || opts.uaccess || opts.sls) { ret =validate_functions (file);if (ret <0 ) goto out;
Signature · 1 line
2.34.1
Re: [PATCH v2 15/25] objtool: Rework ibt and extricate from stack validation
A nit and it was there even before this patch...
tools/objtool/check.c static struct instruction *next_insn_to_validate(struct objtool_file *file, · line 3198
Quoted 13 lines
tools/objtool/check.c +0
-13-static struct instruction * -validate_ibt_reloc (struct objtool_file *file,struct reloc *reloc) -{ -struct instruction *dest; -struct section *sec; -unsigned long off; - - sec = reloc->sym->sec; - off = reloc->sym->offset; - -if ((reloc->sec->base->sh.sh_flags &SHF_EXECINSTR ) && - (reloc->type ==R_X86_64_PC32 || reloc->type ==R_X86_64_PLT32 )) - off +=arch_dest_reloc_offset (reloc->addend);
here...
Quoted 2 lines
tools/objtool/check.c +2
-0+static int validate_ibt_insn (struct objtool_file *file,struct instruction *insn) +{
...
tools/objtool/check.c static int validate_functions(struct objtool_file *file) · line 3728
Quoted 5 lines
tools/objtool/check.c +5
-0+ off = reloc->sym->offset; +if (reloc->type ==R_X86_64_PC32 || reloc->type ==R_X86_64_PLT32 ) + off +=arch_dest_reloc_offset (reloc->addend); +else + off += reloc->addend;
it looks kind of strange to have arch_dest_reloc_offset() and still reference arch-specific relocation types here. On the other hand it seems difficult to achieve complete arch-agnostic code, so take it just as a note and maybe someone porting objtool to a different architecture will split the code, make it all arch-independent and all will be nice and shiny.
Miroslav
Peter Zijlstra
maintainerRe: [PATCH v2 15/25] objtool: Rework ibt and extricate from stack validation
Quoted 22 lines · Miroslav Benes
A nit and it was there even before this patch...
Review
Quoted 13 lines
(quoted diff) +0
-13-static struct instruction * -validate_ibt_reloc(struct objtool_file *file, struct reloc *reloc) -{ - struct instruction *dest; - struct section *sec; - unsigned long off; - - sec = reloc->sym->sec; - off = reloc->sym->offset; - - if ((reloc->sec->base->sh.sh_flags & SHF_EXECINSTR) && - (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32)) - off += arch_dest_reloc_offset(reloc->addend);here...
Quoted 2 lines
(quoted diff) +2
-0+static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn) +{...
Quoted 12 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ off = reloc->sym->offset; + if (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32) + off += arch_dest_reloc_offset(reloc->addend); + else + off += reloc->addend;it looks kind of strange to have
arch_dest_reloc_offset()and still reference arch-specific relocation types here. On the other hand it seems difficult to achieve complete arch-agnostic code, so take it just as a note and maybe someone porting objtool to a different architecture will split the code, make it all arch-independent and all will be nice and shiny.
Something like so perhaps? Seems to build and boot x86_64-defconfig.
--- tools/objtool/arch/x86/decode.c | 9 +++++++-- tools/objtool/check.c | 18 +++++++----------- tools/objtool/include/objtool/arch.h | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-)
tools/objtool/arch/x86/decode.c +7 -2
@@ -63,9 +63,14 @@ bool arch_callee_saved_reg(unsigned char reg) } } -unsigned long arch_dest_reloc_offset (int addend) +unsigned long arch_dest_reloc_offset (struct reloc *reloc) { -return addend +4 ; +unsigned long offset = reloc->sym->offset + reloc->addend; + +if (reloc->type ==R_X86_64_PC32 || reloc->type ==R_X86_64_PLT32 ) + offset +=4 ; + +return offset; }unsigned long arch_jump_destination (struct instruction *insn)
tools/objtool/check.c +7 -11
@@ -1295,7 +1295,7 @@ static int add_jump_destinations(struct objtool_file *file) dest_off =arch_jump_destination (insn); }else if (reloc->sym->type ==STT_SECTION ) { dest_sec = reloc->sym->sec; - dest_off =arch_dest_reloc_offset (reloc->addend); + dest_off =arch_dest_reloc_offset (reloc); }else if (reloc->sym->retpoline_thunk) {add_retpoline_call (file, insn);continue ;
@@ -1308,8 +1308,7 @@ static int add_jump_destinations(struct objtool_file *file)continue ; }else if (reloc->sym->sec->idx) { dest_sec = reloc->sym->sec; - dest_off = reloc->sym->sym.st_value + -arch_dest_reloc_offset (reloc->addend); + dest_off =arch_dest_reloc_offset (reloc); }else {/* non-func asm code jumping to another file */ continue ;
@@ -1413,7 +1412,7 @@ static int add_call_destinations(struct objtool_file *file) } }else if (reloc->sym->type ==STT_SECTION ) { - dest_off =arch_dest_reloc_offset (reloc->addend); + dest_off =arch_dest_reloc_offset (reloc); dest =find_call_destination (reloc->sym->sec, dest_off);if (!dest) { WARN_FUNC("can't find call dest symbol at %s+0x%lx",
@@ -3031,6 +3030,7 @@ static inline const char *call_dest_name(struct instruction *insn)static bool pv_call_dest (struct objtool_file *file,struct instruction *insn) {struct symbol *target; +unsigned long offset;struct reloc *rel;int idx;
@@ -3038,7 +3038,8 @@ static bool pv_call_dest(struct objtool_file *file, struct instruction *insn)if (!rel ||strcmp (rel->sym->name,"pv_ops" ))return false; - idx = (arch_dest_reloc_offset (rel->addend) /sizeof (void *)); + offset =arch_dest_reloc_offset (rel) - rel->sym->offset; + idx = offset /sizeof (void *);if (file->pv_ops[idx].clean)return true;
@@ -3709,12 +3710,7 @@ static int validate_ibt_insn(struct objtool_file *file, struct instruction *insnif (reloc->sym->static_call_tramp)continue ; - off = reloc->sym->offset; -if (reloc->type ==R_X86_64_PC32 || reloc->type ==R_X86_64_PLT32 ) - off +=arch_dest_reloc_offset (reloc->addend); -else - off += reloc->addend; - + off =arch_dest_reloc_offset (reloc); dest =find_insn (file, reloc->sym->sec, off);if (!dest)continue ;
tools/objtool/include/objtool/arch.h +1 -1
@@ -81,7 +81,7 @@ bool arch_callee_saved_reg(unsigned char reg);unsigned long arch_jump_destination (struct instruction *insn); -unsigned long arch_dest_reloc_offset (int addend); +unsigned long arch_dest_reloc_offset (struct reloc *reloc);const char *arch_nop_insn (int len);const char *arch_ret_insn (int len);
Re: [PATCH v2 15/25] objtool: Rework ibt and extricate from stack validation
Quoted 36 lines · Peter Zijlstra
Quoted 22 lines · Miroslav Benes
A nit and it was there even before this patch...
Review
Quoted 13 lines
(quoted diff) +0
-13-static struct instruction * -validate_ibt_reloc(struct objtool_file *file, struct reloc *reloc) -{ - struct instruction *dest; - struct section *sec; - unsigned long off; - - sec = reloc->sym->sec; - off = reloc->sym->offset; - - if ((reloc->sec->base->sh.sh_flags & SHF_EXECINSTR) && - (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32)) - off += arch_dest_reloc_offset(reloc->addend);here...
Quoted 2 lines
(quoted diff) +2
-0+static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn) +{...
Quoted 12 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ off = reloc->sym->offset; + if (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32) + off += arch_dest_reloc_offset(reloc->addend); + else + off += reloc->addend;it looks kind of strange to have
arch_dest_reloc_offset()and still reference arch-specific relocation types here. On the other hand it seems difficult to achieve complete arch-agnostic code, so take it just as a note and maybe someone porting objtool to a different architecture will split the code, make it all arch-independent and all will be nice and shiny.
Quoted 1 line
Something like so perhaps? Seems to build and boot x86_64-defconfig.
Looks good...
Signature · 1 line
Josh
Re: [PATCH v2 15/25] objtool: Rework ibt and extricate from stack validation
In reply to Peter ZijlstraQuoted 36 lines · Peter Zijlstra
Quoted 22 lines · Miroslav Benes
A nit and it was there even before this patch...
Review
Quoted 13 lines
(quoted diff) +0
-13-static struct instruction * -validate_ibt_reloc(struct objtool_file *file, struct reloc *reloc) -{ - struct instruction *dest; - struct section *sec; - unsigned long off; - - sec = reloc->sym->sec; - off = reloc->sym->offset; - - if ((reloc->sec->base->sh.sh_flags & SHF_EXECINSTR) && - (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32)) - off += arch_dest_reloc_offset(reloc->addend);here...
Quoted 2 lines
(quoted diff) +2
-0+static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn) +{...
Quoted 12 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ off = reloc->sym->offset; + if (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32) + off += arch_dest_reloc_offset(reloc->addend); + else + off += reloc->addend;it looks kind of strange to have
arch_dest_reloc_offset()and still reference arch-specific relocation types here. On the other hand it seems difficult to achieve complete arch-agnostic code, so take it just as a note and maybe someone porting objtool to a different architecture will split the code, make it all arch-independent and all will be nice and shiny.
Quoted 1 line
Something like so perhaps? Seems to build and boot x86_64-defconfig.
Yes, that looks good. Thanks.
Miroslav
[tip: objtool/core] objtool: Rework ibt and extricate from stack validation
In reply to Josh PoimboeufThe following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 3c6f9f77e6188ca4d283633d66e91b3821a505ae Gitweb: https://git.kernel.org/tip/3c6f9f77e6188ca4d283633d66e91b3821a505ae Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:34 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:02 +02:00
objtool: Rework ibt and extricate from stack validation
Extricate ibt from validate_branch() so they can be executed (or ported) independently from each other.
While shuffling code around, simplify and improve the ibt logic:
- Ignore an explicit list of known sections which reference functions for reasons other than indirect branching to them. This helps prevent unnnecesary sealing.
- Warn on missing !ENDBR for all other sections, not just .data and .rodata. This finds additional warnings, because there are sections other than .[ro]data which reference function pointers. For example, the ksymtab sections which are used for exporting symbols.
--- tools/objtool/check.c | 280 +++++++++++++++++++++-------------------- 1 file changed, 147 insertions(+), 133 deletions(-)
tools/objtool/check.c +147 -133
@@ -3182,114 +3182,6 @@ static struct instruction *next_insn_to_validate(struct objtool_file *file,return next_insn_same_sec (file, insn); } -static struct instruction * -validate_ibt_reloc (struct objtool_file *file,struct reloc *reloc) -{ -struct instruction *dest; -struct section *sec; -unsigned long off; - - sec = reloc->sym->sec; - off = reloc->sym->offset; - -if ((reloc->sec->base->sh.sh_flags &SHF_EXECINSTR ) && - (reloc->type ==R_X86_64_PC32 || reloc->type ==R_X86_64_PLT32 )) - off +=arch_dest_reloc_offset (reloc->addend); -else - off += reloc->addend; - - dest =find_insn (file, sec, off); -if (!dest) -return NULL ; - -if (dest->type ==INSN_ENDBR ) { -if (!list_empty (&dest->call_node)) -list_del_init (&dest->call_node); - -return NULL ; - } - -if (reloc->sym->static_call_tramp) -return NULL ; - -return dest; -} - -static void warn_noendbr (const char *msg,struct section *sec,unsigned long offset, -struct instruction *dest) -{ -WARN_FUNC ("%srelocation to !ENDBR: %s" , sec, offset, msg, -offstr (dest->sec, dest->offset)); -} - -static void validate_ibt_dest (struct objtool_file *file,struct instruction *insn, -struct instruction *dest) -{ -if (dest->func && dest->func == insn->func) { -/* -* Anything from->to self is either _THIS_IP_ or IRET-to-self. -* -* There is no sane way to annotate _THIS_IP_ since the compiler treats the -* relocation as a constant and is happy to fold in offsets, skewing any -* annotation we do, leading to vast amounts of false-positives. -* -* There's also compiler generated _THIS_IP_ through KCOV and -* such which we have no hope of annotating. -* -* As such, blanket accept self-references without issue. -*/ -return ; - } - -if (dest->noendbr) -return ; - -warn_noendbr ("" , insn->sec, insn->offset, dest); -} - -static void validate_ibt_insn (struct objtool_file *file,struct instruction *insn) -{ -struct instruction *dest; -struct reloc *reloc; - -switch (insn->type) { -case INSN_CALL : -case INSN_CALL_DYNAMIC : -case INSN_JUMP_CONDITIONAL : -case INSN_JUMP_UNCONDITIONAL : -case INSN_JUMP_DYNAMIC : -case INSN_JUMP_DYNAMIC_CONDITIONAL : -case INSN_RETURN : -/* -* We're looking for code references setting up indirect code -* flow. As such, ignore direct code flow and the actual -* dynamic branches. -*/ -return ; - -case INSN_NOP : -/* -* handle_group_alt() will create INSN_NOP instruction that -* don't belong to any section, ignore all NOP since they won't -* carry a (useful) relocation anyway. -*/ -return ; - -default : -break ; - } - -for (reloc =insn_reloc (file, insn); - reloc; - reloc =find_reloc_by_dest_range (file->elf, insn->sec, - reloc->offset +1 , - (insn->offset + insn->len) - (reloc->offset +1 ))) { - dest =validate_ibt_reloc (file, reloc); -if (dest) -validate_ibt_dest (file, insn, dest); - } -} -/* * Follow the branch starting at the given instruction, and recursively follow * any other branches (jumps). Meanwhile, track the frame pointer state at
@@ -3499,9 +3391,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,break ; } -if (opts.ibt) -validate_ibt_insn (file, insn); -if (insn->dead_end)return 0 ;
@@ -3787,48 +3676,173 @@ static int validate_functions(struct objtool_file *file)return warnings; } -static int validate_ibt (struct objtool_file *file) +static void mark_endbr_used (struct instruction *insn) { -struct section *sec; +if (!list_empty (&insn->call_node)) +list_del_init (&insn->call_node); +} + +static int validate_ibt_insn (struct objtool_file *file,struct instruction *insn) +{ +struct instruction *dest;struct reloc *reloc; +unsigned long off; +int warnings =0 ; -for_each_sec (file, sec) { -bool is_data; +/* +* Looking for function pointer load relocations. Ignore +* direct/indirect branches: +*/ +switch (insn->type) { +case INSN_CALL : +case INSN_CALL_DYNAMIC : +case INSN_JUMP_CONDITIONAL : +case INSN_JUMP_UNCONDITIONAL : +case INSN_JUMP_DYNAMIC : +case INSN_JUMP_DYNAMIC_CONDITIONAL : +case INSN_RETURN : +case INSN_NOP : +return 0 ; +default : +break ; + } -/* already done in validate_branch() */ -if (sec->sh.sh_flags &SHF_EXECINSTR ) -continue ; +for (reloc =insn_reloc (file, insn); + reloc; + reloc =find_reloc_by_dest_range (file->elf, insn->sec, + reloc->offset +1 , + (insn->offset + insn->len) - (reloc->offset +1 ))) { -if (!sec->reloc) +/* +* static_call_update() references the trampoline, which +* doesn't have (or need) ENDBR. Skip warning in that case. +*/ +if (reloc->sym->static_call_tramp)continue ; -if (!strncmp (sec->name,".orc" ,4 )) + off = reloc->sym->offset; +if (reloc->type ==R_X86_64_PC32 || reloc->type ==R_X86_64_PLT32 ) + off +=arch_dest_reloc_offset (reloc->addend); +else + off += reloc->addend; + + dest =find_insn (file, reloc->sym->sec, off); +if (!dest)continue ; -if (!strncmp (sec->name,".discard" ,8 )) +if (dest->type ==INSN_ENDBR ) { +mark_endbr_used (dest);continue ; + } -if (!strncmp (sec->name,".debug" ,6 )) +if (dest->func && dest->func == insn->func) { +/* +* Anything from->to self is either _THIS_IP_ or +* IRET-to-self. +* +* There is no sane way to annotate _THIS_IP_ since the +* compiler treats the relocation as a constant and is +* happy to fold in offsets, skewing any annotation we +* do, leading to vast amounts of false-positives. +* +* There's also compiler generated _THIS_IP_ through +* KCOV and such which we have no hope of annotating. +* +* As such, blanket accept self-references without +* issue. +*/ continue ; + } -if (!strcmp (sec->name,"_error_injection_whitelist" )) +if (dest->noendbr)continue ; -if (!strcmp (sec->name,"_kprobe_blacklist" )) +WARN_FUNC ("relocation to !ENDBR: %s" , + insn->sec, insn->offset, +offstr (dest->sec, dest->offset)); + + warnings++; + } + +return warnings; +} + +static int validate_ibt_data_reloc (struct objtool_file *file, +struct reloc *reloc) +{ +struct instruction *dest; + + dest =find_insn (file, reloc->sym->sec, + reloc->sym->offset + reloc->addend); +if (!dest) +return 0 ; + +if (dest->type ==INSN_ENDBR ) { +mark_endbr_used (dest); +return 0 ; + } + +if (dest->noendbr) +return 0 ; + +WARN_FUNC ("data relocation to !ENDBR: %s" , + reloc->sec->base, reloc->offset, +offstr (dest->sec, dest->offset)); + +return 1 ; +} + +/* +* Validate IBT rules and remove used ENDBR instructions from the seal list. +* Unused ENDBR instructions will be annotated for sealing (i.e., replaced with +* NOPs) later, in create_ibt_endbr_seal_sections(). +*/ +static int validate_ibt (struct objtool_file *file) +{ +struct section *sec; +struct reloc *reloc; +struct instruction *insn; +int warnings =0 ; + +for_each_insn (file, insn) + warnings +=validate_ibt_insn (file, insn); + +for_each_sec (file, sec) { + +/* Already done by validate_ibt_insn() */ +if (sec->sh.sh_flags &SHF_EXECINSTR )continue ; - is_data =strstr (sec->name,".data" ) ||strstr (sec->name,".rodata" ); +if (!sec->reloc) +continue ; -list_for_each_entry (reloc, &sec->reloc->reloc_list, list) { -struct instruction *dest; +/* +* These sections can reference text addresses, but not with +* the intent to indirect branch to them. +*/ +if (!strncmp (sec->name,".discard" ,8 ) || + !strncmp (sec->name,".debug" ,6 ) || + !strcmp (sec->name,".altinstructions" ) || + !strcmp (sec->name,".ibt_endbr_seal" ) || + !strcmp (sec->name,".orc_unwind_ip" ) || + !strcmp (sec->name,".parainstructions" ) || + !strcmp (sec->name,".retpoline_sites" ) || + !strcmp (sec->name,".smp_locks" ) || + !strcmp (sec->name,".static_call_sites" ) || + !strcmp (sec->name,"_error_injection_whitelist" ) || + !strcmp (sec->name,"_kprobe_blacklist" ) || + !strcmp (sec->name,"__bug_table" ) || + !strcmp (sec->name,"__ex_table" ) || + !strcmp (sec->name,"__jump_table" ) || + !strcmp (sec->name,"__mcount_loc" ) || + !strcmp (sec->name,"__tracepoints" )) +continue ; - dest =validate_ibt_reloc (file, reloc); -if (is_data && dest && !dest->noendbr) -warn_noendbr ("data " , sec, reloc->offset, dest); - } +list_for_each_entry (reloc, &sec->reloc->reloc_list, list) + warnings +=validate_ibt_data_reloc (file, reloc); } -return 0 ; +return warnings; }static int validate_reachable_instructions (struct objtool_file *file)
@@ -3899,7 +3913,7 @@ int check(struct objtool_file *file) warnings += ret; } -if (opts.stackval || opts.orc || opts.uaccess || opts.ibt || opts.sls) { +if (opts.stackval || opts.orc || opts.uaccess || opts.sls) { ret =validate_functions (file);if (ret <0 ) goto out;
PATCH v2 16/25 objtool: Extricate sls from stack validation
In reply to Josh PoimboeufExtricate sls functionality from validate_branch() so they can be executed (or ported) independently from each other.
--- tools/objtool/check.c | 56 +++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 13 deletions(-)
tools/objtool/check.c +43 -13
@@ -3272,11 +3272,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,switch (insn->type) {case INSN_RETURN : -if (opts.sls && !insn->retpoline_safe && - next_insn && next_insn->type !=INSN_TRAP ) { -WARN_FUNC ("missing int3 after ret" , - insn->sec, insn->offset); - }return validate_return (func, insn, &state);case INSN_CALL :
@@ -3320,13 +3315,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,break ;case INSN_JUMP_DYNAMIC : -if (opts.sls && !insn->retpoline_safe && - next_insn && next_insn->type !=INSN_TRAP ) { -WARN_FUNC ("missing int3 after indirect jump" , - insn->sec, insn->offset); - } - -/* fallthrough */ case INSN_JUMP_DYNAMIC_CONDITIONAL :if (is_sibling_call (insn)) { ret =validate_sibling_call (file, insn, &state);
@@ -3846,6 +3834,41 @@ static int validate_ibt(struct objtool_file *file)return warnings; } +static int validate_sls (struct objtool_file *file) +{ +struct instruction *insn, *next_insn; +int warnings =0 ; + +for_each_insn (file, insn) { + next_insn =next_insn_same_sec (file, insn); + +if (insn->retpoline_safe) +continue ; + +switch (insn->type) { +case INSN_RETURN : +if (!next_insn || next_insn->type !=INSN_TRAP ) { +WARN_FUNC ("missing int3 after ret" , + insn->sec, insn->offset); + warnings++; + } + +break ; +case INSN_JUMP_DYNAMIC : +if (!next_insn || next_insn->type !=INSN_TRAP ) { +WARN_FUNC ("missing int3 after indirect jump" , + insn->sec, insn->offset); + warnings++; + } +break ; +default : +break ; + } + } + +return warnings; +} +static int validate_reachable_instructions (struct objtool_file *file) {struct instruction *insn;
@@ -3914,7 +3937,7 @@ int check(struct objtool_file *file) warnings += ret; } -if (opts.stackval || opts.orc || opts.uaccess || opts.sls) { +if (opts.stackval || opts.orc || opts.uaccess) { ret =validate_functions (file);if (ret <0 ) goto out;
@@ -3940,6 +3963,13 @@ int check(struct objtool_file *file) warnings += ret; } +if (opts.sls) { + ret =validate_sls (file); +if (ret <0 ) + goto out; + warnings += ret; + } + ret =create_static_call_sections (file);if (ret <0 ) goto out;
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Extricate sls from stack validation
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: c2bdd61c98d915ad2cc1f8cd4661fcda1f1e4c16 Gitweb: https://git.kernel.org/tip/c2bdd61c98d915ad2cc1f8cd4661fcda1f1e4c16 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:35 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:03 +02:00
objtool: Extricate sls from stack validation
Extricate sls functionality from validate_branch() so they can be executed (or ported) independently from each other.
--- tools/objtool/check.c | 56 ++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 13 deletions(-)
tools/objtool/check.c +43 -13
@@ -3271,11 +3271,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,switch (insn->type) {case INSN_RETURN : -if (opts.sls && !insn->retpoline_safe && - next_insn && next_insn->type !=INSN_TRAP ) { -WARN_FUNC ("missing int3 after ret" , - insn->sec, insn->offset); - }return validate_return (func, insn, &state);case INSN_CALL :
@@ -3319,13 +3314,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,break ;case INSN_JUMP_DYNAMIC : -if (opts.sls && !insn->retpoline_safe && - next_insn && next_insn->type !=INSN_TRAP ) { -WARN_FUNC ("missing int3 after indirect jump" , - insn->sec, insn->offset); - } - -/* fallthrough */ case INSN_JUMP_DYNAMIC_CONDITIONAL :if (is_sibling_call (insn)) { ret =validate_sibling_call (file, insn, &state);
@@ -3845,6 +3833,41 @@ static int validate_ibt(struct objtool_file *file)return warnings; } +static int validate_sls (struct objtool_file *file) +{ +struct instruction *insn, *next_insn; +int warnings =0 ; + +for_each_insn (file, insn) { + next_insn =next_insn_same_sec (file, insn); + +if (insn->retpoline_safe) +continue ; + +switch (insn->type) { +case INSN_RETURN : +if (!next_insn || next_insn->type !=INSN_TRAP ) { +WARN_FUNC ("missing int3 after ret" , + insn->sec, insn->offset); + warnings++; + } + +break ; +case INSN_JUMP_DYNAMIC : +if (!next_insn || next_insn->type !=INSN_TRAP ) { +WARN_FUNC ("missing int3 after indirect jump" , + insn->sec, insn->offset); + warnings++; + } +break ; +default : +break ; + } + } + +return warnings; +} +static int validate_reachable_instructions (struct objtool_file *file) {struct instruction *insn;
@@ -3913,7 +3936,7 @@ int check(struct objtool_file *file) warnings += ret; } -if (opts.stackval || opts.orc || opts.uaccess || opts.sls) { +if (opts.stackval || opts.orc || opts.uaccess) { ret =validate_functions (file);if (ret <0 ) goto out;
@@ -3939,6 +3962,13 @@ int check(struct objtool_file *file) warnings += ret; } +if (opts.sls) { + ret =validate_sls (file); +if (ret <0 ) + goto out; + warnings += ret; + } + ret =create_static_call_sections (file);if (ret <0 ) goto out;
PATCH v2 17/25 objtool: Add CONFIG_OBJTOOL
In reply to Josh PoimboeufNow that stack validation is an optional feature of objtool, add CONFIG_OBJTOOL and replace most usages of CONFIG_STACK_VALIDATION with it.
CONFIG_STACK_VALIDATION can now be considered to be frame-pointer specific. CONFIG_UNWINDER_ORC is already inherently valid for live patching, so no need to "validate" it.
--- Makefile | 2 +- arch/Kconfig | 8 ++++++-- arch/x86/Kconfig | 18 ++++++++++------- arch/x86/Kconfig.debug | 2 +- arch/x86/include/asm/jump_label.h | 6 +++--- arch/x86/kernel/alternative.c | 6 +++--- include/linux/compiler.h | 6 +++--- include/linux/instrumentation.h | 6 +++--- include/linux/objtool.h | 6 +++--- kernel/trace/Kconfig | 1 + lib/Kconfig.debug | 20 ++++++++++--------- lib/Kconfig.kcsan | 3 ++- lib/Kconfig.ubsan | 2 +- scripts/Makefile.build | 4 ++-- scripts/link-vmlinux.sh | 32 +++++++++++++++++-------------- scripts/package/builddeb | 2 +- tools/include/linux/objtool.h | 6 +++--- 17 files changed, 73 insertions(+), 57 deletions(-)
Makefile +1 -1
@@ -1302,7 +1302,7 @@ install: sub_make_done := # --------------------------------------------------------------------------- # Tools -ifdef CONFIG_STACK_VALIDATION +ifdef CONFIG_OBJTOOL prepare: tools/objtool endif
arch/Kconfig +6 -2
@@ -1028,11 +1028,14 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT depends on MMU select ARCH_HAS_ELF_RANDOMIZE +config HAVE_OBJTOOL + bool + config HAVE_STACK_VALIDATION bool help - Architecture supports the 'objtool check' host tool command, which - performs compile-time stack metadata validation. + Architecture supports objtool compile-time frame pointer rule + validation. config HAVE_RELIABLE_STACKTRACE bool
@@ -1302,6 +1305,7 @@ config HAVE_STATIC_CALL config HAVE_STATIC_CALL_INLINE bool depends on HAVE_STATIC_CALL + select OBJTOOL config HAVE_PREEMPT_DYNAMIC bool
arch/x86/Kconfig +11 -7
@@ -188,7 +188,7 @@ config X86 select HAVE_CONTEXT_TRACKING if X86_64 select HAVE_CONTEXT_TRACKING_OFFSTACK if HAVE_CONTEXT_TRACKING select HAVE_C_RECORDMCOUNT - select HAVE_OBJTOOL_MCOUNT if STACK_VALIDATION + select HAVE_OBJTOOL_MCOUNT if HAVE_OBJTOOL select HAVE_BUILDTIME_MCOUNT_SORT select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS
@@ -231,6 +231,7 @@ config X86 select HAVE_MOVE_PMD select HAVE_MOVE_PUD select HAVE_NMI + select HAVE_OBJTOOL if X86_64 select HAVE_OPTPROBES select HAVE_PCSPKR_PLATFORM select HAVE_PERF_EVENTS
@@ -239,17 +240,17 @@ config X86 select HAVE_PCI select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP - select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT + select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API - select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || UNWINDER_ORC) && STACK_VALIDATION + select HAVE_RELIABLE_STACKTRACE if UNWINDER_ORC || STACK_VALIDATION select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_SETUP_PER_CPU_AREA select HAVE_SOFTIRQ_ON_OWN_STACK select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR - select HAVE_STACK_VALIDATION if X86_64 + select HAVE_STACK_VALIDATION if HAVE_OBJTOOL select HAVE_STATIC_CALL - select HAVE_STATIC_CALL_INLINE if HAVE_STACK_VALIDATION + select HAVE_STATIC_CALL_INLINE if HAVE_OBJTOOL select HAVE_PREEMPT_DYNAMIC_CALL select HAVE_RSEQ select HAVE_SYSCALL_TRACEPOINTS
@@ -268,7 +269,6 @@ config X86 select RTC_MC146818_LIB select SPARSE_IRQ select SRCU - select STACK_VALIDATION if HAVE_STACK_VALIDATION && (HAVE_STATIC_CALL_INLINE || RETPOLINE) select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT
@@ -459,6 +459,7 @@ config GOLDFISH config RETPOLINE bool "Avoid speculative indirect branches in kernel" + select OBJTOOL if HAVE_OBJTOOL default y help Compile kernel with the retpoline compiler options to guard against
@@ -472,6 +473,7 @@ config CC_HAS_SLS config SLS bool "Mitigate Straight-Line-Speculation" depends on CC_HAS_SLS && X86_64 + select OBJTOOL if HAVE_OBJTOOL default n help Compile the kernel with straight-line-speculation options to guard
@@ -1819,6 +1821,7 @@ config ARCH_RANDOM config X86_SMAP def_bool y prompt "Supervisor Mode Access Prevention" if EXPERT + select OBJTOOL if HAVE_OBJTOOL help Supervisor Mode Access Prevention (SMAP) is a security feature in newer Intel processors. There is a small
@@ -1855,9 +1858,10 @@ config CC_HAS_IBT config X86_KERNEL_IBT prompt "Indirect Branch Tracking" bool - depends on X86_64 && CC_HAS_IBT && STACK_VALIDATION + depends on X86_64 && CC_HAS_IBT && HAVE_OBJTOOL # https://github.com/llvm/llvm-project/commit/9d7001eba9c4cb311e03cd8cdc231f9e579f2d0f depends on !LD_IS_LLD || LLD_VERSION >= 140000 + select OBJTOOL help Build the kernel with support for Indirect Branch Tracking, a hardware support course-grain forward-edge Control Flow Integrity
arch/x86/Kconfig.debug +1 -1
@@ -237,7 +237,7 @@ choice config UNWINDER_ORC bool "ORC unwinder" depends on X86_64 - select STACK_VALIDATION + select OBJTOOL help This option enables the ORC (Oops Rewind Capability) unwinder for unwinding kernel stack traces. It uses a custom data format which is
arch/x86/include/asm/jump_label.h +3 -3
@@ -20,7 +20,7 @@ _ASM_PTR"%c0 + %c1 - .\n\t" \".popsection \n\t" -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL static __always_inline bool arch_static_branch(struct static_key *key, bool branch) {
@@ -34,7 +34,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool branreturn true; } -#else +#else /* !CONFIG_OBJTOOL */ static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch) {
@@ -48,7 +48,7 @@ static __always_inline bool arch_static_branch(struct static_key * const key, coreturn true; } -#endif /* STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch) {
arch/x86/kernel/alternative.c +3 -3
@@ -338,7 +338,7 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start, } } -#if defined(CONFIG_RETPOLINE ) && defined(CONFIG_STACK_VALIDATION ) +#if defined(CONFIG_RETPOLINE ) && defined(CONFIG_OBJTOOL )/* * CALL/JMP *%\reg
@@ -507,11 +507,11 @@ void __init_or_module noinline apply_retpolines(s32 *start, s32 *end) } } -#else /* !RETPOLINES || !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_RETPOLINE || !CONFIG_OBJTOOL */ void __init_or_module noinline apply_retpolines(s32 *start, s32 *end) { } -#endif /* CONFIG_RETPOLINE && CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_RETPOLINE && CONFIG_OBJTOOL */ #ifdef CONFIG_X86_KERNEL_IBT
include/linux/compiler.h +3 -3
@@ -109,7 +109,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,#endif /* Unreachable code */ -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL /* * These macros help objtool understand GCC code flow for unreachable code. * The __COUNTER__ based labels are a hack to make each instance of the macros
@@ -128,10 +128,10 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,/* Annotate a C jump table to allow objtool to follow the code flow */ #define __annotate_jump_table __section(".rodata..c_jump_table") -#else +#else /* !CONFIG_OBJTOOL */ #define annotate_unreachable ()#define __annotate_jump_table -#endif +#endif /* CONFIG_OBJTOOL */ #ifndef unreachable# define unreachable () do { \
include/linux/instrumentation.h +3 -3
@@ -2,7 +2,7 @@#ifndef __LINUX_INSTRUMENTATION_H#define __LINUX_INSTRUMENTATION_H -#if defined(CONFIG_DEBUG_ENTRY ) && defined(CONFIG_STACK_VALIDATION ) +#ifdef CONFIG_VMLINUX_VALIDATION #include <linux/stringify.h>
@@ -53,9 +53,9 @@ ".popsection\n\t" : : "i" (c)); \ })#define instrumentation_end () __instrumentation_end(__COUNTER__) -#else +#else /* !CONFIG_VMLINUX_VALIDATION */ # define instrumentation_begin () do { } while(0)# define instrumentation_end () do { } while(0) -#endif +#endif /* CONFIG_VMLINUX_VALIDATION */ #endif /* __LINUX_INSTRUMENTATION_H */
include/linux/objtool.h +3 -3
@@ -38,7 +38,7 @@ struct unwind_hint {#define UNWIND_HINT_TYPE_REGS_PARTIAL 2#define UNWIND_HINT_TYPE_FUNC 3 -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL #ifndef __ASSEMBLY__
@@ -157,7 +157,7 @@ struct unwind_hint {#endif /* __ASSEMBLY__ */ -#else /* !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_OBJTOOL */ #ifndef __ASSEMBLY__
@@ -179,6 +179,6 @@ struct unwind_hint { .endm#endif -#endif /* CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ #endif /* _LINUX_OBJTOOL_H */
kernel/trace/Kconfig +1 -0
@@ -728,6 +728,7 @@ config FTRACE_MCOUNT_USE_OBJTOOL depends on !FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY depends on !FTRACE_MCOUNT_USE_CC depends on FTRACE_MCOUNT_RECORD + select OBJTOOL config FTRACE_MCOUNT_USE_RECORDMCOUNT def_bool y
lib/Kconfig.debug +11 -9
@@ -485,24 +485,25 @@ config FRAME_POINTER larger and slower, but it gives very useful debugging information in case of kernel bugs. (precise oopses/stacktraces/warnings) +config OBJTOOL + bool + config STACK_VALIDATION bool "Compile-time stack metadata validation" - depends on HAVE_STACK_VALIDATION + depends on HAVE_STACK_VALIDATION && UNWINDER_FRAME_POINTER + select OBJTOOL default n help - Add compile-time checks to validate stack metadata, including frame - pointers (if CONFIG_FRAME_POINTER is enabled). This helps ensure - that runtime stack traces are more reliable. - - This is also a prerequisite for generation of ORC unwind data, which - is needed for CONFIG_UNWINDER_ORC. + Validate frame pointer rules at compile-time. This helps ensure that + runtime stack traces are more reliable. For more information, see tools/objtool/Documentation/stack-validation.txt. config VMLINUX_VALIDATION bool - depends on STACK_VALIDATION && DEBUG_ENTRY + depends on HAVE_OBJTOOL && DEBUG_ENTRY + select OBJTOOL default y config VMLINUX_MAP
@@ -2035,10 +2036,11 @@ config KCOV bool "Code coverage for fuzzing" depends on ARCH_HAS_KCOV depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS - depends on !ARCH_WANTS_NO_INSTR || STACK_VALIDATION || \ + depends on !ARCH_WANTS_NO_INSTR || HAVE_OBJTOOL || \ GCC_VERSION >= 120000 || CLANG_VERSION >= 130000 select DEBUG_FS select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC + select OBJTOOL if HAVE_OBJTOOL help KCOV exposes kernel code coverage information in a form suitable for coverage-guided fuzzing (randomized testing).
lib/Kconfig.kcsan +2 -1
@@ -187,7 +187,8 @@ config KCSAN_WEAK_MEMORY # We can either let objtool nop __tsan_func_{entry,exit}() and builtin # atomics instrumentation in .noinstr.text, or use a compiler that can # implement __no_kcsan to really remove all instrumentation. - depends on STACK_VALIDATION || CC_IS_GCC || CLANG_VERSION >= 140000 + depends on HAVE_OBJTOOL || CC_IS_GCC || CLANG_VERSION >= 140000 + select OBJTOOL if HAVE_OBJTOOL help Enable support for modeling a subset of weak memory, which allows detecting a subset of data races due to missing memory barriers.
lib/Kconfig.ubsan +1 -1
@@ -94,7 +94,7 @@ config UBSAN_UNREACHABLE bool "Perform checking for unreachable code" # objtool already handles unreachable checking and gets angry about # seeing UBSan instrumentation located in unreachable places. - depends on !STACK_VALIDATION + depends on !(OBJTOOL && (STACK_VALIDATION || UNWINDER_ORC || X86_SMAP)) depends on $(cc-option,-fsanitize=unreachable) help This option enables -fsanitize=unreachable which checks for control
scripts/Makefile.build +2 -2
@@ -222,7 +222,7 @@ cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), $(sub_cmd_record_mcount)) endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT -ifdef CONFIG_STACK_VALIDATION +ifdef CONFIG_OBJTOOL objtool := $(objtree)/tools/objtool/objtool
@@ -241,7 +241,7 @@ objtool_args = \ cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) -endif # CONFIG_STACK_VALIDATION +endif # CONFIG_OBJTOOL ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
scripts/link-vmlinux.sh +18 -14
@@ -108,8 +108,11 @@ objtool_link() local objtoolcmd; local objtoolopt; - if is_enabled CONFIG_STACK_VALIDATION && \ - ( is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT ); then + if ! is_enabled CONFIG_OBJTOOL; then + return; + fi + + if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file.
@@ -126,10 +129,23 @@ objtool_link() objtoolopt="${objtoolopt} --orc" fi + if is_enabled CONFIG_RETPOLINE; then + objtoolopt="${objtoolopt} --retpoline" + fi + + if is_enabled CONFIG_SLS; then + objtoolopt="${objtoolopt} --sls" + fi + if is_enabled CONFIG_STACK_VALIDATION; then objtoolopt="${objtoolopt} --stackval" fi + if is_enabled CONFIG_X86_SMAP; then + objtoolopt="${objtoolopt} --uaccess" + fi + + objtoolopt="${objtoolopt} --lto" fi
@@ -139,18 +155,6 @@ objtool_link() if [ -n "${objtoolopt}" ]; then - if is_enabled CONFIG_RETPOLINE; then - objtoolopt="${objtoolopt} --retpoline" - fi - - if is_enabled CONFIG_SLS; then - objtoolopt="${objtoolopt} --sls" - fi - - if is_enabled CONFIG_X86_SMAP; then - objtoolopt="${objtoolopt} --uaccess" - fi - if ! is_enabled CONFIG_FRAME_POINTER; then objtoolopt="${objtoolopt} --no-fp" fi
scripts/package/builddeb +1 -1
@@ -67,7 +67,7 @@ deploy_kernel_headers () { ) > debian/hdrsrcfiles { - if is_enabled CONFIG_STACK_VALIDATION; then + if is_enabled CONFIG_OBJTOOL; then echo tools/objtool/objtool fi
tools/include/linux/objtool.h +3 -3
@@ -38,7 +38,7 @@ struct unwind_hint {#define UNWIND_HINT_TYPE_REGS_PARTIAL 2#define UNWIND_HINT_TYPE_FUNC 3 -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL #ifndef __ASSEMBLY__
@@ -157,7 +157,7 @@ struct unwind_hint {#endif /* __ASSEMBLY__ */ -#else /* !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_OBJTOOL */ #ifndef __ASSEMBLY__
@@ -179,6 +179,6 @@ struct unwind_hint { .endm#endif -#endif /* CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ #endif /* _LINUX_OBJTOOL_H */
Signature · 1 line
2.34.1
Re: [PATCH v2 17/25] objtool: Add CONFIG_OBJTOOL
Review
Quoted 7 lines · Josh Poimboeuf
config
X86_SMAP(quoted diff) +1
-0def_bool y prompt "Supervisor Mode Access Prevention" if EXPERT + select OBJTOOL if HAVE_OBJTOOL help Supervisor Mode Access Prevention (SMAP) is a security feature in newer Intel processors. There is a small
Runs into:
commit dbae0a934f09208075ec3e73491bd0844e1397b3
Author: Borislav Petkov <[email protected]> Date: Thu Jan 27 12:56:23 2022 +0100
x86/cpu: Remove CONFIG_X86_SMAP and "nosmap"
Those were added as part of the SMAP enablement but SMAP is currently an integral part of kernel proper and there's no need to disable it anymore.
Rip out that functionality. Leave --uaccess default on for objtool as this is what objtool should do by default anyway.
If still needed - clearcpuid=smap.
Documentation/admin-guide/kernel-parameters.txt +1 -1
@@ -3461,7 +3461,7 @@ noexec=on: enable non-executable mappings (default) noexec=off: disable non-executable mappings - nosmap [X86,PPC] + nosmap [PPC] Disable SMAP (Supervisor Mode Access Prevention) even if it is supported by processor.
Documentation/x86/cpuinfo.rst +2 -3
@@ -140,9 +140,8 @@ from #define X86_FEATURE_UMIP (16*32 + 2). In addition, there exists a variety of custom command-line parameters that disable specific features. The list of parameters includes, but is not limited -to, nofsgsbase, nosmap, and nosmep. 5-level paging can also be disabled using -"no5lvl". SMAP and SMEP are disabled with the aforementioned parameters, -respectively. +to, nofsgsbase, and nosmep. 5-level paging can also be disabled using +"no5lvl". SMEP is disabled with the aforementioned parameter. e: The feature was known to be non-functional. ----------------------------------------------
arch/x86/Kconfig +0 -11
@@ -1816,17 +1816,6 @@ config ARCH_RANDOM If supported, this is a high bandwidth, cryptographically secure hardware random number generator. -config X86_SMAP - def_bool y - prompt "Supervisor Mode Access Prevention" if EXPERT - help - Supervisor Mode Access Prevention (SMAP) is a security - feature in newer Intel processors. There is a small - performance cost if this enabled and turned on; there is - also a small increase in the kernel size if this is enabled. - - If unsure, say Y. - config X86_UMIP def_bool y prompt "User Mode Instruction Prevention" if EXPERT
arch/x86/include/asm/disabled-features.h +1 -7
@@ -10,12 +10,6 @@* cpu_feature_enabled(). */ -#ifdef CONFIG_X86_SMAP -# define DISABLE_SMAP 0 -#else -# define DISABLE_SMAP (1<<(X86_FEATURE_SMAP & 31)) -#endif -#ifdef CONFIG_X86_UMIP # define DISABLE_UMIP 0#else
@@ -80,7 +74,7 @@#define DISABLED_MASK6 0#define DISABLED_MASK7 (DISABLE_PTI)#define DISABLED_MASK8 0 -#define DISABLED_MASK9 (DISABLE_SMAP|DISABLE_SGX) +#define DISABLED_MASK9 (DISABLE_SGX)#define DISABLED_MASK10 0#define DISABLED_MASK11 0#define DISABLED_MASK12 0
arch/x86/include/asm/smap.h +0 -24
@@ -19,25 +19,14 @@#ifdef __ASSEMBLY__ -#ifdef CONFIG_X86_SMAP -#define ASM_CLAC \ ALTERNATIVE "", __ASM_CLAC, X86_FEATURE_SMAP#define ASM_STAC \ ALTERNATIVE "", __ASM_STAC, X86_FEATURE_SMAP -#else /* CONFIG_X86_SMAP */ - -#define ASM_CLAC -#define ASM_STAC - -#endif /* CONFIG_X86_SMAP */ -#else /* __ASSEMBLY__ */ -#ifdef CONFIG_X86_SMAP - static __always_inline void clac(void) {/* Note: a barrier is implicit in alternative() */
@@ -76,19 +65,6 @@ static __always_inline void smap_restore(unsigned long flags)#define ASM_STAC \ ALTERNATIVE("", __ASM_STAC, X86_FEATURE_SMAP) -#else /* CONFIG_X86_SMAP */ - -static inline void clac (void ) { } -static inline void stac (void ) { } - -static inline unsigned long smap_save (void ) {return 0 ; } -static inline void smap_restore (unsigned long flags) { } - -#define ASM_CLAC -#define ASM_STAC - -#endif /* CONFIG_X86_SMAP */ -#endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_SMAP_H */
arch/x86/kernel/cpu/common.c +1 -14
@@ -382,13 +382,6 @@ static __always_inline void setup_smep(struct cpuinfo_x86 *c)cr4_set_bits (X86_CR4_SMEP ); } -static __init int setup_disable_smap (char *arg) -{ -setup_clear_cpu_cap (X86_FEATURE_SMAP ); -return 1 ; -} -__setup ("nosmap" , setup_disable_smap); - static __always_inline void setup_smap(struct cpuinfo_x86 *c) {unsigned long eflags =native_save_fl ();
@@ -396,14 +389,8 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)/* This should have been cleared long ago */ BUG_ON (eflags &X86_EFLAGS_AC ); -if (cpu_has (c,X86_FEATURE_SMAP )) { -#ifdef CONFIG_X86_SMAP +if (cpu_has (c,X86_FEATURE_SMAP ))cr4_set_bits (X86_CR4_SMAP ); -#else -clear_cpu_cap (c,X86_FEATURE_SMAP ); -cr4_clear_bits (X86_CR4_SMAP ); -#endif - } } static __always_inline void setup_umip(struct cpuinfo_x86 *c)
scripts/Makefile.build +1 -1
@@ -233,7 +233,7 @@ objtool_args = \ $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\ $(if $(CONFIG_RETPOLINE), --retpoline) \ - $(if $(CONFIG_X86_SMAP), --uaccess) \ + --uaccess \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_SLS), --sls)
scripts/link-vmlinux.sh +3 -3
@@ -146,9 +146,9 @@ objtool_link() if is_enabled CONFIG_RETPOLINE; then objtoolopt="${objtoolopt} --retpoline" fi - if is_enabled CONFIG_X86_SMAP; then - objtoolopt="${objtoolopt} --uaccess" - fi + + objtoolopt="${objtoolopt} --uaccess" + if is_enabled CONFIG_SLS; then objtoolopt="${objtoolopt} --sls" fi
tools/arch/x86/include/asm/disabled-features.h +1 -7
@@ -10,12 +10,6 @@* cpu_feature_enabled(). */ -#ifdef CONFIG_X86_SMAP -# define DISABLE_SMAP 0 -#else -# define DISABLE_SMAP (1<<(X86_FEATURE_SMAP & 31)) -#endif -#ifdef CONFIG_X86_UMIP # define DISABLE_UMIP 0#else
@@ -80,7 +74,7 @@#define DISABLED_MASK6 0#define DISABLED_MASK7 (DISABLE_PTI)#define DISABLED_MASK8 0 -#define DISABLED_MASK9 (DISABLE_SMAP|DISABLE_SGX) +#define DISABLED_MASK9 (DISABLE_SGX)#define DISABLED_MASK10 0#define DISABLED_MASK11 0#define DISABLED_MASK12 0
[tip: objtool/core] objtool: Add CONFIG_OBJTOOL
In reply to Josh PoimboeufThe following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 03f16cd020eb8bb2eb837e2090086f296a9fa91d Gitweb: https://git.kernel.org/tip/03f16cd020eb8bb2eb837e2090086f296a9fa91d Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:36 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:03 +02:00
objtool: Add CONFIG_OBJTOOL
Now that stack validation is an optional feature of objtool, add CONFIG_OBJTOOL and replace most usages of CONFIG_STACK_VALIDATION with it.
CONFIG_STACK_VALIDATION can now be considered to be frame-pointer specific. CONFIG_UNWINDER_ORC is already inherently valid for live patching, so no need to "validate" it.
--- Makefile | 2 +- arch/Kconfig | 8 ++++++-- arch/x86/Kconfig | 18 ++++++++++------- arch/x86/Kconfig.debug | 2 +- arch/x86/include/asm/jump_label.h | 6 +++--- arch/x86/kernel/alternative.c | 6 +++--- include/linux/compiler.h | 6 +++--- include/linux/instrumentation.h | 6 +++--- include/linux/objtool.h | 6 +++--- kernel/trace/Kconfig | 1 +- lib/Kconfig.debug | 20 ++++++++++--------- lib/Kconfig.kcsan | 3 ++- lib/Kconfig.ubsan | 2 +- scripts/Makefile.build | 4 ++-- scripts/link-vmlinux.sh | 32 ++++++++++++++++-------------- scripts/package/builddeb | 2 +- tools/include/linux/objtool.h | 6 +++--- 17 files changed, 73 insertions(+), 57 deletions(-)
Makefile +1 -1
@@ -1302,7 +1302,7 @@ install: sub_make_done := # --------------------------------------------------------------------------- # Tools -ifdef CONFIG_STACK_VALIDATION +ifdef CONFIG_OBJTOOL prepare: tools/objtool endif
arch/Kconfig +6 -2
@@ -1028,11 +1028,14 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT depends on MMU select ARCH_HAS_ELF_RANDOMIZE +config HAVE_OBJTOOL + bool + config HAVE_STACK_VALIDATION bool help - Architecture supports the 'objtool check' host tool command, which - performs compile-time stack metadata validation. + Architecture supports objtool compile-time frame pointer rule + validation. config HAVE_RELIABLE_STACKTRACE bool
@@ -1302,6 +1305,7 @@ config HAVE_STATIC_CALL config HAVE_STATIC_CALL_INLINE bool depends on HAVE_STATIC_CALL + select OBJTOOL config HAVE_PREEMPT_DYNAMIC bool
arch/x86/Kconfig +11 -7
@@ -188,7 +188,7 @@ config X86 select HAVE_CONTEXT_TRACKING if X86_64 select HAVE_CONTEXT_TRACKING_OFFSTACK if HAVE_CONTEXT_TRACKING select HAVE_C_RECORDMCOUNT - select HAVE_OBJTOOL_MCOUNT if STACK_VALIDATION + select HAVE_OBJTOOL_MCOUNT if HAVE_OBJTOOL select HAVE_BUILDTIME_MCOUNT_SORT select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS
@@ -231,6 +231,7 @@ config X86 select HAVE_MOVE_PMD select HAVE_MOVE_PUD select HAVE_NMI + select HAVE_OBJTOOL if X86_64 select HAVE_OPTPROBES select HAVE_PCSPKR_PLATFORM select HAVE_PERF_EVENTS
@@ -239,17 +240,17 @@ config X86 select HAVE_PCI select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP - select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT + select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API - select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || UNWINDER_ORC) && STACK_VALIDATION + select HAVE_RELIABLE_STACKTRACE if UNWINDER_ORC || STACK_VALIDATION select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_SETUP_PER_CPU_AREA select HAVE_SOFTIRQ_ON_OWN_STACK select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR - select HAVE_STACK_VALIDATION if X86_64 + select HAVE_STACK_VALIDATION if HAVE_OBJTOOL select HAVE_STATIC_CALL - select HAVE_STATIC_CALL_INLINE if HAVE_STACK_VALIDATION + select HAVE_STATIC_CALL_INLINE if HAVE_OBJTOOL select HAVE_PREEMPT_DYNAMIC_CALL select HAVE_RSEQ select HAVE_SYSCALL_TRACEPOINTS
@@ -268,7 +269,6 @@ config X86 select RTC_MC146818_LIB select SPARSE_IRQ select SRCU - select STACK_VALIDATION if HAVE_STACK_VALIDATION && (HAVE_STATIC_CALL_INLINE || RETPOLINE) select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT
@@ -459,6 +459,7 @@ config GOLDFISH config RETPOLINE bool "Avoid speculative indirect branches in kernel" + select OBJTOOL if HAVE_OBJTOOL default y help Compile kernel with the retpoline compiler options to guard against
@@ -472,6 +473,7 @@ config CC_HAS_SLS config SLS bool "Mitigate Straight-Line-Speculation" depends on CC_HAS_SLS && X86_64 + select OBJTOOL if HAVE_OBJTOOL default n help Compile the kernel with straight-line-speculation options to guard
@@ -1819,6 +1821,7 @@ config ARCH_RANDOM config X86_SMAP def_bool y prompt "Supervisor Mode Access Prevention" if EXPERT + select OBJTOOL if HAVE_OBJTOOL help Supervisor Mode Access Prevention (SMAP) is a security feature in newer Intel processors. There is a small
@@ -1855,9 +1858,10 @@ config CC_HAS_IBT config X86_KERNEL_IBT prompt "Indirect Branch Tracking" bool - depends on X86_64 && CC_HAS_IBT && STACK_VALIDATION + depends on X86_64 && CC_HAS_IBT && HAVE_OBJTOOL # https://github.com/llvm/llvm-project/commit/9d7001eba9c4cb311e03cd8cdc231f9e579f2d0f depends on !LD_IS_LLD || LLD_VERSION >= 140000 + select OBJTOOL help Build the kernel with support for Indirect Branch Tracking, a hardware support course-grain forward-edge Control Flow Integrity
arch/x86/Kconfig.debug +1 -1
@@ -237,7 +237,7 @@ choice config UNWINDER_ORC bool "ORC unwinder" depends on X86_64 - select STACK_VALIDATION + select OBJTOOL help This option enables the ORC (Oops Rewind Capability) unwinder for unwinding kernel stack traces. It uses a custom data format which is
arch/x86/include/asm/jump_label.h +3 -3
@@ -20,7 +20,7 @@ _ASM_PTR"%c0 + %c1 - .\n\t" \".popsection \n\t" -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL static __always_inline bool arch_static_branch(struct static_key *key, bool branch) {
@@ -34,7 +34,7 @@ l_yes:return true; } -#else +#else /* !CONFIG_OBJTOOL */ static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch) {
@@ -48,7 +48,7 @@ l_yes:return true; } -#endif /* STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch) {
arch/x86/kernel/alternative.c +3 -3
@@ -338,7 +338,7 @@ next: } } -#if defined(CONFIG_RETPOLINE ) && defined(CONFIG_STACK_VALIDATION ) +#if defined(CONFIG_RETPOLINE ) && defined(CONFIG_OBJTOOL )/* * CALL/JMP *%\reg
@@ -507,11 +507,11 @@ void __init_or_module noinline apply_retpolines(s32 *start, s32 *end) } } -#else /* !RETPOLINES || !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_RETPOLINE || !CONFIG_OBJTOOL */ void __init_or_module noinline apply_retpolines(s32 *start, s32 *end) { } -#endif /* CONFIG_RETPOLINE && CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_RETPOLINE && CONFIG_OBJTOOL */ #ifdef CONFIG_X86_KERNEL_IBT
include/linux/compiler.h +3 -3
@@ -109,7 +109,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,#endif /* Unreachable code */ -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL /* * These macros help objtool understand GCC code flow for unreachable code. * The __COUNTER__ based labels are a hack to make each instance of the macros
@@ -128,10 +128,10 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,/* Annotate a C jump table to allow objtool to follow the code flow */ #define __annotate_jump_table __section(".rodata..c_jump_table") -#else +#else /* !CONFIG_OBJTOOL */ #define annotate_unreachable ()#define __annotate_jump_table -#endif +#endif /* CONFIG_OBJTOOL */ #ifndef unreachable# define unreachable () do { \
include/linux/instrumentation.h +3 -3
@@ -2,7 +2,7 @@#ifndef __LINUX_INSTRUMENTATION_H#define __LINUX_INSTRUMENTATION_H -#if defined(CONFIG_DEBUG_ENTRY ) && defined(CONFIG_STACK_VALIDATION ) +#ifdef CONFIG_VMLINUX_VALIDATION #include <linux/stringify.h>
@@ -53,9 +53,9 @@ ".popsection\n\t" : : "i" (c)); \ })#define instrumentation_end () __instrumentation_end(__COUNTER__) -#else +#else /* !CONFIG_VMLINUX_VALIDATION */ # define instrumentation_begin () do { } while(0)# define instrumentation_end () do { } while(0) -#endif +#endif /* CONFIG_VMLINUX_VALIDATION */ #endif /* __LINUX_INSTRUMENTATION_H */
include/linux/objtool.h +3 -3
@@ -38,7 +38,7 @@ struct unwind_hint {#define UNWIND_HINT_TYPE_REGS_PARTIAL 2#define UNWIND_HINT_TYPE_FUNC 3 -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL #ifndef __ASSEMBLY__
@@ -157,7 +157,7 @@ struct unwind_hint {#endif /* __ASSEMBLY__ */ -#else /* !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_OBJTOOL */ #ifndef __ASSEMBLY__
@@ -179,6 +179,6 @@ struct unwind_hint { .endm#endif -#endif /* CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ #endif /* _LINUX_OBJTOOL_H */
kernel/trace/Kconfig +1 -0
@@ -728,6 +728,7 @@ config FTRACE_MCOUNT_USE_OBJTOOL depends on !FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY depends on !FTRACE_MCOUNT_USE_CC depends on FTRACE_MCOUNT_RECORD + select OBJTOOL config FTRACE_MCOUNT_USE_RECORDMCOUNT def_bool y
lib/Kconfig.debug +11 -9
@@ -485,24 +485,25 @@ config FRAME_POINTER larger and slower, but it gives very useful debugging information in case of kernel bugs. (precise oopses/stacktraces/warnings) +config OBJTOOL + bool + config STACK_VALIDATION bool "Compile-time stack metadata validation" - depends on HAVE_STACK_VALIDATION + depends on HAVE_STACK_VALIDATION && UNWINDER_FRAME_POINTER + select OBJTOOL default n help - Add compile-time checks to validate stack metadata, including frame - pointers (if CONFIG_FRAME_POINTER is enabled). This helps ensure - that runtime stack traces are more reliable. - - This is also a prerequisite for generation of ORC unwind data, which - is needed for CONFIG_UNWINDER_ORC. + Validate frame pointer rules at compile-time. This helps ensure that + runtime stack traces are more reliable. For more information, see tools/objtool/Documentation/stack-validation.txt. config VMLINUX_VALIDATION bool - depends on STACK_VALIDATION && DEBUG_ENTRY + depends on HAVE_OBJTOOL && DEBUG_ENTRY + select OBJTOOL default y config VMLINUX_MAP
@@ -2035,10 +2036,11 @@ config KCOV bool "Code coverage for fuzzing" depends on ARCH_HAS_KCOV depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS - depends on !ARCH_WANTS_NO_INSTR || STACK_VALIDATION || \ + depends on !ARCH_WANTS_NO_INSTR || HAVE_OBJTOOL || \ GCC_VERSION >= 120000 || CLANG_VERSION >= 130000 select DEBUG_FS select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC + select OBJTOOL if HAVE_OBJTOOL help KCOV exposes kernel code coverage information in a form suitable for coverage-guided fuzzing (randomized testing).
lib/Kconfig.kcsan +2 -1
@@ -187,7 +187,8 @@ config KCSAN_WEAK_MEMORY # We can either let objtool nop __tsan_func_{entry,exit}() and builtin # atomics instrumentation in .noinstr.text, or use a compiler that can # implement __no_kcsan to really remove all instrumentation. - depends on STACK_VALIDATION || CC_IS_GCC || CLANG_VERSION >= 140000 + depends on HAVE_OBJTOOL || CC_IS_GCC || CLANG_VERSION >= 140000 + select OBJTOOL if HAVE_OBJTOOL help Enable support for modeling a subset of weak memory, which allows detecting a subset of data races due to missing memory barriers.
lib/Kconfig.ubsan +1 -1
@@ -94,7 +94,7 @@ config UBSAN_UNREACHABLE bool "Perform checking for unreachable code" # objtool already handles unreachable checking and gets angry about # seeing UBSan instrumentation located in unreachable places. - depends on !STACK_VALIDATION + depends on !(OBJTOOL && (STACK_VALIDATION || UNWINDER_ORC || X86_SMAP)) depends on $(cc-option,-fsanitize=unreachable) help This option enables -fsanitize=unreachable which checks for control
scripts/Makefile.build +2 -2
@@ -222,7 +222,7 @@ cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), $(sub_cmd_record_mcount)) endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT -ifdef CONFIG_STACK_VALIDATION +ifdef CONFIG_OBJTOOL objtool := $(objtree)/tools/objtool/objtool
@@ -241,7 +241,7 @@ objtool_args = \ cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) -endif # CONFIG_STACK_VALIDATION +endif # CONFIG_OBJTOOL ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
scripts/link-vmlinux.sh +18 -14
@@ -108,8 +108,11 @@ objtool_link() local objtoolcmd; local objtoolopt; - if is_enabled CONFIG_STACK_VALIDATION && \ - ( is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT ); then + if ! is_enabled CONFIG_OBJTOOL; then + return; + fi + + if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file.
@@ -126,10 +129,23 @@ objtool_link() objtoolopt="${objtoolopt} --orc" fi + if is_enabled CONFIG_RETPOLINE; then + objtoolopt="${objtoolopt} --retpoline" + fi + + if is_enabled CONFIG_SLS; then + objtoolopt="${objtoolopt} --sls" + fi + if is_enabled CONFIG_STACK_VALIDATION; then objtoolopt="${objtoolopt} --stackval" fi + if is_enabled CONFIG_X86_SMAP; then + objtoolopt="${objtoolopt} --uaccess" + fi + + objtoolopt="${objtoolopt} --lto" fi
@@ -139,18 +155,6 @@ objtool_link() if [ -n "${objtoolopt}" ]; then - if is_enabled CONFIG_RETPOLINE; then - objtoolopt="${objtoolopt} --retpoline" - fi - - if is_enabled CONFIG_SLS; then - objtoolopt="${objtoolopt} --sls" - fi - - if is_enabled CONFIG_X86_SMAP; then - objtoolopt="${objtoolopt} --uaccess" - fi - if ! is_enabled CONFIG_FRAME_POINTER; then objtoolopt="${objtoolopt} --no-fp" fi
scripts/package/builddeb +1 -1
@@ -67,7 +67,7 @@ deploy_kernel_headers () { ) > debian/hdrsrcfiles { - if is_enabled CONFIG_STACK_VALIDATION; then + if is_enabled CONFIG_OBJTOOL; then echo tools/objtool/objtool fi
tools/include/linux/objtool.h +3 -3
@@ -38,7 +38,7 @@ struct unwind_hint {#define UNWIND_HINT_TYPE_REGS_PARTIAL 2#define UNWIND_HINT_TYPE_FUNC 3 -#ifdef CONFIG_STACK_VALIDATION +#ifdef CONFIG_OBJTOOL #ifndef __ASSEMBLY__
@@ -157,7 +157,7 @@ struct unwind_hint {#endif /* __ASSEMBLY__ */ -#else /* !CONFIG_STACK_VALIDATION */ +#else /* !CONFIG_OBJTOOL */ #ifndef __ASSEMBLY__
@@ -179,6 +179,6 @@ struct unwind_hint { .endm#endif -#endif /* CONFIG_STACK_VALIDATION */ +#endif /* CONFIG_OBJTOOL */ #endif /* _LINUX_OBJTOOL_H */
PATCH v2 18/25 objtool: Make stack validation frame-pointer-specific
In reply to Josh PoimboeufNow that CONFIG_STACK_VALIDATION is frame-pointer specific, do the same for the '--stackval' option. Now the '--no-fp' option is redundant and can be removed.
--- scripts/Makefile.build | 1 - scripts/link-vmlinux.sh | 4 ---- tools/objtool/builtin-check.c | 3 +-- tools/objtool/check.c | 4 ++-- tools/objtool/include/objtool/builtin.h | 1 - 5 files changed, 3 insertions(+), 10 deletions(-)
scripts/Makefile.build +0 -1
@@ -235,7 +235,6 @@ objtool_args = \ $(if $(CONFIG_STACK_VALIDATION), --stackval) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(part-of-module), --module) \ - $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
scripts/link-vmlinux.sh +0 -4
@@ -155,10 +155,6 @@ objtool_link() if [ -n "${objtoolopt}" ]; then - if ! is_enabled CONFIG_FRAME_POINTER; then - objtoolopt="${objtoolopt} --no-fp" - fi - if is_enabled CONFIG_GCOV_KERNEL; then objtoolopt="${objtoolopt} --no-unreachable" fi
tools/objtool/builtin-check.c +1 -2
@@ -39,7 +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 ('s' ,"stackval" , &opts.stackval,"validate frame pointer rules" ),OPT_BOOLEAN ('u' ,"uaccess" , &opts.uaccess,"validate uaccess rules for SMAP" ), OPT_CALLBACK_OPTARG(0, "dump", NULL, NULL, "orc", "dump metadata", parse_dump),
@@ -49,7 +49,6 @@ const struct option check_options[] = {OPT_BOOLEAN (0 ,"dry-run" , &opts.dryrun,"don't write modifications" ),OPT_BOOLEAN (0 ,"lto" , &opts.lto,"whole-archive like runs" ),OPT_BOOLEAN (0 ,"module" , &opts.module,"object is part of a kernel module" ), -OPT_BOOLEAN (0 ,"no-fp" , &opts.no_fp,"skip frame pointer validation" ),OPT_BOOLEAN (0 ,"no-unreachable" , &opts.no_unreachable,"skip 'unreachable instruction' warnings" ),OPT_BOOLEAN (0 ,"sec-address" , &opts.sec_address,"print section addresses in warnings" ), OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"),
tools/objtool/check.c +2 -2
@@ -2807,7 +2807,7 @@ static int update_cfi_state(struct instruction *insn, }/* detect when asm code uses rbp as a scratch register */ -if (!opts.no_fp && insn->func && op->src.reg ==CFI_BP && +if (opts.stackval && insn->func && op->src.reg ==CFI_BP && cfa->base !=CFI_BP ) cfi->bp_scratch = true;break ;
@@ -3280,7 +3280,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,if (ret)return ret; -if (!opts.no_fp && func && !is_fentry_call (insn) && +if (opts.stackval && func && !is_fentry_call (insn) && !has_valid_stack_frame (&state)) {WARN_FUNC ("call without frame pointer save/setup" , sec, insn->offset);
tools/objtool/include/objtool/builtin.h +0 -1
@@ -27,7 +27,6 @@ struct opts {bool dryrun;bool lto;bool module; -bool no_fp;bool no_unreachable;bool sec_address;bool stats;
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Make stack validation frame-pointer-specific
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 72064474964724c59ddff58a581a31b1ede75cf9 Gitweb: https://git.kernel.org/tip/72064474964724c59ddff58a581a31b1ede75cf9 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:37 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:03 +02:00
objtool: Make stack validation frame-pointer-specific
Now that CONFIG_STACK_VALIDATION is frame-pointer specific, do the same for the '--stackval' option. Now the '--no-fp' option is redundant and can be removed.
--- scripts/Makefile.build | 1 - scripts/link-vmlinux.sh | 4 ---- tools/objtool/builtin-check.c | 3 +-- tools/objtool/check.c | 4 ++-- tools/objtool/include/objtool/builtin.h | 1 - 5 files changed, 3 insertions(+), 10 deletions(-)
scripts/Makefile.build +0 -1
@@ -235,7 +235,6 @@ objtool_args = \ $(if $(CONFIG_STACK_VALIDATION), --stackval) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(part-of-module), --module) \ - $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
scripts/link-vmlinux.sh +0 -4
@@ -155,10 +155,6 @@ objtool_link() if [ -n "${objtoolopt}" ]; then - if ! is_enabled CONFIG_FRAME_POINTER; then - objtoolopt="${objtoolopt} --no-fp" - fi - if is_enabled CONFIG_GCOV_KERNEL; then objtoolopt="${objtoolopt} --no-unreachable" fi
tools/objtool/builtin-check.c +1 -2
@@ -39,7 +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 ('s' ,"stackval" , &opts.stackval,"validate frame pointer rules" ),OPT_BOOLEAN ('u' ,"uaccess" , &opts.uaccess,"validate uaccess rules for SMAP" ), OPT_CALLBACK_OPTARG(0, "dump", NULL, NULL, "orc", "dump metadata", parse_dump),
@@ -49,7 +49,6 @@ const struct option check_options[] = {OPT_BOOLEAN (0 ,"dry-run" , &opts.dryrun,"don't write modifications" ),OPT_BOOLEAN (0 ,"lto" , &opts.lto,"whole-archive like runs" ),OPT_BOOLEAN (0 ,"module" , &opts.module,"object is part of a kernel module" ), -OPT_BOOLEAN (0 ,"no-fp" , &opts.no_fp,"skip frame pointer validation" ),OPT_BOOLEAN (0 ,"no-unreachable" , &opts.no_unreachable,"skip 'unreachable instruction' warnings" ),OPT_BOOLEAN (0 ,"sec-address" , &opts.sec_address,"print section addresses in warnings" ), OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"),
tools/objtool/check.c +2 -2
@@ -2806,7 +2806,7 @@ static int update_cfi_state(struct instruction *insn, }/* detect when asm code uses rbp as a scratch register */ -if (!opts.no_fp && insn->func && op->src.reg ==CFI_BP && +if (opts.stackval && insn->func && op->src.reg ==CFI_BP && cfa->base !=CFI_BP ) cfi->bp_scratch = true;break ;
@@ -3279,7 +3279,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,if (ret)return ret; -if (!opts.no_fp && func && !is_fentry_call (insn) && +if (opts.stackval && func && !is_fentry_call (insn) && !has_valid_stack_frame (&state)) {WARN_FUNC ("call without frame pointer save/setup" , sec, insn->offset);
tools/objtool/include/objtool/builtin.h +0 -1
@@ -27,7 +27,6 @@ struct opts {bool dryrun;bool lto;bool module; -bool no_fp;bool no_unreachable;bool sec_address;bool stats;
PATCH v2 19/25 objtool: Make static call annotation optional
In reply to Josh PoimboeufAs part of making objtool more modular, put the existing static call code behind a new '--static-call' option.
--- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 5 ++++- tools/objtool/builtin-check.c | 2 ++ tools/objtool/check.c | 10 ++++++---- tools/objtool/include/objtool/builtin.h | 1 + 5 files changed, 14 insertions(+), 5 deletions(-)
scripts/Makefile.build +1 -0
@@ -233,6 +233,7 @@ objtool_args = \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_STACK_VALIDATION), --stackval) \ + $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(part-of-module), --module) \ $(if $(CONFIG_GCOV_KERNEL), --no-unreachable)
scripts/link-vmlinux.sh +4 -1
@@ -141,11 +141,14 @@ objtool_link() objtoolopt="${objtoolopt} --stackval" fi + if is_enabled CONFIG_HAVE_STATIC_CALL_INLINE; then + objtoolopt="${objtoolopt} --static-call" + fi + if is_enabled CONFIG_X86_SMAP; then objtoolopt="${objtoolopt} --uaccess" fi - objtoolopt="${objtoolopt} --lto" fi
tools/objtool/builtin-check.c +2 -0
@@ -40,6 +40,7 @@ const struct option check_options[] = {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 frame pointer rules" ), +OPT_BOOLEAN ('t' ,"static-call" , &opts.static_call,"annotate static calls" ),OPT_BOOLEAN ('u' ,"uaccess" , &opts.uaccess,"validate uaccess rules for SMAP" ), OPT_CALLBACK_OPTARG(0, "dump", NULL, NULL, "orc", "dump metadata", parse_dump),
@@ -93,6 +94,7 @@ static bool opts_valid(void) opts.retpoline || opts.sls || opts.stackval || + opts.static_call || opts.uaccess) {if (opts.dump_orc) {fprintf (stderr,"--dump can't be combined with other options\n" );
tools/objtool/check.c +6 -4
@@ -3970,10 +3970,12 @@ int check(struct objtool_file *file) warnings += ret; } - ret =create_static_call_sections (file); -if (ret <0 ) - goto out; - warnings += ret; +if (opts.static_call) { + ret =create_static_call_sections (file); +if (ret <0 ) + goto out; + warnings += ret; + }if (opts.retpoline) { ret =create_retpoline_sites_sections (file);
tools/objtool/include/objtool/builtin.h +1 -0
@@ -19,6 +19,7 @@ struct opts {bool retpoline;bool sls;bool stackval; +bool static_call;bool uaccess;/* options: */
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Make static call annotation optional
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 26e176896a5bb9222ae3433da902edd2566a61a4 Gitweb: https://git.kernel.org/tip/26e176896a5bb9222ae3433da902edd2566a61a4 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:38 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:03 +02:00
objtool: Make static call annotation optional
As part of making objtool more modular, put the existing static call code behind a new '--static-call' option.
--- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 5 ++++- tools/objtool/builtin-check.c | 2 ++ tools/objtool/check.c | 10 ++++++---- tools/objtool/include/objtool/builtin.h | 1 + 5 files changed, 14 insertions(+), 5 deletions(-)
scripts/Makefile.build +1 -0
@@ -233,6 +233,7 @@ objtool_args = \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_SLS), --sls) \ $(if $(CONFIG_STACK_VALIDATION), --stackval) \ + $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(part-of-module), --module) \ $(if $(CONFIG_GCOV_KERNEL), --no-unreachable)
scripts/link-vmlinux.sh +4 -1
@@ -141,11 +141,14 @@ objtool_link() objtoolopt="${objtoolopt} --stackval" fi + if is_enabled CONFIG_HAVE_STATIC_CALL_INLINE; then + objtoolopt="${objtoolopt} --static-call" + fi + if is_enabled CONFIG_X86_SMAP; then objtoolopt="${objtoolopt} --uaccess" fi - objtoolopt="${objtoolopt} --lto" fi
tools/objtool/builtin-check.c +2 -0
@@ -40,6 +40,7 @@ const struct option check_options[] = {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 frame pointer rules" ), +OPT_BOOLEAN ('t' ,"static-call" , &opts.static_call,"annotate static calls" ),OPT_BOOLEAN ('u' ,"uaccess" , &opts.uaccess,"validate uaccess rules for SMAP" ), OPT_CALLBACK_OPTARG(0, "dump", NULL, NULL, "orc", "dump metadata", parse_dump),
@@ -93,6 +94,7 @@ static bool opts_valid(void) opts.retpoline || opts.sls || opts.stackval || + opts.static_call || opts.uaccess) {if (opts.dump_orc) {fprintf (stderr,"--dump can't be combined with other options\n" );
tools/objtool/check.c +6 -4
@@ -3969,10 +3969,12 @@ int check(struct objtool_file *file) warnings += ret; } - ret =create_static_call_sections (file); -if (ret <0 ) - goto out; - warnings += ret; +if (opts.static_call) { + ret =create_static_call_sections (file); +if (ret <0 ) + goto out; + warnings += ret; + }if (opts.retpoline) { ret =create_retpoline_sites_sections (file);
tools/objtool/include/objtool/builtin.h +1 -0
@@ -19,6 +19,7 @@ struct opts {bool retpoline;bool sls;bool stackval; +bool static_call;bool uaccess;/* options: */
PATCH v2 20/25 objtool: Make jump label hack optional
In reply to Josh PoimboeufObjtool secretly does a jump label hack to overcome the limitations of the toolchain. Make the hack explicit (and optional for other arches) by turning it into a cmdline option and kernel config option.
--- arch/Kconfig | 4 +++ arch/x86/Kconfig | 1 + arch/x86/include/asm/jump_label.h | 6 ++-- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 4 +++ tools/objtool/builtin-check.c | 37 +++++++++++++++++++------ tools/objtool/check.c | 2 +- tools/objtool/include/objtool/builtin.h | 1 + 8 files changed, 44 insertions(+), 12 deletions(-)
arch/Kconfig +4 -0
@@ -46,6 +46,7 @@ config JUMP_LABEL bool "Optimize very unlikely/likely branches" depends on HAVE_ARCH_JUMP_LABEL depends on CC_HAS_ASM_GOTO + select OBJTOOL if HAVE_JUMP_LABEL_HACK help This option enables a transparent branch optimization that makes certain almost-always-true or almost-always-false branch
@@ -1031,6 +1032,9 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT config HAVE_OBJTOOL bool +config HAVE_JUMP_LABEL_HACK + bool + config HAVE_STACK_VALIDATION bool help
arch/x86/Kconfig +1 -0
@@ -212,6 +212,7 @@ config X86 select HAVE_IOREMAP_PROT select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64 select HAVE_IRQ_TIME_ACCOUNTING + select HAVE_JUMP_LABEL_HACK if HAVE_OBJTOOL select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZ4
arch/x86/include/asm/jump_label.h +3 -3
@@ -20,7 +20,7 @@ _ASM_PTR"%c0 + %c1 - .\n\t" \".popsection \n\t" -#ifdef CONFIG_OBJTOOL +#ifdef CONFIG_HAVE_JUMP_LABEL_HACK static __always_inline bool arch_static_branch(struct static_key *key, bool branch) {
@@ -34,7 +34,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool branreturn true; } -#else /* !CONFIG_OBJTOOL */ +#else /* !CONFIG_HAVE_JUMP_LABEL_HACK */ static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch) {
@@ -48,7 +48,7 @@ static __always_inline bool arch_static_branch(struct static_key * const key, coreturn true; } -#endif /* CONFIG_OBJTOOL */ +#endif /* CONFIG_HAVE_JUMP_LABEL_HACK */ static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch) {
scripts/Makefile.build +1 -0
@@ -227,6 +227,7 @@ ifdef CONFIG_OBJTOOL objtool := $(objtree)/tools/objtool/objtool objtool_args = \ + $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_UNWINDER_ORC), --orc) \
scripts/link-vmlinux.sh +4 -0
@@ -117,6 +117,10 @@ objtool_link() # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file. + if is_enabled CONFIG_HAVE_JUMP_LABEL_HACK; then + objtoolopt="${objtoolopt} --hacks=jump_label" + fi + if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt="${objtoolopt} --ibt" fi
tools/objtool/builtin-check.c +29 -8
@@ -31,8 +31,28 @@ static int parse_dump(const struct option *opt, const char *str, int unset)return -1 ; } +static int parse_hacks (const struct option *opt,const char *str,int unset) +{ +bool found = false; + +/* +* Use strstr() as a lazy method of checking for comma-separated +* options. +* +* No string provided == enable all options. +*/ + +if (!str ||strstr (str,"jump_label" )) { + opts.hack_jump_label = true; + found = true; + } + +return found ?0 :-1 ; +} +const struct option check_options[] = {OPT_GROUP ("Actions:" ), +OPT_CALLBACK_OPTARG ('h' ,"hacks" ,NULL ,NULL ,"jump_label" ,"patch toolchain bugs/limitations" , parse_hacks),OPT_BOOLEAN ('i' ,"ibt" , &opts.ibt,"validate and annotate IBT" ),OPT_BOOLEAN ('m' ,"mcount" , &opts.mcount,"annotate mcount/fentry calls for ftrace" ),OPT_BOOLEAN ('n' ,"noinstr" , &opts.noinstr,"validate noinstr rules" ),
@@ -87,14 +107,15 @@ int cmd_parse_options(int argc, const char **argv, const char * const usage[])static bool opts_valid (void ) { -if (opts.ibt || - opts.mcount || - opts.noinstr || - opts.orc || - opts.retpoline || - opts.sls || - opts.stackval || - opts.static_call || +if (opts.hack_jump_label || + opts.ibt || + opts.mcount || + opts.noinstr || + opts.orc || + opts.retpoline || + opts.sls || + opts.stackval || + opts.static_call || opts.uaccess) {if (opts.dump_orc) {fprintf (stderr,"--dump can't be combined with other options\n" );
tools/objtool/check.c +1 -1
@@ -1593,7 +1593,7 @@ static int handle_jump_alt(struct objtool_file *file,return -1 ; } -if (special_alt->key_addend &2 ) { +if (opts.hack_jump_label && special_alt->key_addend &2 ) {struct reloc *reloc =insn_reloc (file, orig_insn);if (reloc) {
tools/objtool/include/objtool/builtin.h +1 -0
@@ -12,6 +12,7 @@ extern const struct option check_options[];struct opts {/* actions: */ bool dump_orc; +bool hack_jump_label;bool ibt;bool mcount;bool noinstr;
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Make jump label hack optional
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 4ab7674f5951ac6a8ac4fa8828090edb64a4771f Gitweb: https://git.kernel.org/tip/4ab7674f5951ac6a8ac4fa8828090edb64a4771f Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:39 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:04 +02:00
objtool: Make jump label hack optional
Objtool secretly does a jump label hack to overcome the limitations of the toolchain. Make the hack explicit (and optional for other arches) by turning it into a cmdline option and kernel config option.
--- arch/Kconfig | 4 +++- arch/x86/Kconfig | 1 +- arch/x86/include/asm/jump_label.h | 6 ++-- scripts/Makefile.build | 1 +- scripts/link-vmlinux.sh | 4 +++- tools/objtool/builtin-check.c | 37 ++++++++++++++++++------ tools/objtool/check.c | 2 +- tools/objtool/include/objtool/builtin.h | 1 +- 8 files changed, 44 insertions(+), 12 deletions(-)
arch/Kconfig +4 -0
@@ -46,6 +46,7 @@ config JUMP_LABEL bool "Optimize very unlikely/likely branches" depends on HAVE_ARCH_JUMP_LABEL depends on CC_HAS_ASM_GOTO + select OBJTOOL if HAVE_JUMP_LABEL_HACK help This option enables a transparent branch optimization that makes certain almost-always-true or almost-always-false branch
@@ -1031,6 +1032,9 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT config HAVE_OBJTOOL bool +config HAVE_JUMP_LABEL_HACK + bool + config HAVE_STACK_VALIDATION bool help
arch/x86/Kconfig +1 -0
@@ -212,6 +212,7 @@ config X86 select HAVE_IOREMAP_PROT select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64 select HAVE_IRQ_TIME_ACCOUNTING + select HAVE_JUMP_LABEL_HACK if HAVE_OBJTOOL select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZ4
arch/x86/include/asm/jump_label.h +3 -3
@@ -20,7 +20,7 @@ _ASM_PTR"%c0 + %c1 - .\n\t" \".popsection \n\t" -#ifdef CONFIG_OBJTOOL +#ifdef CONFIG_HAVE_JUMP_LABEL_HACK static __always_inline bool arch_static_branch(struct static_key *key, bool branch) {
@@ -34,7 +34,7 @@ l_yes:return true; } -#else /* !CONFIG_OBJTOOL */ +#else /* !CONFIG_HAVE_JUMP_LABEL_HACK */ static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch) {
@@ -48,7 +48,7 @@ l_yes:return true; } -#endif /* CONFIG_OBJTOOL */ +#endif /* CONFIG_HAVE_JUMP_LABEL_HACK */ static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch) {
scripts/Makefile.build +1 -0
@@ -227,6 +227,7 @@ ifdef CONFIG_OBJTOOL objtool := $(objtree)/tools/objtool/objtool objtool_args = \ + $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_UNWINDER_ORC), --orc) \
scripts/link-vmlinux.sh +4 -0
@@ -117,6 +117,10 @@ objtool_link() # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file. + if is_enabled CONFIG_HAVE_JUMP_LABEL_HACK; then + objtoolopt="${objtoolopt} --hacks=jump_label" + fi + if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt="${objtoolopt} --ibt" fi
tools/objtool/builtin-check.c +29 -8
@@ -31,8 +31,28 @@ static int parse_dump(const struct option *opt, const char *str, int unset)return -1 ; } +static int parse_hacks (const struct option *opt,const char *str,int unset) +{ +bool found = false; + +/* +* Use strstr() as a lazy method of checking for comma-separated +* options. +* +* No string provided == enable all options. +*/ + +if (!str ||strstr (str,"jump_label" )) { + opts.hack_jump_label = true; + found = true; + } + +return found ?0 :-1 ; +} +const struct option check_options[] = {OPT_GROUP ("Actions:" ), +OPT_CALLBACK_OPTARG ('h' ,"hacks" ,NULL ,NULL ,"jump_label" ,"patch toolchain bugs/limitations" , parse_hacks),OPT_BOOLEAN ('i' ,"ibt" , &opts.ibt,"validate and annotate IBT" ),OPT_BOOLEAN ('m' ,"mcount" , &opts.mcount,"annotate mcount/fentry calls for ftrace" ),OPT_BOOLEAN ('n' ,"noinstr" , &opts.noinstr,"validate noinstr rules" ),
@@ -87,14 +107,15 @@ int cmd_parse_options(int argc, const char **argv, const char * const usage[])static bool opts_valid (void ) { -if (opts.ibt || - opts.mcount || - opts.noinstr || - opts.orc || - opts.retpoline || - opts.sls || - opts.stackval || - opts.static_call || +if (opts.hack_jump_label || + opts.ibt || + opts.mcount || + opts.noinstr || + opts.orc || + opts.retpoline || + opts.sls || + opts.stackval || + opts.static_call || opts.uaccess) {if (opts.dump_orc) {fprintf (stderr,"--dump can't be combined with other options\n" );
tools/objtool/check.c +1 -1
@@ -1592,7 +1592,7 @@ static int handle_jump_alt(struct objtool_file *file,return -1 ; } -if (special_alt->key_addend &2 ) { +if (opts.hack_jump_label && special_alt->key_addend &2 ) {struct reloc *reloc =insn_reloc (file, orig_insn);if (reloc) {
tools/objtool/include/objtool/builtin.h +1 -0
@@ -12,6 +12,7 @@ extern const struct option check_options[];struct opts {/* actions: */ bool dump_orc; +bool hack_jump_label;bool ibt;bool mcount;bool noinstr;
PATCH v2 21/25 objtool: Make noinstr hacks optional
In reply to Josh PoimboeufObjtool has some hacks in place to workaround toolchain limitations which otherwise would break no-instrumentation rules. Make the hacks explicit (and optional for other arches) by turning it into a cmdline option and kernel config option.
--- arch/Kconfig | 3 +++ arch/x86/Kconfig | 1 + lib/Kconfig.debug | 4 ++-- lib/Kconfig.kcsan | 5 +++-- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 4 ++++ tools/objtool/builtin-check.c | 8 +++++++- tools/objtool/check.c | 2 +- tools/objtool/include/objtool/builtin.h | 1 + 9 files changed, 23 insertions(+), 6 deletions(-)
arch/Kconfig +3 -0
@@ -1035,6 +1035,9 @@ config HAVE_OBJTOOL config HAVE_JUMP_LABEL_HACK bool +config HAVE_NOINSTR_HACK + bool + config HAVE_STACK_VALIDATION bool help
arch/x86/Kconfig +1 -0
@@ -231,6 +231,7 @@ config X86 select HAVE_MOD_ARCH_SPECIFIC select HAVE_MOVE_PMD select HAVE_MOVE_PUD + select HAVE_NOINSTR_HACK if HAVE_OBJTOOL select HAVE_NMI select HAVE_OBJTOOL if X86_64 select HAVE_OPTPROBES
lib/Kconfig.debug +2 -2
@@ -2036,11 +2036,11 @@ config KCOV bool "Code coverage for fuzzing" depends on ARCH_HAS_KCOV depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS - depends on !ARCH_WANTS_NO_INSTR || HAVE_OBJTOOL || \ + depends on !ARCH_WANTS_NO_INSTR || HAVE_NOINSTR_HACK || \ GCC_VERSION >= 120000 || CLANG_VERSION >= 130000 select DEBUG_FS select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC - select OBJTOOL if HAVE_OBJTOOL + select OBJTOOL if HAVE_NOINSTR_HACK help KCOV exposes kernel code coverage information in a form suitable for coverage-guided fuzzing (randomized testing).
lib/Kconfig.kcsan +3 -2
@@ -187,8 +187,9 @@ config KCSAN_WEAK_MEMORY # We can either let objtool nop __tsan_func_{entry,exit}() and builtin # atomics instrumentation in .noinstr.text, or use a compiler that can # implement __no_kcsan to really remove all instrumentation. - depends on HAVE_OBJTOOL || CC_IS_GCC || CLANG_VERSION >= 140000 - select OBJTOOL if HAVE_OBJTOOL + depends on !ARCH_WANTS_NO_INSTR || HAVE_NOINSTR_HACK || \ + CC_IS_GCC || CLANG_VERSION >= 140000 + select OBJTOOL if HAVE_NOINSTR_HACK help Enable support for modeling a subset of weak memory, which allows detecting a subset of data races due to missing memory barriers.
scripts/Makefile.build +1 -0
@@ -228,6 +228,7 @@ objtool := $(objtree)/tools/objtool/objtool objtool_args = \ $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \ + $(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_UNWINDER_ORC), --orc) \
scripts/link-vmlinux.sh +4 -0
@@ -121,6 +121,10 @@ objtool_link() objtoolopt="${objtoolopt} --hacks=jump_label" fi + if is_enabled CONFIG_HAVE_NOINSTR_HACK; then + objtoolopt="${objtoolopt} --hacks=noinstr" + fi + if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt="${objtoolopt} --ibt" fi
tools/objtool/builtin-check.c +7 -1
@@ -47,12 +47,17 @@ static int parse_hacks(const struct option *opt, const char *str, int unset) found = true; } +if (!str ||strstr (str,"noinstr" )) { + opts.hack_noinstr = true; + found = true; + } +return found ?0 :-1 ; }const struct option check_options[] = {OPT_GROUP ("Actions:" ), -OPT_CALLBACK_OPTARG ('h' ,"hacks" ,NULL ,NULL ,"jump_label" ,"patch toolchain bugs/limitations" , parse_hacks), +OPT_CALLBACK_OPTARG ('h' ,"hacks" ,NULL ,NULL ,"jump_label,noinstr" ,"patch toolchain bugs/limitations" , parse_hacks),OPT_BOOLEAN ('i' ,"ibt" , &opts.ibt,"validate and annotate IBT" ),OPT_BOOLEAN ('m' ,"mcount" , &opts.mcount,"annotate mcount/fentry calls for ftrace" ),OPT_BOOLEAN ('n' ,"noinstr" , &opts.noinstr,"validate noinstr rules" ),
@@ -108,6 +113,7 @@ int cmd_parse_options(int argc, const char **argv, const char * const usage[])static bool opts_valid (void ) { if (opts.hack_jump_label || + opts.hack_noinstr || opts.ibt || opts.mcount || opts.noinstr ||
tools/objtool/check.c +1 -1
@@ -1145,7 +1145,7 @@ static void annotate_call_site(struct objtool_file *file,* attribute so they need a little help, NOP out any such calls from * noinstr text. */ -if (insn->sec->noinstr && sym->profiling_func) { +if (opts.hack_noinstr && insn->sec->noinstr && sym->profiling_func) {if (reloc) { reloc->type =R_NONE ;elf_write_reloc (file->elf, reloc);
tools/objtool/include/objtool/builtin.h +1 -0
@@ -13,6 +13,7 @@ struct opts {/* actions: */ bool dump_orc;bool hack_jump_label; +bool hack_noinstr;bool ibt;bool mcount;bool noinstr;
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Make noinstr hacks optional
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 22102f4559beaabcea614b29ee090c6a214f002f Gitweb: https://git.kernel.org/tip/22102f4559beaabcea614b29ee090c6a214f002f Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:40 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:04 +02:00
objtool: Make noinstr hacks optional
Objtool has some hacks in place to workaround toolchain limitations which otherwise would break no-instrumentation rules. Make the hacks explicit (and optional for other arches) by turning it into a cmdline option and kernel config option.
--- arch/Kconfig | 3 +++ arch/x86/Kconfig | 1 + lib/Kconfig.debug | 4 ++-- lib/Kconfig.kcsan | 5 +++-- scripts/Makefile.build | 1 + scripts/link-vmlinux.sh | 4 ++++ tools/objtool/builtin-check.c | 8 +++++++- tools/objtool/check.c | 2 +- tools/objtool/include/objtool/builtin.h | 1 + 9 files changed, 23 insertions(+), 6 deletions(-)
arch/Kconfig +3 -0
@@ -1035,6 +1035,9 @@ config HAVE_OBJTOOL config HAVE_JUMP_LABEL_HACK bool +config HAVE_NOINSTR_HACK + bool + config HAVE_STACK_VALIDATION bool help
arch/x86/Kconfig +1 -0
@@ -231,6 +231,7 @@ config X86 select HAVE_MOD_ARCH_SPECIFIC select HAVE_MOVE_PMD select HAVE_MOVE_PUD + select HAVE_NOINSTR_HACK if HAVE_OBJTOOL select HAVE_NMI select HAVE_OBJTOOL if X86_64 select HAVE_OPTPROBES
lib/Kconfig.debug +2 -2
@@ -2036,11 +2036,11 @@ config KCOV bool "Code coverage for fuzzing" depends on ARCH_HAS_KCOV depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS - depends on !ARCH_WANTS_NO_INSTR || HAVE_OBJTOOL || \ + depends on !ARCH_WANTS_NO_INSTR || HAVE_NOINSTR_HACK || \ GCC_VERSION >= 120000 || CLANG_VERSION >= 130000 select DEBUG_FS select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC - select OBJTOOL if HAVE_OBJTOOL + select OBJTOOL if HAVE_NOINSTR_HACK help KCOV exposes kernel code coverage information in a form suitable for coverage-guided fuzzing (randomized testing).
lib/Kconfig.kcsan +3 -2
@@ -187,8 +187,9 @@ config KCSAN_WEAK_MEMORY # We can either let objtool nop __tsan_func_{entry,exit}() and builtin # atomics instrumentation in .noinstr.text, or use a compiler that can # implement __no_kcsan to really remove all instrumentation. - depends on HAVE_OBJTOOL || CC_IS_GCC || CLANG_VERSION >= 140000 - select OBJTOOL if HAVE_OBJTOOL + depends on !ARCH_WANTS_NO_INSTR || HAVE_NOINSTR_HACK || \ + CC_IS_GCC || CLANG_VERSION >= 140000 + select OBJTOOL if HAVE_NOINSTR_HACK help Enable support for modeling a subset of weak memory, which allows detecting a subset of data races due to missing memory barriers.
scripts/Makefile.build +1 -0
@@ -228,6 +228,7 @@ objtool := $(objtree)/tools/objtool/objtool objtool_args = \ $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \ + $(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \ $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_UNWINDER_ORC), --orc) \
scripts/link-vmlinux.sh +4 -0
@@ -121,6 +121,10 @@ objtool_link() objtoolopt="${objtoolopt} --hacks=jump_label" fi + if is_enabled CONFIG_HAVE_NOINSTR_HACK; then + objtoolopt="${objtoolopt} --hacks=noinstr" + fi + if is_enabled CONFIG_X86_KERNEL_IBT; then objtoolopt="${objtoolopt} --ibt" fi
tools/objtool/builtin-check.c +7 -1
@@ -47,12 +47,17 @@ static int parse_hacks(const struct option *opt, const char *str, int unset) found = true; } +if (!str ||strstr (str,"noinstr" )) { + opts.hack_noinstr = true; + found = true; + } +return found ?0 :-1 ; }const struct option check_options[] = {OPT_GROUP ("Actions:" ), -OPT_CALLBACK_OPTARG ('h' ,"hacks" ,NULL ,NULL ,"jump_label" ,"patch toolchain bugs/limitations" , parse_hacks), +OPT_CALLBACK_OPTARG ('h' ,"hacks" ,NULL ,NULL ,"jump_label,noinstr" ,"patch toolchain bugs/limitations" , parse_hacks),OPT_BOOLEAN ('i' ,"ibt" , &opts.ibt,"validate and annotate IBT" ),OPT_BOOLEAN ('m' ,"mcount" , &opts.mcount,"annotate mcount/fentry calls for ftrace" ),OPT_BOOLEAN ('n' ,"noinstr" , &opts.noinstr,"validate noinstr rules" ),
@@ -108,6 +113,7 @@ int cmd_parse_options(int argc, const char **argv, const char * const usage[])static bool opts_valid (void ) { if (opts.hack_jump_label || + opts.hack_noinstr || opts.ibt || opts.mcount || opts.noinstr ||
tools/objtool/check.c +1 -1
@@ -1144,7 +1144,7 @@ static void annotate_call_site(struct objtool_file *file,* attribute so they need a little help, NOP out any such calls from * noinstr text. */ -if (insn->sec->noinstr && sym->profiling_func) { +if (opts.hack_noinstr && insn->sec->noinstr && sym->profiling_func) {if (reloc) { reloc->type =R_NONE ;elf_write_reloc (file->elf, reloc);
tools/objtool/include/objtool/builtin.h +1 -0
@@ -13,6 +13,7 @@ struct opts {/* actions: */ bool dump_orc;bool hack_jump_label; +bool hack_noinstr;bool ibt;bool mcount;bool noinstr;
PATCH v2 22/25 objtool: Rename "VMLINUX_VALIDATION" -> "NOINSTR_VALIDATION"
In reply to Josh PoimboeufCONFIG_VMLINUX_VALIDATION is just the validation of the "noinstr" rules. That name is a misnomer, because now objtool actually does vmlinux validation for other reasons.
Rename CONFIG_VMLINUX_VALIDATION to CONFIG_NOINSTR_VALIDATION.
--- include/linux/instrumentation.h | 6 +++--- lib/Kconfig.debug | 2 +- scripts/link-vmlinux.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
include/linux/instrumentation.h +3 -3
@@ -2,7 +2,7 @@#ifndef __LINUX_INSTRUMENTATION_H#define __LINUX_INSTRUMENTATION_H -#ifdef CONFIG_VMLINUX_VALIDATION +#ifdef CONFIG_NOINSTR_VALIDATION #include <linux/stringify.h>
@@ -53,9 +53,9 @@ ".popsection\n\t" : : "i" (c)); \ })#define instrumentation_end () __instrumentation_end(__COUNTER__) -#else /* !CONFIG_VMLINUX_VALIDATION */ +#else /* !CONFIG_NOINSTR_VALIDATION */ # define instrumentation_begin () do { } while(0)# define instrumentation_end () do { } while(0) -#endif /* CONFIG_VMLINUX_VALIDATION */ +#endif /* CONFIG_NOINSTR_VALIDATION */ #endif /* __LINUX_INSTRUMENTATION_H */
lib/Kconfig.debug +1 -1
@@ -500,7 +500,7 @@ config STACK_VALIDATION For more information, see tools/objtool/Documentation/stack-validation.txt. -config VMLINUX_VALIDATION +config NOINSTR_VALIDATION bool depends on HAVE_OBJTOOL && DEBUG_ENTRY select OBJTOOL
scripts/link-vmlinux.sh +1 -1
@@ -160,7 +160,7 @@ objtool_link() objtoolopt="${objtoolopt} --lto" fi - if is_enabled CONFIG_VMLINUX_VALIDATION; then + if is_enabled CONFIG_NOINSTR_VALIDATION; then objtoolopt="${objtoolopt} --noinstr" fi
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Rename "VMLINUX_VALIDATION" -> "NOINSTR_VALIDATION"
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 0f620cefd7753175b6258fed85f76c2014ec3799 Gitweb: https://git.kernel.org/tip/0f620cefd7753175b6258fed85f76c2014ec3799 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:41 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:04 +02:00
objtool: Rename "VMLINUX_VALIDATION" -> "NOINSTR_VALIDATION"
CONFIG_VMLINUX_VALIDATION is just the validation of the "noinstr" rules. That name is a misnomer, because now objtool actually does vmlinux validation for other reasons.
Rename CONFIG_VMLINUX_VALIDATION to CONFIG_NOINSTR_VALIDATION.
--- include/linux/instrumentation.h | 6 +++--- lib/Kconfig.debug | 2 +- scripts/link-vmlinux.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
include/linux/instrumentation.h +3 -3
@@ -2,7 +2,7 @@#ifndef __LINUX_INSTRUMENTATION_H#define __LINUX_INSTRUMENTATION_H -#ifdef CONFIG_VMLINUX_VALIDATION +#ifdef CONFIG_NOINSTR_VALIDATION #include <linux/stringify.h>
@@ -53,9 +53,9 @@ ".popsection\n\t" : : "i" (c)); \ })#define instrumentation_end () __instrumentation_end(__COUNTER__) -#else /* !CONFIG_VMLINUX_VALIDATION */ +#else /* !CONFIG_NOINSTR_VALIDATION */ # define instrumentation_begin () do { } while(0)# define instrumentation_end () do { } while(0) -#endif /* CONFIG_VMLINUX_VALIDATION */ +#endif /* CONFIG_NOINSTR_VALIDATION */ #endif /* __LINUX_INSTRUMENTATION_H */
lib/Kconfig.debug +1 -1
@@ -500,7 +500,7 @@ config STACK_VALIDATION For more information, see tools/objtool/Documentation/stack-validation.txt. -config VMLINUX_VALIDATION +config NOINSTR_VALIDATION bool depends on HAVE_OBJTOOL && DEBUG_ENTRY select OBJTOOL
scripts/link-vmlinux.sh +1 -1
@@ -160,7 +160,7 @@ objtool_link() objtoolopt="${objtoolopt} --lto" fi - if is_enabled CONFIG_VMLINUX_VALIDATION; then + if is_enabled CONFIG_NOINSTR_VALIDATION; then objtoolopt="${objtoolopt} --noinstr" fi
PATCH v2 23/25 objtool: Add HAVE_NOINSTR_VALIDATION
In reply to Josh PoimboeufRemove CONFIG_NOINSTR_VALIDATION's dependency on HAVE_OBJTOOL, since other arches might want to implement objtool without it.
--- arch/Kconfig | 3 +++ arch/x86/Kconfig | 1 + lib/Kconfig.debug | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)
arch/Kconfig +3 -0
@@ -1038,6 +1038,9 @@ config HAVE_JUMP_LABEL_HACK config HAVE_NOINSTR_HACK bool +config HAVE_NOINSTR_VALIDATION + bool + config HAVE_STACK_VALIDATION bool help
arch/x86/Kconfig +1 -0
@@ -233,6 +233,7 @@ config X86 select HAVE_MOVE_PUD select HAVE_NOINSTR_HACK if HAVE_OBJTOOL select HAVE_NMI + select HAVE_NOINSTR_VALIDATION if HAVE_OBJTOOL select HAVE_OBJTOOL if X86_64 select HAVE_OPTPROBES select HAVE_PCSPKR_PLATFORM
lib/Kconfig.debug +1 -1
@@ -502,7 +502,7 @@ config STACK_VALIDATION config NOINSTR_VALIDATION bool - depends on HAVE_OBJTOOL && DEBUG_ENTRY + depends on HAVE_NOINSTR_VALIDATION && DEBUG_ENTRY select OBJTOOL default y
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Add HAVE_NOINSTR_VALIDATION
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 489e355b42255c5536a0ea3083a66b54a5e235c3 Gitweb: https://git.kernel.org/tip/489e355b42255c5536a0ea3083a66b54a5e235c3 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:42 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:05 +02:00
objtool: Add HAVE_NOINSTR_VALIDATION
Remove CONFIG_NOINSTR_VALIDATION's dependency on HAVE_OBJTOOL, since other arches might want to implement objtool without it.
--- arch/Kconfig | 3 +++ arch/x86/Kconfig | 1 + lib/Kconfig.debug | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)
arch/Kconfig +3 -0
@@ -1038,6 +1038,9 @@ config HAVE_JUMP_LABEL_HACK config HAVE_NOINSTR_HACK bool +config HAVE_NOINSTR_VALIDATION + bool + config HAVE_STACK_VALIDATION bool help
arch/x86/Kconfig +1 -0
@@ -233,6 +233,7 @@ config X86 select HAVE_MOVE_PUD select HAVE_NOINSTR_HACK if HAVE_OBJTOOL select HAVE_NMI + select HAVE_NOINSTR_VALIDATION if HAVE_OBJTOOL select HAVE_OBJTOOL if X86_64 select HAVE_OPTPROBES select HAVE_PCSPKR_PLATFORM
lib/Kconfig.debug +1 -1
@@ -502,7 +502,7 @@ config STACK_VALIDATION config NOINSTR_VALIDATION bool - depends on HAVE_OBJTOOL && DEBUG_ENTRY + depends on HAVE_NOINSTR_VALIDATION && DEBUG_ENTRY select OBJTOOL default y
PATCH v2 24/25 objtool: Remove --lto and --vmlinux in favor of --link
In reply to Josh PoimboeufThe '--lto' option is a confusing way of telling objtool to do stack validation despite it being a linked object. It's no longer needed now that an explicit '--stackval' option exists. The '--vmlinux' option is also redundant.
Remove both options in favor of a straightforward '--link' option which identifies a linked object.
Also, implicitly set '--link' with a warning if the user forgets to do so and we can tell that it's a linked object. This makes it easier for manual vmlinux runs.
--- scripts/Makefile.build | 4 ++- scripts/link-vmlinux.sh | 8 ++--- tools/objtool/builtin-check.c | 39 +++++++++++++++++++++--- tools/objtool/check.c | 40 +++++++++---------------- tools/objtool/elf.c | 3 ++ tools/objtool/include/objtool/builtin.h | 3 +- tools/objtool/include/objtool/elf.h | 12 +++++++- 7 files changed, 70 insertions(+), 39 deletions(-)
scripts/Makefile.build +3 -1
@@ -229,7 +229,7 @@ objtool := $(objtree)/tools/objtool/objtool objtool_args = \ $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \ $(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \ - $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ + $(if $(CONFIG_X86_KERNEL_IBT), --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_UNWINDER_ORC), --orc) \ $(if $(CONFIG_RETPOLINE), --retpoline) \
@@ -237,6 +237,7 @@ objtool_args = \ $(if $(CONFIG_STACK_VALIDATION), --stackval) \ $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ + $(if $(linked-object), --link) \ $(if $(part-of-module), --module) \ $(if $(CONFIG_GCOV_KERNEL), --no-unreachable)
@@ -306,6 +307,7 @@ quiet_cmd_cc_prelink_modules = LD [M] $@ # modules into native code $(obj)/%.prelink.o: objtool-enabled = y $(obj)/%.prelink.o: part-of-module := y +$(obj)/%.prelink.o: linked-object := y $(obj)/%.prelink.o: $(obj)/%.o FORCE $(call if_changed,cc_prelink_modules)
scripts/link-vmlinux.sh +3 -5
@@ -114,8 +114,8 @@ objtool_link() if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then - # Don't perform vmlinux validation unless explicitly requested, - # but run objtool on vmlinux.o now that we have an object file. + # For LTO and IBT, objtool doesn't run on individual + # translation units. Run everything on vmlinux instead. if is_enabled CONFIG_HAVE_JUMP_LABEL_HACK; then objtoolopt="${objtoolopt} --hacks=jump_label"
@@ -156,8 +156,6 @@ objtool_link() if is_enabled CONFIG_X86_SMAP; then objtoolopt="${objtoolopt} --uaccess" fi - - objtoolopt="${objtoolopt} --lto" fi if is_enabled CONFIG_NOINSTR_VALIDATION; then
@@ -170,7 +168,7 @@ objtool_link() objtoolopt="${objtoolopt} --no-unreachable" fi - objtoolopt="${objtoolopt} --vmlinux" + objtoolopt="${objtoolopt} --link" info OBJTOOL ${1} tools/objtool/objtool ${objtoolopt} ${1}
tools/objtool/builtin-check.c +35 -4
@@ -9,6 +9,11 @@#include <objtool/builtin.h> #include <objtool/objtool.h> +#define ERROR (format, ...) \ + fprintf(stderr, \ + "error: objtool: " format "\n", \ + ##__VA_ARGS__) +struct opts opts;static const char *const check_usage[] = {
@@ -73,12 +78,11 @@ const struct option check_options[] = {OPT_BOOLEAN (0 ,"backtrace" , &opts.backtrace,"unwind on error" ),OPT_BOOLEAN (0 ,"backup" , &opts.backup,"create .orig files before modification" ),OPT_BOOLEAN (0 ,"dry-run" , &opts.dryrun,"don't write modifications" ), -OPT_BOOLEAN (0 ,"lto" , &opts.lto,"whole-archive like runs" ), +OPT_BOOLEAN (0 ,"link" , &opts.link,"object is a linked object" ),OPT_BOOLEAN (0 ,"module" , &opts.module,"object is part of a kernel module" ),OPT_BOOLEAN (0 ,"no-unreachable" , &opts.no_unreachable,"skip 'unreachable instruction' warnings" ),OPT_BOOLEAN (0 ,"sec-address" , &opts.sec_address,"print section addresses in warnings" ),OPT_BOOLEAN (0 ,"stats" , &opts.stats,"print statistics" ), -OPT_BOOLEAN (0 ,"vmlinux" , &opts.vmlinux,"vmlinux.o validation" ), OPT_END(), };
@@ -124,7 +128,7 @@ static bool opts_valid(void) opts.static_call || opts.uaccess) {if (opts.dump_orc) { -fprintf (stderr,"--dump can't be combined with other options\n" ); +ERROR ("--dump can't be combined with other options" );return false; }
@@ -134,10 +138,34 @@ static bool opts_valid(void)if (opts.dump_orc)return true; -fprintf (stderr,"At least one command required\n" ); +ERROR ("At least one command required" );return false; } +static bool link_opts_valid (struct objtool_file *file) +{ +if (opts.link) +return true; + +if (has_multiple_files (file->elf)) { +ERROR ("Linked object detected, forcing --link" ); + opts.link = true; +return true; + } + +if (opts.noinstr) { +ERROR ("--noinstr requires --link" ); +return false; + } + +if (opts.ibt) { +ERROR ("--ibt requires --link" ); +return false; + } + +return true; +} +int objtool_run (int argc,const char **argv) {const char *objname;
@@ -157,6 +185,9 @@ int objtool_run(int argc, const char **argv)if (!file)return 1 ; +if (!link_opts_valid (file)) +return 1 ; + ret =check (file);if (ret)return ret;
tools/objtool/check.c +14 -26
@@ -264,7 +264,8 @@ static void init_cfi_state(struct cfi_state *cfi) cfi->drap_offset =-1 ; } -static void init_insn_state (struct insn_state *state,struct section *sec) +static void init_insn_state (struct objtool_file *file,struct insn_state *state, +struct section *sec) {memset (state,0 ,sizeof (*state));init_cfi_state (&state->cfi);
@@ -274,7 +275,7 @@ static void init_insn_state(struct insn_state *state, struct section *sec)* not correctly determine insn->call_dest->sec (external symbols do * not have a section). */ -if (opts.vmlinux && opts.noinstr && sec) +if (opts.link && opts.noinstr && sec) state->noinstr = sec->noinstr; }
@@ -3406,7 +3407,7 @@ static int validate_unwind_hints(struct objtool_file *file, struct section *sec)if (!file->hints)return 0 ; -init_insn_state (&state, sec); +init_insn_state (file, &state, sec);if (sec) { insn =find_insn (file, sec,0 );
@@ -3492,14 +3493,14 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructioreturn true;/* -* Whole archive runs might encounder dead code from weak symbols. +* Whole archive runs might encounter dead code from weak symbols. * This is where the linker will have dropped the weak symbol in * favour of a regular symbol, but leaves the code in place. * * In this case we'll find a piece of code (whole function) that is not * covered by a !section symbol. Ignore them. */ -if (!insn->func && opts.lto) { +if (opts.link && !insn->func) {int size =find_symbol_hole_containing (insn->sec, insn->offset);unsigned long end = insn->offset + size;
@@ -3621,7 +3622,7 @@ static int validate_section(struct objtool_file *file, struct section *sec)if (func->type !=STT_FUNC )continue ; -init_insn_state (&state, sec); +init_insn_state (file, &state, sec);set_func_state (&state.cfi); warnings +=validate_symbol (file, sec, func, &state);
@@ -3630,7 +3631,7 @@ static int validate_section(struct objtool_file *file, struct section *sec)return warnings; } -static int validate_vmlinux_functions (struct objtool_file *file) +static int validate_noinstr_sections (struct objtool_file *file) {struct section *sec;int warnings =0 ;
@@ -3891,16 +3892,6 @@ int check(struct objtool_file *file) {int ret, warnings =0 ; -if (opts.lto && !(opts.vmlinux || opts.module)) { -fprintf (stderr,"--lto requires: --vmlinux or --module\n" ); -return 1 ; - } - -if (opts.ibt && !opts.lto) { -fprintf (stderr,"--ibt requires: --lto\n" ); -return 1 ; - } -arch_initial_func_cfi_state (&initial_func_cfi);init_cfi_state (&init_cfi);init_cfi_state (&func_cfi);
@@ -3921,15 +3912,6 @@ int check(struct objtool_file *file)if (list_empty (&file->insn_list)) goto out; -if (opts.vmlinux && !opts.lto) { - ret =validate_vmlinux_functions (file); -if (ret <0 ) - goto out; - - warnings += ret; - goto out; - } -if (opts.retpoline) { ret =validate_retpoline (file);if (ret <0 )
@@ -3954,6 +3936,12 @@ int check(struct objtool_file *file) goto out; warnings += ret; } + + }else if (opts.noinstr) { + ret =validate_noinstr_sections (file); +if (ret <0 ) + goto out; + warnings += ret; }if (opts.ibt) {
tools/objtool/elf.c +3 -0
@@ -377,6 +377,9 @@ static void elf_add_symbol(struct elf *elf, struct symbol *sym) sym->type =GELF_ST_TYPE (sym->sym.st_info); sym->bind =GELF_ST_BIND (sym->sym.st_info); +if (sym->type ==STT_FILE ) + elf->num_files++; + sym->offset = sym->sym.st_value; sym->len = sym->sym.st_size;
tools/objtool/include/objtool/builtin.h +1 -2
@@ -28,12 +28,11 @@ struct opts {bool backtrace;bool backup;bool dryrun; -bool lto; +bool link;bool module;bool no_unreachable;bool sec_address;bool stats; -bool vmlinux; };extern struct opts opts;
tools/objtool/include/objtool/elf.h +11 -1
@@ -86,7 +86,7 @@ struct elf {int fd;bool changed;char *name; -unsigned int text_size; +unsigned int text_size, num_files;struct list_head sections;int symbol_bits;
@@ -131,6 +131,16 @@ static inline u32 reloc_hash(struct reloc *reloc)return sec_offset_hash (reloc->sec, reloc->offset); } +/* +* Try to see if it's a whole archive (vmlinux.o or module). +* +* Note this will miss the case where a module only has one source file. +*/ +static inline bool has_multiple_files (struct elf *elf) +{ +return elf->num_files >1 ; +} +struct elf *elf_open_read (const char *name,int flags);struct section *elf_create_section (struct elf *elf,const char *name,unsigned int sh_flags,size_t entsize,int nr);
Signature · 1 line
2.34.1
Re: [PATCH v2 24/25] objtool: Remove --lto and --vmlinux in favor of --link
tools/objtool/check.c static void init_cfi_state(struct cfi_state *cfi) · line 268
Quoted 3 lines
tools/objtool/check.c +2
-1-static void init_insn_state (struct insn_state *state,struct section *sec) +static void init_insn_state (struct objtool_file *file,struct insn_state *state, +struct section *sec)
file is not needed anymore here.
Miroslav
[tip: objtool/core] objtool: Remove --lto and --vmlinux in favor of --link
In reply to Josh PoimboeufThe following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 753da4179d08b625d8df72e97724e22749969fd3 Gitweb: https://git.kernel.org/tip/753da4179d08b625d8df72e97724e22749969fd3 Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:43 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:05 +02:00
objtool: Remove --lto and --vmlinux in favor of --link
The '--lto' option is a confusing way of telling objtool to do stack validation despite it being a linked object. It's no longer needed now that an explicit '--stackval' option exists. The '--vmlinux' option is also redundant.
Remove both options in favor of a straightforward '--link' option which identifies a linked object.
Also, implicitly set '--link' with a warning if the user forgets to do so and we can tell that it's a linked object. This makes it easier for manual vmlinux runs.
--- scripts/Makefile.build | 4 +- scripts/link-vmlinux.sh | 8 +---- tools/objtool/builtin-check.c | 39 ++++++++++++++++++++--- tools/objtool/check.c | 40 ++++++++---------------- tools/objtool/elf.c | 3 ++- tools/objtool/include/objtool/builtin.h | 3 +-- tools/objtool/include/objtool/elf.h | 12 ++++++- 7 files changed, 70 insertions(+), 39 deletions(-)
scripts/Makefile.build +3 -1
@@ -229,7 +229,7 @@ objtool := $(objtree)/tools/objtool/objtool objtool_args = \ $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \ $(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \ - $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ + $(if $(CONFIG_X86_KERNEL_IBT), --ibt) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ $(if $(CONFIG_UNWINDER_ORC), --orc) \ $(if $(CONFIG_RETPOLINE), --retpoline) \
@@ -237,6 +237,7 @@ objtool_args = \ $(if $(CONFIG_STACK_VALIDATION), --stackval) \ $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ + $(if $(linked-object), --link) \ $(if $(part-of-module), --module) \ $(if $(CONFIG_GCOV_KERNEL), --no-unreachable)
@@ -306,6 +307,7 @@ quiet_cmd_cc_prelink_modules = LD [M] $@ # modules into native code $(obj)/%.prelink.o: objtool-enabled = y $(obj)/%.prelink.o: part-of-module := y +$(obj)/%.prelink.o: linked-object := y $(obj)/%.prelink.o: $(obj)/%.o FORCE $(call if_changed,cc_prelink_modules)
scripts/link-vmlinux.sh +3 -5
@@ -114,8 +114,8 @@ objtool_link() if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then - # Don't perform vmlinux validation unless explicitly requested, - # but run objtool on vmlinux.o now that we have an object file. + # For LTO and IBT, objtool doesn't run on individual + # translation units. Run everything on vmlinux instead. if is_enabled CONFIG_HAVE_JUMP_LABEL_HACK; then objtoolopt="${objtoolopt} --hacks=jump_label"
@@ -156,8 +156,6 @@ objtool_link() if is_enabled CONFIG_X86_SMAP; then objtoolopt="${objtoolopt} --uaccess" fi - - objtoolopt="${objtoolopt} --lto" fi if is_enabled CONFIG_NOINSTR_VALIDATION; then
@@ -170,7 +168,7 @@ objtool_link() objtoolopt="${objtoolopt} --no-unreachable" fi - objtoolopt="${objtoolopt} --vmlinux" + objtoolopt="${objtoolopt} --link" info OBJTOOL ${1} tools/objtool/objtool ${objtoolopt} ${1}
tools/objtool/builtin-check.c +35 -4
@@ -9,6 +9,11 @@#include <objtool/builtin.h> #include <objtool/objtool.h> +#define ERROR (format, ...) \ + fprintf(stderr, \ + "error: objtool: " format "\n", \ + ##__VA_ARGS__) +struct opts opts;static const char *const check_usage[] = {
@@ -73,12 +78,11 @@ const struct option check_options[] = {OPT_BOOLEAN (0 ,"backtrace" , &opts.backtrace,"unwind on error" ),OPT_BOOLEAN (0 ,"backup" , &opts.backup,"create .orig files before modification" ),OPT_BOOLEAN (0 ,"dry-run" , &opts.dryrun,"don't write modifications" ), -OPT_BOOLEAN (0 ,"lto" , &opts.lto,"whole-archive like runs" ), +OPT_BOOLEAN (0 ,"link" , &opts.link,"object is a linked object" ),OPT_BOOLEAN (0 ,"module" , &opts.module,"object is part of a kernel module" ),OPT_BOOLEAN (0 ,"no-unreachable" , &opts.no_unreachable,"skip 'unreachable instruction' warnings" ),OPT_BOOLEAN (0 ,"sec-address" , &opts.sec_address,"print section addresses in warnings" ),OPT_BOOLEAN (0 ,"stats" , &opts.stats,"print statistics" ), -OPT_BOOLEAN (0 ,"vmlinux" , &opts.vmlinux,"vmlinux.o validation" ), OPT_END(), };
@@ -124,7 +128,7 @@ static bool opts_valid(void) opts.static_call || opts.uaccess) {if (opts.dump_orc) { -fprintf (stderr,"--dump can't be combined with other options\n" ); +ERROR ("--dump can't be combined with other options" );return false; }
@@ -134,10 +138,34 @@ static bool opts_valid(void)if (opts.dump_orc)return true; -fprintf (stderr,"At least one command required\n" ); +ERROR ("At least one command required" );return false; } +static bool link_opts_valid (struct objtool_file *file) +{ +if (opts.link) +return true; + +if (has_multiple_files (file->elf)) { +ERROR ("Linked object detected, forcing --link" ); + opts.link = true; +return true; + } + +if (opts.noinstr) { +ERROR ("--noinstr requires --link" ); +return false; + } + +if (opts.ibt) { +ERROR ("--ibt requires --link" ); +return false; + } + +return true; +} +int objtool_run (int argc,const char **argv) {const char *objname;
@@ -157,6 +185,9 @@ int objtool_run(int argc, const char **argv)if (!file)return 1 ; +if (!link_opts_valid (file)) +return 1 ; + ret =check (file);if (ret)return ret;
tools/objtool/check.c +14 -26
@@ -263,7 +263,8 @@ static void init_cfi_state(struct cfi_state *cfi) cfi->drap_offset =-1 ; } -static void init_insn_state (struct insn_state *state,struct section *sec) +static void init_insn_state (struct objtool_file *file,struct insn_state *state, +struct section *sec) {memset (state,0 ,sizeof (*state));init_cfi_state (&state->cfi);
@@ -273,7 +274,7 @@ static void init_insn_state(struct insn_state *state, struct section *sec)* not correctly determine insn->call_dest->sec (external symbols do * not have a section). */ -if (opts.vmlinux && opts.noinstr && sec) +if (opts.link && opts.noinstr && sec) state->noinstr = sec->noinstr; }
@@ -3405,7 +3406,7 @@ static int validate_unwind_hints(struct objtool_file *file, struct section *sec)if (!file->hints)return 0 ; -init_insn_state (&state, sec); +init_insn_state (file, &state, sec);if (sec) { insn =find_insn (file, sec,0 );
@@ -3491,14 +3492,14 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructioreturn true;/* -* Whole archive runs might encounder dead code from weak symbols. +* Whole archive runs might encounter dead code from weak symbols. * This is where the linker will have dropped the weak symbol in * favour of a regular symbol, but leaves the code in place. * * In this case we'll find a piece of code (whole function) that is not * covered by a !section symbol. Ignore them. */ -if (!insn->func && opts.lto) { +if (opts.link && !insn->func) {int size =find_symbol_hole_containing (insn->sec, insn->offset);unsigned long end = insn->offset + size;
@@ -3620,7 +3621,7 @@ static int validate_section(struct objtool_file *file, struct section *sec)if (func->type !=STT_FUNC )continue ; -init_insn_state (&state, sec); +init_insn_state (file, &state, sec);set_func_state (&state.cfi); warnings +=validate_symbol (file, sec, func, &state);
@@ -3629,7 +3630,7 @@ static int validate_section(struct objtool_file *file, struct section *sec)return warnings; } -static int validate_vmlinux_functions (struct objtool_file *file) +static int validate_noinstr_sections (struct objtool_file *file) {struct section *sec;int warnings =0 ;
@@ -3890,16 +3891,6 @@ int check(struct objtool_file *file) {int ret, warnings =0 ; -if (opts.lto && !(opts.vmlinux || opts.module)) { -fprintf (stderr,"--lto requires: --vmlinux or --module\n" ); -return 1 ; - } - -if (opts.ibt && !opts.lto) { -fprintf (stderr,"--ibt requires: --lto\n" ); -return 1 ; - } -arch_initial_func_cfi_state (&initial_func_cfi);init_cfi_state (&init_cfi);init_cfi_state (&func_cfi);
@@ -3920,15 +3911,6 @@ int check(struct objtool_file *file)if (list_empty (&file->insn_list)) goto out; -if (opts.vmlinux && !opts.lto) { - ret =validate_vmlinux_functions (file); -if (ret <0 ) - goto out; - - warnings += ret; - goto out; - } -if (opts.retpoline) { ret =validate_retpoline (file);if (ret <0 )
@@ -3953,6 +3935,12 @@ int check(struct objtool_file *file) goto out; warnings += ret; } + + }else if (opts.noinstr) { + ret =validate_noinstr_sections (file); +if (ret <0 ) + goto out; + warnings += ret; }if (opts.ibt) {
tools/objtool/elf.c +3 -0
@@ -377,6 +377,9 @@ static void elf_add_symbol(struct elf *elf, struct symbol *sym) sym->type =GELF_ST_TYPE (sym->sym.st_info); sym->bind =GELF_ST_BIND (sym->sym.st_info); +if (sym->type ==STT_FILE ) + elf->num_files++; + sym->offset = sym->sym.st_value; sym->len = sym->sym.st_size;
tools/objtool/include/objtool/builtin.h +1 -2
@@ -28,12 +28,11 @@ struct opts {bool backtrace;bool backup;bool dryrun; -bool lto; +bool link;bool module;bool no_unreachable;bool sec_address;bool stats; -bool vmlinux; };extern struct opts opts;
tools/objtool/include/objtool/elf.h +11 -1
@@ -86,7 +86,7 @@ struct elf {int fd;bool changed;char *name; -unsigned int text_size; +unsigned int text_size, num_files;struct list_head sections;int symbol_bits;
@@ -131,6 +131,16 @@ static inline u32 reloc_hash(struct reloc *reloc)return sec_offset_hash (reloc->sec, reloc->offset); } +/* +* Try to see if it's a whole archive (vmlinux.o or module). +* +* Note this will miss the case where a module only has one source file. +*/ +static inline bool has_multiple_files (struct elf *elf) +{ +return elf->num_files >1 ; +} +struct elf *elf_open_read (const char *name,int flags);struct section *elf_create_section (struct elf *elf,const char *name,unsigned int sh_flags,size_t entsize,int nr);
PATCH v2 25/25 objtool: Update documentation
In reply to Josh PoimboeufThe objtool documentation is very stack validation centric. Broaden the documentation and describe all the features objtool supports.
---
.../{stack-validation.txt => objtool.txt} | 122 +++++++++++++++---
1 file changed, 102 insertions(+), 20 deletions(-)
rename tools/objtool/Documentation/{stack-validation.txt => objtool.txt} (80%)tools/objtool/Documentation/objtool.txt renamed from tools/objtool/Documentation/stack-validation.txt +102 -20
@@ -1,15 +1,103 @@ -Compile-time stack metadata validation -====================================== +Objtool +======= +The kernel CONFIG_OBJTOOL option enables a host tool named 'objtool' +which runs at compile time. It can do various validations and +transformations on .o files. -Overview +Objtool has become an integral part of the x86-64 kernel toolchain. The +kernel depends on it for a variety of security and performance features +(and other types of features as well). + + +Features -------- -The kernel CONFIG_STACK_VALIDATION option enables a host tool named -objtool which runs at compile time. It has a "check" subcommand which -analyzes every .o file and ensures the validity of its stack metadata. -It enforces a set of rules on asm code and C inline assembly code so -that stack traces can be reliable. +Objtool has the following features: + +- Stack unwinding metadata validation -- useful for helping to ensure + stack traces are reliable for live patching + +- ORC unwinder metadata generation -- a faster and more precise + alternative to frame pointer based unwinding + +- Retpoline validation -- ensures that all indirect calls go through + retpoline thunks, for Spectre v2 mitigations + +- Retpoline call site annotation -- annotates all retpoline thunk call + sites, enabling the kernel to patch them inline, to prevent "thunk + funneling" for both security and performance reasons + +- Non-instrumentation validation -- validates non-instrumentable + ("noinstr") code rules, preventing instrumentation in low-level C + entry code + +- Static call annotation -- annotates static call sites, enabling the + kernel to implement inline static calls, a faster alternative to some + indirect branches + +- Uaccess validation -- validates uaccess rules for a proper + implementation of Supervisor Mode Access Protection (SMAP) + +- Straight Line Speculation validation -- validates certain SLS + mitigations + +- Indirect Branch Tracking validation -- validates Intel CET IBT rules + to ensure that all functions referenced by function pointers have + corresponding ENDBR instructions + +- Indirect Branch Tracking annotation -- annotates unused ENDBR + instruction sites, enabling the kernel to "seal" them (replace them + with NOPs) to further harden IBT + +- Function entry annotation -- annotates function entries, enabling + kernel function tracing + +- Other toolchain hacks which will go unmentioned at this time... + +Each feature can be enabled individually or in combination using the +objtool cmdline. + + +Objects +------- + +Typically, objtool runs on every translation unit (TU, aka ".o file") in +the kernel. If a TU is part of a kernel module, the '--module' option +is added. + +However: + +- If noinstr validation is enabled, it also runs on vmlinux.o, with all + options removed and '--noinstr' added. + +- If IBT or LTO is enabled, it doesn't run on TUs at all. Instead it + runs on vmlinux.o and linked modules, with all options. + +In summary: + + A) Legacy mode: + TU: objtool [--module] <options> + vmlinux: N/A + module: N/A + + B) CONFIG_NOINSTR_VALIDATION=y && !(CONFIG_X86_KERNEL_IBT=y || CONFIG_LTO=y): + TU: objtool [--module] <options> // no --noinstr + vmlinux: objtool --noinstr // other options removed + module: N/A + + C) CONFIG_X86_KERNEL_IBT=y || CONFIG_LTO=y: + TU: N/A + vmlinux: objtool --noinstr <options> + module: objtool --module --noinstr <options> + + +Stack validation +---------------- + +Objtool's stack validation feature analyzes every .o file and ensures +the validity of its stack metadata. It enforces a set of rules on asm +code and C inline assembly code so that stack traces can be reliable. For each function, it recursively follows all possible code paths and validates the correct frame pointer state at each instruction.
@@ -20,14 +108,6 @@ alternative execution paths to a given instruction (or set of instructions). Similarly, it knows how to follow switch statements, for which gcc sometimes uses jump tables. -(Objtool also has an 'orc generate' subcommand which generates debuginfo -for the ORC unwinder. See Documentation/x86/orc-unwinder.rst in the -kernel tree for more details.) - - -Why do we need stack metadata validation? ------------------------------------------ - Here are some of the benefits of validating stack metadata: a) More reliable stack traces for frame pointer enabled kernels
@@ -113,9 +193,6 @@ c) Higher live patching compatibility rate For more details, see the livepatch documentation in the Linux kernel source tree at Documentation/livepatch/livepatch.rst. -Rules ------ - To achieve the validation, objtool enforces the following rules: 1. Each callable function must be annotated as such with the ELF
@@ -177,7 +254,8 @@ Another possible cause for errors in C code is if the Makefile removes -fno-omit-frame-pointer or adds -fomit-frame-pointer to the gcc options. Here are some examples of common warnings reported by objtool, what -they mean, and suggestions for how to fix them. +they mean, and suggestions for how to fix them. When in doubt, ping +the objtool maintainers. 1. file.o: warning: objtool: func()+0x128: call without frame pointer save/setup
@@ -358,3 +436,7 @@ ignore it: OBJECT_FILES_NON_STANDARD := y to the Makefile. + +NOTE: OBJECT_FILES_NON_STANDARD doesn't work for link time validation of +vmlinux.o or a linked module. So it should only be used for files which +aren't linked into vmlinux or a module.
Signature · 1 line
2.34.1
[tip: objtool/core] objtool: Update documentation
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: a8e35fece49b16b20de000aab687ca075e4463af Gitweb: https://git.kernel.org/tip/a8e35fece49b16b20de000aab687ca075e4463af Author: Josh Poimboeuf <[email protected]> AuthorDate: Mon, 18 Apr 2022 09:50:44 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 22 Apr 2022 12:32:05 +02:00
objtool: Update documentation
The objtool documentation is very stack validation centric. Broaden the documentation and describe all the features objtool supports.
--- tools/objtool/Documentation/objtool.txt | 442 ++++++++++++++- tools/objtool/Documentation/stack-validation.txt | 360 +----------- 2 files changed, 442 insertions(+), 360 deletions(-) create mode 100644 tools/objtool/Documentation/objtool.txt delete mode 100644 tools/objtool/Documentation/stack-validation.txt
tools/objtool/Documentation/objtool.txt new file +442 -0
@@ -0,0 +1,442 @@ +Objtool +======= + +The kernel CONFIG_OBJTOOL option enables a host tool named 'objtool' +which runs at compile time. It can do various validations and +transformations on .o files. + +Objtool has become an integral part of the x86-64 kernel toolchain. The +kernel depends on it for a variety of security and performance features +(and other types of features as well). + + +Features +-------- + +Objtool has the following features: + +- Stack unwinding metadata validation -- useful for helping to ensure + stack traces are reliable for live patching + +- ORC unwinder metadata generation -- a faster and more precise + alternative to frame pointer based unwinding + +- Retpoline validation -- ensures that all indirect calls go through + retpoline thunks, for Spectre v2 mitigations + +- Retpoline call site annotation -- annotates all retpoline thunk call + sites, enabling the kernel to patch them inline, to prevent "thunk + funneling" for both security and performance reasons + +- Non-instrumentation validation -- validates non-instrumentable + ("noinstr") code rules, preventing instrumentation in low-level C + entry code + +- Static call annotation -- annotates static call sites, enabling the + kernel to implement inline static calls, a faster alternative to some + indirect branches + +- Uaccess validation -- validates uaccess rules for a proper + implementation of Supervisor Mode Access Protection (SMAP) + +- Straight Line Speculation validation -- validates certain SLS + mitigations + +- Indirect Branch Tracking validation -- validates Intel CET IBT rules + to ensure that all functions referenced by function pointers have + corresponding ENDBR instructions + +- Indirect Branch Tracking annotation -- annotates unused ENDBR + instruction sites, enabling the kernel to "seal" them (replace them + with NOPs) to further harden IBT + +- Function entry annotation -- annotates function entries, enabling + kernel function tracing + +- Other toolchain hacks which will go unmentioned at this time... + +Each feature can be enabled individually or in combination using the +objtool cmdline. + + +Objects +------- + +Typically, objtool runs on every translation unit (TU, aka ".o file") in +the kernel. If a TU is part of a kernel module, the '--module' option +is added. + +However: + +- If noinstr validation is enabled, it also runs on vmlinux.o, with all + options removed and '--noinstr' added. + +- If IBT or LTO is enabled, it doesn't run on TUs at all. Instead it + runs on vmlinux.o and linked modules, with all options. + +In summary: + + A) Legacy mode: + TU: objtool [--module] <options> + vmlinux: N/A + module: N/A + + B) CONFIG_NOINSTR_VALIDATION=y && !(CONFIG_X86_KERNEL_IBT=y || CONFIG_LTO=y): + TU: objtool [--module] <options> // no --noinstr + vmlinux: objtool --noinstr // other options removed + module: N/A + + C) CONFIG_X86_KERNEL_IBT=y || CONFIG_LTO=y: + TU: N/A + vmlinux: objtool --noinstr <options> + module: objtool --module --noinstr <options> + + +Stack validation +---------------- + +Objtool's stack validation feature analyzes every .o file and ensures +the validity of its stack metadata. It enforces a set of rules on asm +code and C inline assembly code so that stack traces can be reliable. + +For each function, it recursively follows all possible code paths and +validates the correct frame pointer state at each instruction. + +It also follows code paths involving special sections, like +.altinstructions, __jump_table, and __ex_table, which can add +alternative execution paths to a given instruction (or set of +instructions). Similarly, it knows how to follow switch statements, for +which gcc sometimes uses jump tables. + +Here are some of the benefits of validating stack metadata: + +a) More reliable stack traces for frame pointer enabled kernels + + Frame pointers are used for debugging purposes. They allow runtime + code and debug tools to be able to walk the stack to determine the + chain of function call sites that led to the currently executing + code. + + For some architectures, frame pointers are enabled by + CONFIG_FRAME_POINTER. For some other architectures they may be + required by the ABI (sometimes referred to as "backchain pointers"). + + For C code, gcc automatically generates instructions for setting up + frame pointers when the -fno-omit-frame-pointer option is used. + + But for asm code, the frame setup instructions have to be written by + hand, which most people don't do. So the end result is that + CONFIG_FRAME_POINTER is honored for C code but not for most asm code. + + For stack traces based on frame pointers to be reliable, all + functions which call other functions must first create a stack frame + and update the frame pointer. If a first function doesn't properly + create a stack frame before calling a second function, the *caller* + of the first function will be skipped on the stack trace. + + For example, consider the following example backtrace with frame + pointers enabled: + + [<ffffffff81812584>] dump_stack+0x4b/0x63 + [<ffffffff812d6dc2>] cmdline_proc_show+0x12/0x30 + [<ffffffff8127f568>] seq_read+0x108/0x3e0 + [<ffffffff812cce62>] proc_reg_read+0x42/0x70 + [<ffffffff81256197>] __vfs_read+0x37/0x100 + [<ffffffff81256b16>] vfs_read+0x86/0x130 + [<ffffffff81257898>] SyS_read+0x58/0xd0 + [<ffffffff8181c1f2>] entry_SYSCALL_64_fastpath+0x12/0x76 + + It correctly shows that the caller of cmdline_proc_show() is + seq_read(). + + If we remove the frame pointer logic from cmdline_proc_show() by + replacing the frame pointer related instructions with nops, here's + what it looks like instead: + + [<ffffffff81812584>] dump_stack+0x4b/0x63 + [<ffffffff812d6dc2>] cmdline_proc_show+0x12/0x30 + [<ffffffff812cce62>] proc_reg_read+0x42/0x70 + [<ffffffff81256197>] __vfs_read+0x37/0x100 + [<ffffffff81256b16>] vfs_read+0x86/0x130 + [<ffffffff81257898>] SyS_read+0x58/0xd0 + [<ffffffff8181c1f2>] entry_SYSCALL_64_fastpath+0x12/0x76 + + Notice that cmdline_proc_show()'s caller, seq_read(), has been + skipped. Instead the stack trace seems to show that + cmdline_proc_show() was called by proc_reg_read(). + + The benefit of objtool here is that because it ensures that *all* + functions honor CONFIG_FRAME_POINTER, no functions will ever[*] be + skipped on a stack trace. + + [*] unless an interrupt or exception has occurred at the very + beginning of a function before the stack frame has been created, + or at the very end of the function after the stack frame has been + destroyed. This is an inherent limitation of frame pointers. + +b) ORC (Oops Rewind Capability) unwind table generation + + An alternative to frame pointers and DWARF, ORC unwind data can be + used to walk the stack. Unlike frame pointers, ORC data is out of + band. So it doesn't affect runtime performance and it can be + reliable even when interrupts or exceptions are involved. + + For more details, see Documentation/x86/orc-unwinder.rst. + +c) Higher live patching compatibility rate + + Livepatch has an optional "consistency model", which is needed for + more complex patches. In order for the consistency model to work, + stack traces need to be reliable (or an unreliable condition needs to + be detectable). Objtool makes that possible. + + For more details, see the livepatch documentation in the Linux kernel + source tree at Documentation/livepatch/livepatch.rst. + +To achieve the validation, objtool enforces the following rules: + +1. Each callable function must be annotated as such with the ELF + function type. In asm code, this is typically done using the + ENTRY/ENDPROC macros. If objtool finds a return instruction + outside of a function, it flags an error since that usually indicates + callable code which should be annotated accordingly. + + This rule is needed so that objtool can properly identify each + callable function in order to analyze its stack metadata. + +2. Conversely, each section of code which is *not* callable should *not* + be annotated as an ELF function. The ENDPROC macro shouldn't be used + in this case. + + This rule is needed so that objtool can ignore non-callable code. + Such code doesn't have to follow any of the other rules. + +3. Each callable function which calls another function must have the + correct frame pointer logic, if required by CONFIG_FRAME_POINTER or + the architecture's back chain rules. This can by done in asm code + with the FRAME_BEGIN/FRAME_END macros. + + This rule ensures that frame pointer based stack traces will work as + designed. If function A doesn't create a stack frame before calling + function B, the _caller_ of function A will be skipped on the stack + trace. + +4. Dynamic jumps and jumps to undefined symbols are only allowed if: + + a) the jump is part of a switch statement; or + + b) the jump matches sibling call semantics and the frame pointer has + the same value it had on function entry. + + This rule is needed so that objtool can reliably analyze all of a + function's code paths. If a function jumps to code in another file, + and it's not a sibling call, objtool has no way to follow the jump + because it only analyzes a single file at a time. + +5. A callable function may not execute kernel entry/exit instructions. + The only code which needs such instructions is kernel entry code, + which shouldn't be be in callable functions anyway. + + This rule is just a sanity check to ensure that callable functions + return normally. + + +Objtool warnings +---------------- + +For asm files, if you're getting an error which doesn't make sense, +first make sure that the affected code follows the above rules. + +For C files, the common culprits are inline asm statements and calls to +"noreturn" functions. See below for more details. + +Another possible cause for errors in C code is if the Makefile removes +-fno-omit-frame-pointer or adds -fomit-frame-pointer to the gcc options. + +Here are some examples of common warnings reported by objtool, what +they mean, and suggestions for how to fix them. When in doubt, ping +the objtool maintainers. + + +1. file.o: warning: objtool: func()+0x128: call without frame pointer save/setup + + The func() function made a function call without first saving and/or + updating the frame pointer, and CONFIG_FRAME_POINTER is enabled. + + If the error is for an asm file, and func() is indeed a callable + function, add proper frame pointer logic using the FRAME_BEGIN and + FRAME_END macros. Otherwise, if it's not a callable function, remove + its ELF function annotation by changing ENDPROC to END, and instead + use the manual unwind hint macros in asm/unwind_hints.h. + + If it's a GCC-compiled .c file, the error may be because the function + uses an inline asm() statement which has a "call" instruction. An + asm() statement with a call instruction must declare the use of the + stack pointer in its output operand. On x86_64, this means adding + the ASM_CALL_CONSTRAINT as an output constraint: + + asm volatile("call func" : ASM_CALL_CONSTRAINT); + + Otherwise the stack frame may not get created before the call. + + +2. file.o: warning: objtool: .text+0x53: unreachable instruction + + Objtool couldn't find a code path to reach the instruction. + + If the error is for an asm file, and the instruction is inside (or + reachable from) a callable function, the function should be annotated + with the ENTRY/ENDPROC macros (ENDPROC is the important one). + Otherwise, the code should probably be annotated with the unwind hint + macros in asm/unwind_hints.h so objtool and the unwinder can know the + stack state associated with the code. + + If you're 100% sure the code won't affect stack traces, or if you're + a just a bad person, you can tell objtool to ignore it. See the + "Adding exceptions" section below. + + If it's not actually in a callable function (e.g. kernel entry code), + change ENDPROC to END. + + +4. file.o: warning: objtool: func(): can't find starting instruction + or + file.o: warning: objtool: func()+0x11dd: can't decode instruction + + Does the file have data in a text section? If so, that can confuse + objtool's instruction decoder. Move the data to a more appropriate + section like .data or .rodata. + + +5. file.o: warning: objtool: func()+0x6: unsupported instruction in callable function + + This is a kernel entry/exit instruction like sysenter or iret. Such + instructions aren't allowed in a callable function, and are most + likely part of the kernel entry code. They should usually not have + the callable function annotation (ENDPROC) and should always be + annotated with the unwind hint macros in asm/unwind_hints.h. + + +6. file.o: warning: objtool: func()+0x26: sibling call from callable instruction with modified stack frame + + This is a dynamic jump or a jump to an undefined symbol. Objtool + assumed it's a sibling call and detected that the frame pointer + wasn't first restored to its original state. + + If it's not really a sibling call, you may need to move the + destination code to the local file. + + If the instruction is not actually in a callable function (e.g. + kernel entry code), change ENDPROC to END and annotate manually with + the unwind hint macros in asm/unwind_hints.h. + + +7. file: warning: objtool: func()+0x5c: stack state mismatch + + The instruction's frame pointer state is inconsistent, depending on + which execution path was taken to reach the instruction. + + Make sure that, when CONFIG_FRAME_POINTER is enabled, the function + pushes and sets up the frame pointer (for x86_64, this means rbp) at + the beginning of the function and pops it at the end of the function. + Also make sure that no other code in the function touches the frame + pointer. + + Another possibility is that the code has some asm or inline asm which + does some unusual things to the stack or the frame pointer. In such + cases it's probably appropriate to use the unwind hint macros in + asm/unwind_hints.h. + + +8. file.o: warning: objtool: funcA() falls through to next function funcB() + + This means that funcA() doesn't end with a return instruction or an + unconditional jump, and that objtool has determined that the function + can fall through into the next function. There could be different + reasons for this: + + 1) funcA()'s last instruction is a call to a "noreturn" function like + panic(). In this case the noreturn function needs to be added to + objtool's hard-coded global_noreturns array. Feel free to bug the + objtool maintainer, or you can submit a patch. + + 2) funcA() uses the unreachable() annotation in a section of code + that is actually reachable. + + 3) If funcA() calls an inline function, the object code for funcA() + might be corrupt due to a gcc bug. For more details, see: + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646 + +9. file.o: warning: objtool: funcA() call to funcB() with UACCESS enabled + + This means that an unexpected call to a non-whitelisted function exists + outside of arch-specific guards. + X86: SMAP (stac/clac): __uaccess_begin()/__uaccess_end() + ARM: PAN: uaccess_enable()/uaccess_disable() + + These functions should be called to denote a minimal critical section around + access to __user variables. See also: https://lwn.net/Articles/517475/ + + The intention of the warning is to prevent calls to funcB() from eventually + calling schedule(), potentially leaking the AC flags state, and not + restoring them correctly. + + It also helps verify that there are no unexpected calls to funcB() which may + access user space pages with protections against doing so disabled. + + To fix, either: + 1) remove explicit calls to funcB() from funcA(). + 2) add the correct guards before and after calls to low level functions like + __get_user_size()/__put_user_size(). + 3) add funcB to uaccess_safe_builtin whitelist in tools/objtool/check.c, if + funcB obviously does not call schedule(), and is marked notrace (since + function tracing inserts additional calls, which is not obvious from the + sources). + +10. file.o: warning: func()+0x5c: stack layout conflict in alternatives + + This means that in the use of the alternative() or ALTERNATIVE() + macro, the code paths have conflicting modifications to the stack. + The problem is that there is only one ORC unwind table, which means + that the ORC unwind entries must be consistent for all possible + instruction boundaries regardless of which code has been patched. + This limitation can be overcome by massaging the alternatives with + NOPs to shift the stack changes around so they no longer conflict. + +11. file.o: warning: unannotated intra-function call + + This warning means that a direct call is done to a destination which + is not at the beginning of a function. If this is a legit call, you + can remove this warning by putting the ANNOTATE_INTRA_FUNCTION_CALL + directive right before the call. + + +If the error doesn't seem to make sense, it could be a bug in objtool. +Feel free to ask the objtool maintainer for help. + + +Adding exceptions +----------------- + +If you _really_ need objtool to ignore something, and are 100% sure +that it won't affect kernel stack traces, you can tell objtool to +ignore it: + +- To skip validation of a function, use the STACK_FRAME_NON_STANDARD + macro. + +- To skip validation of a file, add + + OBJECT_FILES_NON_STANDARD_filename.o := y + + to the Makefile. + +- To skip validation of a directory, add + + OBJECT_FILES_NON_STANDARD := y + + to the Makefile. + +NOTE: OBJECT_FILES_NON_STANDARD doesn't work for link time validation of +vmlinux.o or a linked module. So it should only be used for files which +aren't linked into vmlinux or a module.
tools/objtool/Documentation/stack-validation.txt deleted +0 -360
360 lines not on this page · raw message
Peter Zijlstra
maintainerQuoted 18 lines · Josh Poimboeuf
Josh Poimboeuf (25):
objtool: Enable unreachable warnings for CLANG LTO
libsubcmd: FixOPTION_GROUPsorting
x86/static_call: AddANNOTATE_NOENDBRto static call trampoline x86/retpoline: AddANNOTATE_ENDBRfor retpolines x86/uaccess: Add ENDBR to __put_user_nocheck*() x86/xen: AddANNOTATE_ENDBRtostartup_xen()
objtool: Reorganize cmdline options
objtool: Ditch subcommands
objtool: Don't print parentheses in function addresses
objtool: Print data address for "!ENDBR" data warnings
objtool: Useoffstr()to print address of missing ENDBR
objtool: Add option to print section addresses
scripts: Create objdump-func helper script
objtool: Make stack validation optional
objtool: Rework ibt and extricate from stack validation
objtool: Extricate sls from stack validation
objtool: AddCONFIG_OBJTOOL
Quoted 8 lines
objtool: Make stack validation frame-pointer-specific
objtool: Make static call annotation optional
objtool: Make jump label hack optional
objtool: Make noinstr hacks optional
objtool: Rename "VMLINUX_VALIDATION" -> "NOINSTR_VALIDATION"
objtool: AddHAVE_NOINSTR_VALIDATION
objtool: Remove --lto and --vmlinux in favor of --link
objtool: Update documentation
I've taken the liberty of reordering it slightly:
objtool: Enable unreachable warnings for CLANG LTO x86/static_call: Add ANNOTATE_NOENDBR to static call trampoline x86/retpoline: Add ANNOTATE_ENDBR for retpolines x86/uaccess: Add ENDBR to __put_user_nocheck*() x86/xen: Add ANNOTATE_ENDBR to startup_xen()
objtool: Print data address for "!ENDBR" data warnings
objtool: Use offstr() to print address of missing ENDBR
Go into x86/urgent, and I've added Fixes: tags with various patches from the IBT series, and then the rest goes into objtool/core.
As already indicated, there's going to be a few merge conflicts against x86/core, but alas. Resolved as per the below.
---
arch/x86/Kconfig +0 -0
scripts/Makefile.build +0 -0
@@@ -227,15 -227,19 +227,19 @@@ ifdef CONFIG_OBJTOO objtool := $(objtree)/tools/objtool/objtool objtool_args = \ - $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ - $(if $(part-of-module), --module) \ - $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ - $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ - $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\ + $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \ + $(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \ + $(if $(CONFIG_X86_KERNEL_IBT), --ibt) \ + $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ + $(if $(CONFIG_UNWINDER_ORC), --orc) \ $(if $(CONFIG_RETPOLINE), --retpoline) \ + $(if $(CONFIG_SLS), --sls) \ + $(if $(CONFIG_STACK_VALIDATION), --stackval) \ + $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \ - $(if $(CONFIG_X86_SMAP), --uaccess) \ + --uaccess \ - $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ - $(if $(CONFIG_SLS), --sls) + $(if $(linked-object), --link) \ + $(if $(part-of-module), --module) \ + $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
scripts/link-vmlinux.sh +0 -0
@@@ -126,34 -132,46 +132,44 @@@ objtool_link( if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then objtoolopt="${objtoolopt} --mcount" fi - fi - if is_enabled CONFIG_VMLINUX_VALIDATION; then - objtoolopt="${objtoolopt} --noinstr" - fi + if is_enabled CONFIG_UNWINDER_ORC; then + objtoolopt="${objtoolopt} --orc" + fi - if [ -n "${objtoolopt}" ]; then - if [ -z "${objtoolcmd}" ]; then - objtoolcmd="check" + if is_enabled CONFIG_RETPOLINE; then + objtoolopt="${objtoolopt} --retpoline" fi - objtoolopt="${objtoolopt} --vmlinux" - if ! is_enabled CONFIG_FRAME_POINTER; then - objtoolopt="${objtoolopt} --no-fp" + + if is_enabled CONFIG_SLS; then + objtoolopt="${objtoolopt} --sls" fi - if is_enabled CONFIG_GCOV_KERNEL || is_enabled CONFIG_LTO_CLANG; then - objtoolopt="${objtoolopt} --no-unreachable" + + if is_enabled CONFIG_STACK_VALIDATION; then + objtoolopt="${objtoolopt} --stackval" fi - if is_enabled CONFIG_RETPOLINE; then - objtoolopt="${objtoolopt} --retpoline" + + if is_enabled CONFIG_HAVE_STATIC_CALL_INLINE; then + objtoolopt="${objtoolopt} --static-call" fi - if is_enabled CONFIG_X86_SMAP; then - objtoolopt="${objtoolopt} --uaccess" - fi + objtoolopt="${objtoolopt} --uaccess" + fi - if is_enabled CONFIG_SLS; then - objtoolopt="${objtoolopt} --sls" + if is_enabled CONFIG_NOINSTR_VALIDATION; then + objtoolopt="${objtoolopt} --noinstr" + fi + + if [ -n "${objtoolopt}" ]; then + + if is_enabled CONFIG_GCOV_KERNEL; then + objtoolopt="${objtoolopt} --no-unreachable" fi + + objtoolopt="${objtoolopt} --link" + info OBJTOOL ${1} - tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1} + tools/objtool/objtool ${objtoolopt} ${1} fi }
Quoted 10 lines · Peter Zijlstra
I've taken the liberty of reordering it slightly:
objtool: Enable unreachable warnings for CLANG LTO x86/static_call: Add
ANNOTATE_NOENDBRto static call trampoline x86/retpoline: AddANNOTATE_ENDBRfor retpolines x86/uaccess: Add ENDBR to __put_user_nocheck*() x86/xen: AddANNOTATE_ENDBRtostartup_xen()
objtool: Print data address for "!ENDBR" data warnings
objtool: Useoffstr()to print address of missing ENDBR
Quoted 5 lines
Go into x86/urgent, and I've added Fixes: tags with various patches from the IBT series, and then the rest goes into objtool/core.
As already indicated, there's going to be a few merge conflicts against x86/core, but alas. Resolved as per the below.
Thanks! I guess tip bot is broken?
Quoted 2 lines
- $(if $(CONFIG_X86_SMAP), --uaccess) \
+ --uaccess \
Here we'll need HAVE_UACCESS_VALIDATION. I'll work up a new patch for that once your objtool/core changes go live (don't see them yet).
Signature · 1 line
Josh
Peter Zijlstra
maintainerQuoted 11 lines · Josh Poimboeuf
Quoted 10 lines · Peter Zijlstra
I've taken the liberty of reordering it slightly:
objtool: Enable unreachable warnings for CLANG LTO x86/static_call: Add
ANNOTATE_NOENDBRto static call trampoline x86/retpoline: AddANNOTATE_ENDBRfor retpolines x86/uaccess: Add ENDBR to __put_user_nocheck*() x86/xen: AddANNOTATE_ENDBRtostartup_xen()
objtool: Print data address for "!ENDBR" data warnings
objtool: Useoffstr()to print address of missing ENDBR
Quoted 7 lines
Quoted 5 lines
Go into x86/urgent, and I've added Fixes: tags with various patches from the IBT series, and then the rest goes into objtool/core.
As already indicated, there's going to be a few merge conflicts against x86/core, but alas. Resolved as per the below.
Thanks! I guess tip bot is broken?
Not pushed out yet, still in queue.git. Hopefully a little later today.
Quoted 19 lines
$ tools/objtool/objtool --helpUsage: objtool <actions> [<options>] file.o
Actions:
-h, --hacks[=<jump_label,noinstr>] patch toolchain bugs/limitations -i, --ibt validate and annotate IBT -l, --sls validate straight-line-speculation mitigations -m, --mcount annotate mcount/fentry calls for ftrace -n, --noinstr validate noinstr rules -o, --orc generate ORC metadata -r, --retpoline validate and annotate retpoline usage -s, --stackval validate frame pointer rules -t, --static-call annotate static calls -u, --uaccess validate uaccess rules for SMAP --dump[=<orc>] dump metadataOptions:
Quoted 8 lines
--backtrace unwind on error
--backup create .orig files before modification
--dry-run don't write modifications
--link object is a linked object
--module object is part of a kernel module
--no-unreachable skip 'unreachable instruction' warnings
--sec-address print section addresses in warnings
--stats print statisticsNice job! The outcome is much clearer now.
M