Revert "perf unwind-libdw: Fix invalid reference counts"
PATCH 1/1 Revert "perf unwind-libdw: Fix invalid reference counts"
This reverts commit eddddf4ed7f69697cb54e714e773f764c8d3b67e.
Upstream commit f815fc0c66e7 ("perf unwind-libdw: Fix invalid reference counts"), was backported to v6.6.128 as eddddf4ed7f6.
However, this commit depends on map_symbol__exit, which was introduced in v6.7 as commit 56e144fe9826 ("perf mem_info: Add and use map_symbol__exit and addr_map_symbol__exit") and is absent in v6.6.y. This results in a build failure.
This is a revert of a backport, so there is no upstream commit.
--- tools/perf/util/unwind-libdw.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
tools/perf/util/unwind-libdw.c +2 -5
@@ -133,8 +133,8 @@ static int entry(u64 ip, struct unwind_info *ui) } e->ip = ip; - e->ms.maps =maps__get (al.maps); - e->ms.map =map__get (al.map); + e->ms.maps = al.maps; + e->ms.map = al.map; e->ms.sym = al.sym; pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",
@@ -319,9 +319,6 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,if (err)pr_debug ("unwind: failed with '%s'\n" ,dwfl_errmsg (-1 )); -for (i =0 ; i < ui->idx; i++) -map_symbol__exit (&ui->entries[i].ms); -dwfl_end (ui->dwfl);free (ui);return 0 ;
Signature · 1 line
2.50.1
[email protected]
AI reviewSashiko AI review found 1 potential issue(s): - [Medium] Reverting a valid bug fix to resolve a backport build failure reintroduces a use-after-free vulnerability in perf's libdw unwinder. --
Sashiko AI review found 1 potential issue(s):
- [Medium] Reverting a valid bug fix to resolve a backport build failure reintroduces a use-after-free vulnerability in perf's libdw unwinder. --
commit 476f57f8f24801b0104204e756b3e024069b04e7
Author: Kenta Akagi <[email protected]>
Revert "perf unwind-libdw: Fix invalid reference counts"
This commit reverts a backport to resolve a build failure in v6.6.y caused by the absence of map_symbol__exit().
Quoted 4 lines
tools/perf/util/unwind-libdw.c static int entry(u64 ip, struct unwind_info *ui) · line 140
Quoted 10 lines
tools/perf/util/unwind-libdw.c +2
-2@@ -133,8 +133,8 @@ static int entry(u64 ip, struct unwind_info *ui) } e->ip = ip; - e->ms.maps =maps__get (al.maps); - e->ms.map =map__get (al.map); + e->ms.maps = al.maps; + e->ms.map = al.map; e->ms.sym = al.sym; pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",
Does removing these reference increments reintroduce a use-after-free regression?
Directly after these assignments, entry() calls addr_location__exit():
tools/perf/util/unwind-libdw.c:entry() {
...
addr_location__exit(&al);
return 0;
}This drops the references held by al. If these were the last references, the map and maps objects will be freed.
The e->ms.maps and e->ms.map pointers are later accessed in unwind__get_entries() when it invokes the callback, potentially using memory that has already been freed:
tools/perf/util/unwind-libdw.c:unwind__get_entries() {
...
err = ui->entries[j].ip ? ui->cb(&ui->entries[j], ui->arg) : 0;
...
}[ ... ]
tools/perf/util/unwind-libdw.c int unwind__get_entries(unwind_entry_cb_t cb, void *arg, · line 324
Quoted 10 lines
tools/perf/util/unwind-libdw.c +0
-3@@ -319,9 +319,6 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,if (err)pr_debug ("unwind: failed with '%s'\n" ,dwfl_errmsg (-1 )); -for (i =0 ; i < ui->idx; i++) -map_symbol__exit (&ui->entries[i].ms); -dwfl_end (ui->dwfl);free (ui);return 0 ;
Instead of reverting the fix entirely because map_symbol__exit() is absent in v6.6.y, would it be safer to retain the map__get() and maps__get() calls in entry() and replace this loop with manual decrements using map__zput() and maps__zput() here?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 6 lines · Kenta Akagi
This reverts commit
eddddf4ed7f69697cb54e714e773f764c8d3b67e.Upstream commit
f815fc0c66e7("perf unwind-libdw: Fix invalid reference counts"), was backported to v6.6.128 aseddddf4ed7f6.
Quoted 6 lines
However, this commit depends on
map_symbol__exit, which was introduced in v6.7 as commit56e144fe9826("perfmem_info: Add and usemap_symbol__exitandaddr_map_symbol__exit") and is absent in v6.6.y. This results in a build failure.This is a revert of a backport, so there is no upstream commit.
I confirm map_symbol__exit is missing in 6.6.y:
https://web.git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/tools/perf/util/map_symbol.h?h=linux-6.6.y
but present later:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/tools/perf/util/map_symbol.h?h=perf-tools-next&id=56e144fe98260a0f8a17326993ceb576ef859ed5
Thanks,
Ian
Quoted 33 lines
Signed-off-by Kenta Akagi <[email protected]>--- tools/perf/util/unwind-libdw.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)tools/perf/util/unwind-libdw.c +2
-6@@ -133,8 +133,8 @@ static int entry(u64 ip, struct unwind_info *ui) } e->ip = ip; - e->ms.maps =maps__get (al.maps); - e->ms.map =map__get (al.map); + e->ms.maps = al.maps; + e->ms.map = al.map; e->ms.sym = al.sym; pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",@@ -319,9 +319,6 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,if (err)pr_debug ("unwind: failed with '%s'\n" ,dwfl_errmsg (-1 )); -for (i =0 ; i < ui->idx; i++) -map_symbol__exit (&ui->entries[i].ms); -dwfl_end (ui->dwfl);free (ui);return 0 ; --2.50.1