Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

objtool: unreachable instruction #1148

Closed
nickdesaulniers opened this issue Sep 9, 2020 · 11 comments
Closed

objtool: unreachable instruction #1148

nickdesaulniers opened this issue Sep 9, 2020 · 11 comments
Assignees
Labels
[ARCH] x86_64 This bug impacts ARCH=x86_64 [BUG] linux A bug that should be fixed in the mainline kernel. [FIXED][LINUX] 5.10 This bug was fixed in Linux 5.10 [Reported-by] kbuild test robot Reported-by: kbuild test robot <lkp@intel.com> [TOOL] objtool warning is produced by the kernel's objtool

Comments

@nickdesaulniers
Copy link
Member

It looks like since Jul 30, I've seen a few reports from 0day bot about unreachable instructions. They looks randconfig based.

A bunch of reports aug 31, two on aug 6, two on Jul 30.

@nickdesaulniers nickdesaulniers added [BUG] Untriaged Something isn't working [ARCH] x86_64 This bug impacts ARCH=x86_64 [TOOL] objtool warning is produced by the kernel's objtool [Reported-by] kbuild test robot Reported-by: kbuild test robot <lkp@intel.com> labels Sep 9, 2020
@ihalip
Copy link

ihalip commented Sep 10, 2020

@ihalip ihalip added [PATCH] Submitted A patch has been submitted for review and removed [BUG] Untriaged Something isn't working labels Sep 11, 2020
@nickdesaulniers
Copy link
Member Author

@ihalip your previous version of your comment hinting at UBSAN was correct. Specifically, it seems this may be related to:
CONFIG_UBSAN_TRAP.

@nickdesaulniers nickdesaulniers removed the [PATCH] Submitted A patch has been submitted for review label Sep 15, 2020
@ihalip
Copy link

ihalip commented Sep 16, 2020

W.r.t. the arch/x86/kernel/sev-es.o: warning: objtool: ist_exc_vmm_communication()+0x12: unreachable instruction case that's been talked about on the mailing list, this is what happens in short:

call panic
ud2

, where panic() is marked as noreturn. This could easily be fixed in objtool, since it already has a way to check if a function is a "dead end".

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index e034a8f24f46..9224e6565ba2 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2612,9 +2612,10 @@ static bool is_ubsan_insn(struct instruction *insn)
                        "__ubsan_handle_builtin_unreachable"));
 }
 
-static bool ignore_unreachable_insn(struct instruction *insn)
+static bool ignore_unreachable_insn(struct objtool_file *file, struct instruction *insn)
 {
        int i;
+       struct instruction *prev_insn;
 
        if (insn->ignore || insn->type == INSN_NOP)
                return true;
@@ -2640,7 +2641,8 @@ static bool ignore_unreachable_insn(struct instruction *insn)
         * the UD2, which causes GCC's undefined trap logic to emit another UD2
         * (or occasionally a JMP to UD2).
         */
-       if (list_prev_entry(insn, list)->dead_end &&
+       prev_insn = list_prev_entry(insn, list);
+       if ((prev_insn->dead_end || dead_end_function(file, prev_insn->call_dest)) &&
            (insn->type == INSN_BUG ||
             (insn->type == INSN_JUMP_UNCONDITIONAL &&
              insn->jump_dest && insn->jump_dest->type == INSN_BUG)))
@@ -2767,7 +2769,7 @@ static int validate_reachable_instructions(struct objtool_file *file)
                return 0;
 
        for_each_insn(file, insn) {
-               if (insn->visited || ignore_unreachable_insn(insn))
+               if (insn->visited || ignore_unreachable_insn(file, insn))
                        continue;
 
                WARN_FUNC("unreachable instruction", insn->sec, insn->offset);

ihalip added a commit to ihalip/linux that referenced this issue Sep 17, 2020
With CONFIG_UBSAN_TRAP enabled, the compiler may insert a trap instruction
after a call to a noreturn function. In this case, objtool warns that the
ud2 instruction is unreachable.

objtool silences similar warnings (trap after dead end instructions), so
expand that check to include dead end functions.

Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Rong Chen <rong.a.chen@intel.com>
Cc: Marco Elver <elver@google.com>
Cc: Philip Li <philip.li@intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: kasan-dev@googlegroups.com
Cc: x86@kernel.org
Cc: clang-built-linux@googlegroups.com
BugLink: ClangBuiltLinux#1148
Link: https://lore.kernel.org/lkml/CAKwvOdmptEpi8fiOyWUo=AiZJiX+Z+VHJOM2buLPrWsMTwLnyw@mail.gmail.com
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Ilie Halip <ilie.halip@gmail.com>
@ihalip
Copy link

ihalip commented Sep 17, 2020

I sent this patch with an updated comment.

@ihalip ihalip added the [PATCH] Submitted A patch has been submitted for review label Sep 17, 2020
@dileks
Copy link
Collaborator

dileks commented Sep 17, 2020

@ihalip

Shouldn't objtool maintainers be CCed?
Did you run ./scripts/get_maintainer.pl $patch?

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/MAINTAINERS#n12503

@ihalip
Copy link

ihalip commented Sep 17, 2020

I didn't add them in the commit message, but they are CCd on the actual e-mail.

@nickdesaulniers
Copy link
Member Author

fengguang pushed a commit to 0day-ci/linux that referenced this issue Sep 17, 2020
With CONFIG_UBSAN_TRAP enabled, the compiler may insert a trap instruction
after a call to a noreturn function. In this case, objtool warns that the
ud2 instruction is unreachable.

objtool silences similar warnings (trap after dead end instructions), so
expand that check to include dead end functions.

Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Rong Chen <rong.a.chen@intel.com>
Cc: Marco Elver <elver@google.com>
Cc: Philip Li <philip.li@intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: kasan-dev@googlegroups.com
Cc: x86@kernel.org
Cc: clang-built-linux@googlegroups.com
BugLink: ClangBuiltLinux#1148
Link: https://lore.kernel.org/lkml/CAKwvOdmptEpi8fiOyWUo=AiZJiX+Z+VHJOM2buLPrWsMTwLnyw@mail.gmail.com
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Ilie Halip <ilie.halip@gmail.com>
@dileks
Copy link
Collaborator

dileks commented Sep 18, 2020

@ihalip

Always good to point to the message-id of <lore.k.o> or give patchwork LKML link.

[1] https://lore.kernel.org/patchwork/patch/1307224/

@dileks
Copy link
Collaborator

dileks commented Sep 18, 2020

Cool, first time using b4:

root# apt-get update && apt-get install -t testing b4

dileks$ git checkout tags/v5.9-rc5 -b for-5.9/objtool-unreachable-trap-ihalip

dileks$ b4 am https://lore.kernel.org/lkml/20200917084905.1647262-1-ilie.halip@gmail.com/ -o - | git am

[1] https://github.com/ClangBuiltLinux/linux/wiki/Command-line-tips-and-tricks > "For fetching a patch series from the mailing list"

ihalip added a commit to ihalip/linux that referenced this issue Sep 19, 2020
With CONFIG_UBSAN_TRAP enabled, the compiler may insert a trap instruction
after a call to a noreturn function. In this case, objtool warns that the
ud2 instruction is unreachable.

This is a behavior seen with clang, from the oldest version capable of
building the mainline x64_64 kernel (9.0), to the latest experimental
version (12).

objtool silences similar warnings (trap after dead end instructions), so
so expand that check to include dead end functions. This gets rid of 82
warnings in an x86_64 defconfig+UBSAN+UBSTAN_TRAP build.

Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Rong Chen <rong.a.chen@intel.com>
Cc: Marco Elver <elver@google.com>
Cc: Philip Li <philip.li@intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: kasan-dev@googlegroups.com
Cc: x86@kernel.org
Cc: clang-built-linux@googlegroups.com
BugLink: ClangBuiltLinux#1148
Link: https://lore.kernel.org/lkml/CAKwvOdmptEpi8fiOyWUo=AiZJiX+Z+VHJOM2buLPrWsMTwLnyw@mail.gmail.com
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Ilie Halip <ilie.halip@gmail.com>
@ihalip ihalip added [PATCH] Accepted A submitted patch has been accepted upstream and removed [PATCH] Submitted A patch has been submitted for review labels Sep 21, 2020
fengguang pushed a commit to 0day-ci/linux that referenced this issue Sep 24, 2020
With CONFIG_UBSAN_TRAP enabled, the compiler may insert a trap
instruction after a call to a noreturn function. In this case, objtool
warns that the UD2 instruction is unreachable.

This is a behavior seen with Clang, from the oldest version capable of
building the mainline x64_64 kernel (9.0), to the latest experimental
version (12.0).

Objtool silences similar warnings (trap after dead end instructions), so
so expand that check to include dead end functions.

Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Rong Chen <rong.a.chen@intel.com>
Cc: Marco Elver <elver@google.com>
Cc: Philip Li <philip.li@intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: kasan-dev@googlegroups.com
Cc: x86@kernel.org
Cc: clang-built-linux@googlegroups.com
BugLink: ClangBuiltLinux#1148
Link: https://lore.kernel.org/lkml/CAKwvOdmptEpi8fiOyWUo=AiZJiX+Z+VHJOM2buLPrWsMTwLnyw@mail.gmail.com
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Ilie Halip <ilie.halip@gmail.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
@ihalip ihalip closed this as completed Oct 15, 2020
@nickdesaulniers nickdesaulniers added [BUG] linux A bug that should be fixed in the mainline kernel. and removed [PATCH] Accepted A submitted patch has been accepted upstream labels Oct 15, 2020
@nickdesaulniers nickdesaulniers added the [FIXED][LINUX] 5.10 This bug was fixed in Linux 5.10 label Oct 15, 2020
raphielscape pushed a commit to raphielscape/linux-scape-workstation that referenced this issue Oct 25, 2020
With CONFIG_UBSAN_TRAP enabled, the compiler may insert a trap
instruction after a call to a noreturn function. In this case, objtool
warns that the UD2 instruction is unreachable.

This is a behavior seen with Clang, from the oldest version capable of
building the mainline x64_64 kernel (9.0), to the latest experimental
version (12.0).

Objtool silences similar warnings (trap after dead end instructions), so
so expand that check to include dead end functions.

Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Rong Chen <rong.a.chen@intel.com>
Cc: Marco Elver <elver@google.com>
Cc: Philip Li <philip.li@intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: kasan-dev@googlegroups.com
Cc: x86@kernel.org
Cc: clang-built-linux@googlegroups.com
BugLink: ClangBuiltLinux/linux#1148
Link: https://lore.kernel.org/lkml/CAKwvOdmptEpi8fiOyWUo=AiZJiX+Z+VHJOM2buLPrWsMTwLnyw@mail.gmail.com
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Ilie Halip <ilie.halip@gmail.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Rapherion Rollerscaperers <rapherion@raphielgang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[ARCH] x86_64 This bug impacts ARCH=x86_64 [BUG] linux A bug that should be fixed in the mainline kernel. [FIXED][LINUX] 5.10 This bug was fixed in Linux 5.10 [Reported-by] kbuild test robot Reported-by: kbuild test robot <lkp@intel.com> [TOOL] objtool warning is produced by the kernel's objtool
Projects
None yet
Development

No branches or pull requests

3 participants