linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sami Tolvanen <samitolvanen@google.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: X86 ML <x86@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Sedat Dilek <sedat.dilek@gmail.com>,
	Kees Cook <keescook@chromium.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	clang-built-linux <clang-built-linux@googlegroups.com>,
	Miroslav Benes <mbenes@suse.cz>
Subject: Re: [PATCH 12/21] objtool: Add CONFIG_CFI_CLANG support
Date: Thu, 14 Jan 2021 12:49:28 -0800	[thread overview]
Message-ID: <CABCJKudFxiYbuHN+NVJ76QfHCky80nvsb_J08THmMmmHuy0vLA@mail.gmail.com> (raw)
In-Reply-To: <c1889131d5de558e58700ba559e7d8606fe9c680.1610652862.git.jpoimboe@redhat.com>

Hi Josh,

On Thu, Jan 14, 2021 at 11:41 AM Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>
> The upcoming CONFIG_CFI_CLANG support uses -fsanitize=cfi, the
> non-canonical version of which hijacks function entry by changing
> function relocation references to point to an intermediary jump table.
>
> For example:
>
>   Relocation section '.rela.discard.func_stack_frame_non_standard' at offset 0x37e018 contains 6 entries:
>       Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
>   0000000000000000  0002944700000002 R_X86_64_PC32          00000000000023f0 do_suspend_lowlevel + 0
>   0000000000000008  0003c11900000001 R_X86_64_64            0000000000000008 xen_cpuid$e69bc59f4fade3b6f2b579b3934137df.cfi_jt + 0
>   0000000000000010  0003980900000001 R_X86_64_64            0000000000000060 machine_real_restart.cfi_jt + 0
>   0000000000000018  0003962b00000001 R_X86_64_64            0000000000000e18 kretprobe_trampoline.cfi_jt + 0
>   0000000000000020  000028f300000001 R_X86_64_64            0000000000000000 .rodata + 12
>   0000000000000028  000349f400000001 R_X86_64_64            0000000000000018 __crash_kexec.cfi_jt + 0
>
>   0000000000000060 <machine_real_restart.cfi_jt>:
>     60: e9 00 00 00 00          jmpq   65 <machine_real_restart.cfi_jt+0x5>
>                         61: R_X86_64_PLT32      machine_real_restart-0x4
>     65: cc                      int3
>     66: cc                      int3
>     67: cc                      int3
>
> This breaks objtool vmlinux validation in many ways, including static
> call site detection and the STACK_FRAME_NON_STANDARD() macro.
>
> Fix it by converting those relocations' symbol references back to their
> original non-jump-table versions.  Note this doesn't change the actual
> relocations in the object itself, it just changes objtool's view of
> them.
>
> Reported-by: Sedat Dilek <sedat.dilek@gmail.com>
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
>  tools/objtool/elf.c | 28 ++++++++++++++++++++++++++++
>  tools/objtool/elf.h |  2 +-
>  2 files changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> index 292f015f7ec6..e357dc34cd7a 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -382,6 +382,11 @@ static int read_sections(struct elf *elf)
>                 }
>                 sec->len = sec->sh.sh_size;
>
> +               /* Detect -fsanitize=cfi related sections */
> +               if (!strcmp(sec->name, ".text.__cfi_check") ||
> +                   !strncmp(sec->name, ".text..L.cfi.jumptable", 22))
> +                       sec->cfi_jt = true;
> +
>                 list_add_tail(&sec->list, &elf->sections);
>                 elf_hash_add(elf->section_hash, &sec->hash, sec->idx);
>                 elf_hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name));
> @@ -614,6 +619,29 @@ static int read_relocs(struct elf *elf)
>                                 return -1;
>                         }
>
> +                       /*
> +                        * Deal with -fsanitize=cfi (CONFIG_CFI_CLANG), which
> +                        * hijacks function entry by arbitrarily changing a lot
> +                        * of relocation symbol references to refer to an
> +                        * intermediate jump table.  Undo that conversion so
> +                        * objtool can make sense of things.
> +                        */
> +                       if (reloc->sym->sec->cfi_jt) {
> +                               struct symbol *func, *sym;
> +
> +                               if (sym->type == STT_SECTION)
> +                                       sym = find_func_by_offset(sym->sec,
> +                                                                 reloc->addend);

Clang points out that sym is uninitialized here. Should these be
reloc->sym instead?

Sami

  reply	other threads:[~2021-01-14 20:50 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-14 19:39 [PATCH 00/21] objtool: vmlinux.o and CLANG LTO support Josh Poimboeuf
2021-01-14 19:39 ` [PATCH 01/21] objtool: Fix seg fault in BT_FUNC() with fake jump Josh Poimboeuf
2021-01-14 20:04   ` Josh Poimboeuf
2021-01-14 19:39 ` [PATCH 02/21] objtool: Fix error handling for STD/CLD warnings Josh Poimboeuf
2021-01-14 19:39 ` [PATCH 03/21] objtool: Fix retpoline detection in asm code Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 04/21] objtool: Fix ".cold" section suffix check for newer versions of GCC Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 05/21] objtool: Support retpoline jump detection for vmlinux.o Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 06/21] x86/ftrace: Add UNWIND_HINT_FUNC annotation for ftrace_stub Josh Poimboeuf
2021-01-14 20:42   ` Steven Rostedt
2021-01-14 19:40 ` [PATCH 07/21] objtool: Assume only ELF functions do sibling calls Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 08/21] objtool: Add asm version of STACK_FRAME_NON_STANDARD Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 09/21] objtool: Combine UNWIND_HINT_RET_OFFSET and UNWIND_HINT_FUNC Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 10/21] objtool: Add xen_start_kernel() to noreturn list Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 11/21] objtool: Move unsuffixed symbol conversion to a helper function Josh Poimboeuf
2021-01-14 20:55   ` [PATCH v1.1 " Josh Poimboeuf
2021-01-14 21:30     ` Sedat Dilek
2021-01-14 19:40 ` [PATCH 12/21] objtool: Add CONFIG_CFI_CLANG support Josh Poimboeuf
2021-01-14 20:49   ` Sami Tolvanen [this message]
2021-01-14 20:52     ` Josh Poimboeuf
2021-01-14 20:56   ` [PATCH v1.1 " Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 13/21] x86/xen: Support objtool validation in xen-asm.S Josh Poimboeuf
2021-01-15  0:31   ` boris.ostrovsky
2021-01-14 19:40 ` [PATCH 14/21] x86/xen: Support objtool vmlinux.o validation in xen-head.S Josh Poimboeuf
2021-01-15  0:32   ` boris.ostrovsky
2021-01-15  5:17   ` Jürgen Groß
2021-01-15 19:46     ` Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 15/21] x86/xen/pvh: Convert indirect jump to retpoline Josh Poimboeuf
2021-01-15  0:33   ` boris.ostrovsky
2021-01-15  5:24   ` Jürgen Groß
2021-01-15 15:08     ` Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 16/21] x86/ftrace: Support objtool vmlinux.o validation in ftrace_64.S Josh Poimboeuf
2021-01-14 20:42   ` Steven Rostedt
2021-01-14 19:40 ` [PATCH 17/21] x86/acpi: Convert indirect jump to retpoline Josh Poimboeuf
2021-01-14 22:59   ` Andrew Cooper
2021-01-14 23:47     ` Josh Poimboeuf
2021-01-15  0:54       ` Andrew Cooper
2021-01-14 19:40 ` [PATCH 18/21] x86/acpi: Support objtool validation in wakeup_64.S Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 19/21] x86/power: Convert indirect jumps to retpolines Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 20/21] x86/power: Move restore_registers() to top of the file Josh Poimboeuf
2021-01-14 19:40 ` [PATCH 21/21] x86/power: Support objtool validation in hibernate_asm_64.S Josh Poimboeuf
2021-01-15  0:41 ` [PATCH 00/21] objtool: vmlinux.o and CLANG LTO support Sami Tolvanen
2021-01-15  0:49   ` Nick Desaulniers
2021-01-15 19:52   ` Josh Poimboeuf
2021-01-15 20:19     ` Sedat Dilek
2021-01-15 20:59       ` Josh Poimboeuf
2021-01-15 21:01         ` Sedat Dilek
2021-01-18 17:22   ` Josh Poimboeuf
2021-01-19 21:29     ` Nick Desaulniers
2021-01-20 15:37       ` Josh Poimboeuf
2021-01-15  4:51 ` Sedat Dilek
2021-01-15  5:18   ` Sedat Dilek
2021-01-15 15:30   ` Sedat Dilek
2021-01-15 18:54     ` Sedat Dilek
2021-01-15 19:28       ` Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABCJKudFxiYbuHN+NVJ76QfHCky80nvsb_J08THmMmmHuy0vLA@mail.gmail.com \
    --to=samitolvanen@google.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=sedat.dilek@gmail.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).