lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKwvOd=ZJReVqgY_QbyKiX2MoL1neSrhoCxYN--56yFVUkuy2w@mail.gmail.com>
Date:   Tue, 18 Feb 2020 10:13:54 -0800
From:   Nick Desaulniers <ndesaulniers@...gle.com>
To:     Josh Poimboeuf <jpoimboe@...hat.com>
Cc:     "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <x86@...nel.org>,
        LKML <linux-kernel@...r.kernel.org>,
        Peter Zijlstra <peterz@...radead.org>
Subject: Re: [PATCH 2/2] objtool: Improve call destination function detection

On Mon, Feb 17, 2020 at 7:42 PM Josh Poimboeuf <jpoimboe@...hat.com> wrote:
>
> A recent clang change, combined with a binutils bug, can trigger a
> situation where a ".Lprintk$local" STT_NOTYPE symbol gets created at the
> same offset as the "printk" STT_FUNC symbol.  This confuses objtool:
>
>   kernel/printk/printk.o: warning: objtool: ignore_loglevel_setup()+0x10: can't find call dest symbol at .text+0xc67
>
> Improve the call destination detection by looking specifically for an
> STT_FUNC symbol.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/872
> Link: https://sourceware.org/bugzilla/show_bug.cgi?id=25551
> Reported-by: Nick Desaulniers <ndesaulniers@...gle.com>
> Signed-off-by: Josh Poimboeuf <jpoimboe@...hat.com>

Thanks Josh.
Tested-by: Nick Desaulniers <ndesaulniers@...gle.com>
Tested defconfig and allyesconfig builds with the series.

> ---
>  tools/objtool/check.c | 27 ++++++++++++++++++---------
>  tools/objtool/elf.c   | 14 ++++++++++++--
>  tools/objtool/elf.h   |  1 +
>  3 files changed, 31 insertions(+), 11 deletions(-)
>
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index e7227649bac7..da0767128f61 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -415,8 +415,8 @@ static void add_ignores(struct objtool_file *file)
>                         break;
>
>                 case STT_SECTION:
> -                       func = find_symbol_by_offset(rela->sym->sec, rela->addend);
> -                       if (!func || func->type != STT_FUNC)
> +                       func = find_func_by_offset(rela->sym->sec, rela->addend);
> +                       if (!func)
>                                 continue;
>                         break;
>
> @@ -679,10 +679,14 @@ static int add_call_destinations(struct objtool_file *file)
>                                                insn->len);
>                 if (!rela) {
>                         dest_off = insn->offset + insn->len + insn->immediate;
> -                       insn->call_dest = find_symbol_by_offset(insn->sec,
> -                                                               dest_off);
> +                       insn->call_dest = find_func_by_offset(insn->sec, dest_off);
> +                       if (!insn->call_dest)
> +                               insn->call_dest = find_symbol_by_offset(insn->sec, dest_off);
>
> -                       if (!insn->call_dest && !insn->ignore) {
> +                       if (insn->ignore)
> +                               continue;
> +
> +                       if (!insn->call_dest) {
>                                 WARN_FUNC("unsupported intra-function call",
>                                           insn->sec, insn->offset);
>                                 if (retpoline)
> @@ -690,11 +694,16 @@ static int add_call_destinations(struct objtool_file *file)
>                                 return -1;
>                         }
>
> +                       if (insn->func && insn->call_dest->type != STT_FUNC) {
> +                               WARN_FUNC("unsupported call to non-function",
> +                                         insn->sec, insn->offset);
> +                               return -1;
> +                       }
> +
>                 } else if (rela->sym->type == STT_SECTION) {
> -                       insn->call_dest = find_symbol_by_offset(rela->sym->sec,
> -                                                               rela->addend+4);
> -                       if (!insn->call_dest ||
> -                           insn->call_dest->type != STT_FUNC) {
> +                       insn->call_dest = find_func_by_offset(rela->sym->sec,
> +                                                             rela->addend+4);
> +                       if (!insn->call_dest) {
>                                 WARN_FUNC("can't find call dest symbol at %s+0x%x",
>                                           insn->sec, insn->offset,
>                                           rela->sym->sec->name,
> diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> index edba4745f25a..cc4601c879ce 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -62,8 +62,18 @@ struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset)
>         struct symbol *sym;
>
>         list_for_each_entry(sym, &sec->symbol_list, list)
> -               if (sym->type != STT_SECTION &&
> -                   sym->offset == offset)
> +               if (sym->type != STT_SECTION && sym->offset == offset)
> +                       return sym;
> +
> +       return NULL;
> +}
> +
> +struct symbol *find_func_by_offset(struct section *sec, unsigned long offset)
> +{
> +       struct symbol *sym;
> +
> +       list_for_each_entry(sym, &sec->symbol_list, list)
> +               if (sym->type == STT_FUNC && sym->offset == offset)
>                         return sym;
>
>         return NULL;
> diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h
> index 44150204db4d..a1963259b930 100644
> --- a/tools/objtool/elf.h
> +++ b/tools/objtool/elf.h
> @@ -77,6 +77,7 @@ struct elf {
>
>  struct elf *elf_read(const char *name, int flags);
>  struct section *find_section_by_name(struct elf *elf, const char *name);
> +struct symbol *find_func_by_offset(struct section *sec, unsigned long offset);
>  struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset);
>  struct symbol *find_symbol_by_name(struct elf *elf, const char *name);
>  struct symbol *find_symbol_containing(struct section *sec, unsigned long offset);
> --
> 2.21.1
>


-- 
Thanks,
~Nick Desaulniers

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ