perf tools: Address fixes
Adrian Hunter
reviewercover perf tools: Address fixes
Hi
Here are 3 small fixes resulting from a report from a kernel test robot:
https://lore.kernel.org/oe-lkp/[email protected]
Issues were revealed due to the use of build
option:
EXTRA_CFLAGS="-fsanitize=undefined -fsanitize=address"
Adrian Hunter (3):
perf symbols: Fix use-after-free in get_plt_got_name() perf symbols: Fix unaligned access in get_x86_64_plt_disp() perf tools: Avoid warning in do_realloc_array_as_needed()
tools/perf/util/symbol-elf.c | 10 ++++++++-- tools/perf/util/util.c | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-)
Regards
Adrian
Adrian Hunter
reviewerPATCH 1/3 perf symbols: Fix use-after-free in get_plt_got_name()
Fix use-after-free in get_plt_got_name().
Discovered using EXTRA_CFLAGS="-fsanitize=undefined -fsanitize=address".
--- tools/perf/util/symbol-elf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/symbol-elf.c +4 -1
@@ -557,6 +557,7 @@ static bool get_plt_got_name(GElf_Shdr *shdr, size_t i,const char *sym_name;char *demangled;GElf_Sym sym; +bool result;u32 disp;if (!di->sorted)
@@ -583,9 +584,11 @@ static bool get_plt_got_name(GElf_Shdr *shdr, size_t i,snprintf (buf, buf_sz,"%s@plt" , sym_name); + result = *sym_name; +free (demangled); -return *sym_name; +return result; } static int dso__synthesize_plt_got_symbols(struct dso *dso, Elf *elf,
Signature · 1 line
2.34.1
Adrian Hunter
reviewerPATCH 2/3 perf symbols: Fix unaligned access in get_x86_64_plt_disp()
In reply to Adrian HunterUse memcpy() to avoid unaligned access.
Discovered using EXTRA_CFLAGS="-fsanitize=undefined -fsanitize=address".
--- tools/perf/util/symbol-elf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/symbol-elf.c +4 -1
@@ -542,9 +542,12 @@ static u32 get_x86_64_plt_disp(const u8 *p) n +=1 ;/* jmp with 4-byte displacement */ if (p[n] ==0xff && p[n +1 ] ==0x25 ) { +u32 disp; + n +=2 ;/* Also add offset from start of entry to end of instruction */ -return n +4 +le32toh (*(const u32 *)(p + n)); +memcpy (&disp, p + n,sizeof (disp)); +return n +4 +le32toh (disp); }return 0 ; }
Signature · 1 line
2.34.1
Adrian Hunter
reviewerPATCH 3/3 perf tools: Avoid warning in do_realloc_array_as_needed()
In reply to Adrian Hunterdo_realloc_array_as_needed() used memcpy() of zero size with a NULL pointer. Check the size first to avoid sanitize warning.
Discovered using EXTRA_CFLAGS="-fsanitize=undefined -fsanitize=address".
--- tools/perf/util/util.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/util.c +2 -1
@@ -524,7 +524,8 @@ int do_realloc_array_as_needed(void **arr, size_t *arr_sz, size_t x, size_t msz, new_arr =calloc (new_sz, msz);if (!new_arr)return -ENOMEM ; -memcpy (new_arr, *arr, *arr_sz * msz); +if (*arr_sz) +memcpy (new_arr, *arr, *arr_sz * msz);if (init_val) {for (i = *arr_sz; i < new_sz; i++)memcpy (new_arr + (i * msz), init_val, msz);
Signature · 1 line
2.34.1
Quoted 11 lines · Adrian Hunter
Hi
Here are 3 small fixes resulting from a report from a kernel test robot:
https://lore.kernel.org/oe-lkp/[email protected]
Issues were revealed due to the use of build
option:
Quoted 7 lines
EXTRA_CFLAGS="-fsanitize=undefined -fsanitize=address"
Adrian Hunter (3):
perf symbols: Fix use-after-free inget_plt_got_name()perf symbols: Fix unaligned access inget_x86_64_plt_disp()perf tools: Avoid warning indo_realloc_array_as_needed()
All 3:
Thanks,
Ian
Quoted 7 lines
tools/perf/util/symbol-elf.c | 10 ++++++++-- tools/perf/util/util.c | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-)Regards
Adrian
Adrian Hunter
reviewerQuoted 13 lines · Adrian Hunter
Hi
Here are 3 small fixes resulting from a report from a kernel test robot:
https://lore.kernel.org/oe-lkp/[email protected]
Issues were revealed due to the use of build
option:EXTRA_CFLAGS="-fsanitize=undefined -fsanitize=address"
Quoted 8 lines
Adrian Hunter (3):
perf symbols: Fix use-after-free inget_plt_got_name()perf symbols: Fix unaligned access inget_x86_64_plt_disp()perf tools: Avoid warning indo_realloc_array_as_needed()tools/perf/util/symbol-elf.c | 10 ++++++++-- tools/perf/util/util.c | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-)
These seem to be still outstanding.
Arnaldo Carvalho de Melo
maintainerEm Wed, Mar 29, 2023 at 08:07:42AM +0300, Adrian Hunter escreveu:
Quoted 19 lines · Adrian Hunter
Quoted 18 lines
Hi
Here are 3 small fixes resulting from a report from a kernel test robot:
https://lore.kernel.org/oe-lkp/[email protected]
Issues were revealed due to the use of build
option:EXTRA_CFLAGS="-fsanitize=undefined -fsanitize=address"
Adrian Hunter (3):
perf symbols: Fix use-after-free inget_plt_got_name()perf symbols: Fix unaligned access inget_x86_64_plt_disp()perf tools: Avoid warning indo_realloc_array_as_needed()
Quoted 5 lines
Quoted 3 lines
tools/perf/util/symbol-elf.c | 10 ++++++++-- tools/perf/util/util.c | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-)These seem to be still outstanding.
Thanks for the reminder, applied.
- Arnaldo