lkml.org 
[lkml]   [2018]   [Nov]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] objtool: fix .cold. functions parent symbols search
On Wed, Nov 07, 2018 at 03:05:59PM +0100, Artem Savkov wrote:
> The way it is currently done it is possible for read_symbols() to find the
> same symbol as parent for ".cold" functions.

I seem to remember having this discussion for kpatch-build, but I forget
the details. Can you explain how this can happen (and also add that
detail to the commit message)? I haven't seen any bug reports, is it
purely theoretical?

> This leads to a bunch of
> complications such as func length being set to 0 and a segfault in
> add_switch_table(). Fix by copying the search string instead of modifying
> it in place.
>
> Signed-off-by: Artem Savkov <asavkov@redhat.com>
> ---
> tools/objtool/elf.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> index 6dbb9fae0f9d..781c8afb29b9 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -298,6 +298,7 @@ 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;
> if (sym->type != STT_FUNC)
> continue;
> sym->pfunc = sym->cfunc = sym;
> @@ -305,9 +306,9 @@ static int read_symbols(struct elf *elf)
> if (!coldstr)
> continue;
>
> - coldstr[0] = '\0';
> - pfunc = find_symbol_by_name(elf, sym->name);
> - coldstr[0] = '.';
> + pname = strndup(sym->name, coldstr - sym->name);
> + pfunc = find_symbol_by_name(elf, pname);
> + free(pname);
>
> if (!pfunc) {
> WARN("%s(): can't find parent function",
> --
> 2.17.2
>

--
Josh

\
 
 \ /
  Last update: 2018-11-07 18:10    [W:0.051 / U:1.604 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site