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]
Date:   Thu, 14 Jan 2021 22:30:18 +0100
From:   Sedat Dilek <sedat.dilek@...il.com>
To:     Josh Poimboeuf <jpoimboe@...hat.com>
Cc:     x86@...nel.org, linux-kernel@...r.kernel.org,
        Peter Zijlstra <peterz@...radead.org>,
        Sami Tolvanen <samitolvanen@...gle.com>,
        Kees Cook <keescook@...omium.org>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Clang-Built-Linux ML <clang-built-linux@...glegroups.com>,
        Miroslav Benes <mbenes@...e.cz>
Subject: Re: [PATCH v1.1 11/21] objtool: Move unsuffixed symbol conversion to
 a helper function

On Thu, Jan 14, 2021 at 9:55 PM Josh Poimboeuf <jpoimboe@...hat.com> wrote:
>
> This logic will also be needed for the CONFIG_CFI_CLANG support.
>

Good you fixed that in v2.
I re-pulled from [1].

- Sedat -

[1] https://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git/log/?h=objtool-vmlinux

> Signed-off-by: Josh Poimboeuf <jpoimboe@...hat.com>
> ---
>  tools/objtool/elf.c | 60 ++++++++++++++++++++++++++++-----------------
>  1 file changed, 37 insertions(+), 23 deletions(-)
>
> diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> index be89c741ba9a..6d248a19e2c6 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -262,6 +262,38 @@ struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, uns
>         return find_reloc_by_dest_range(elf, sec, offset, 1);
>  }
>
> +static int find_unsuffixed_func(const struct elf *elf, struct symbol *sym,
> +                               const char *suffix, struct symbol **func)
> +{
> +       char name[MAX_NAME_LEN + 1];
> +       const char *loc;
> +       size_t len;
> +
> +       *func = NULL;
> +
> +       loc = strstr(sym->name, suffix);
> +       if (!loc)
> +               return 0;
> +
> +       len = loc - sym->name;
> +       if (len > MAX_NAME_LEN) {
> +               WARN("%s(): unsuffixed function name exceeds maximum length of %d characters",
> +                    sym->name, MAX_NAME_LEN);
> +               return -1;
> +       }
> +
> +       strncpy(name, sym->name, len);
> +       name[len] = '\0';
> +
> +       *func = find_symbol_by_name(elf, name);
> +       if (!*func || (*func)->type != STT_FUNC) {
> +               WARN("%s(): can't find unsuffixed function", sym->name);
> +               return -1;
> +       }
> +
> +       return 0;
> +}
> +
>  void insn_to_reloc_sym_addend(struct section *sec, unsigned long offset,
>                               struct reloc *reloc)
>  {
> @@ -374,7 +406,6 @@ static int read_symbols(struct elf *elf)
>         struct list_head *entry;
>         struct rb_node *pnode;
>         int symbols_nr, i;
> -       char *coldstr;
>         Elf_Data *shndx_data = NULL;
>         Elf32_Word shndx;
>
> @@ -456,37 +487,20 @@ static int read_symbols(struct elf *elf)
>         /* Create parent/child links for any cold subfunctions */
>         list_for_each_entry(sec, &elf->sections, list) {
>                 list_for_each_entry(sym, &sec->symbol_list, list) {
> -                       char pname[MAX_NAME_LEN + 1];
> -                       size_t pnamelen;
>                         if (sym->type != STT_FUNC)
>                                 continue;
>
> -                       if (sym->pfunc == NULL)
> +                       if (!sym->pfunc)
>                                 sym->pfunc = sym;
>
> -                       if (sym->cfunc == NULL)
> +                       if (!sym->cfunc)
>                                 sym->cfunc = sym;
>
> -                       coldstr = strstr(sym->name, ".cold");
> -                       if (!coldstr)
> -                               continue;
> -
> -                       pnamelen = coldstr - sym->name;
> -                       if (pnamelen > MAX_NAME_LEN) {
> -                               WARN("%s(): parent function name exceeds maximum length of %d characters",
> -                                    sym->name, MAX_NAME_LEN);
> +                       if (find_unsuffixed_func(elf, sym, ".cold", &pfunc))
>                                 return -1;
> -                       }
>
> -                       strncpy(pname, sym->name, pnamelen);
> -                       pname[pnamelen] = '\0';
> -                       pfunc = find_symbol_by_name(elf, pname);
> -
> -                       if (!pfunc) {
> -                               WARN("%s(): can't find parent function",
> -                                    sym->name);
> -                               return -1;
> -                       }
> +                       if (!pfunc)
> +                               continue;
>
>                         sym->pfunc = pfunc;
>                         pfunc->cfunc = sym;
> --
> 2.29.2
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ