Patch "perf header: Fix segfault on build_mem_topology() error path" has been added to the 6.7-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    perf header: Fix segfault on build_mem_topology() error path

to the 6.7-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     perf-header-fix-segfault-on-build_mem_topology-error.patch
and it can be found in the queue-6.7 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 4e6a133750c8c8bcd893131f17f590c98d6b3fc4
Author: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Date:   Thu Nov 23 09:58:41 2023 +0200

    perf header: Fix segfault on build_mem_topology() error path
    
    [ Upstream commit 70df07838fc1c0acfab3325ae79014e241a88bdf ]
    
    Do not increase the node count unless a node has been successfully read,
    because it can lead to a segfault if an error occurs.
    
    For example, if perf exceeds the open file limit in memory_node__read(),
    which, on a test system, could be made to happen by setting the file limit
    to exactly 32:
    
     Before:
    
      $ ulimit -n 32
      $ perf mem record --all-user -- sleep 1
      [ perf record: Woken up 1 times to write data ]
      failed: can't open memory sysfs data
      perf: Segmentation fault
      Obtained 14 stack frames.
      perf(sighandler_dump_stack+0x48) [0x55f4b1f59558]
      /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f4ba1c42520]
      /lib/x86_64-linux-gnu/libc.so.6(free+0x1e) [0x7f4ba1ca53fe]
      perf(+0x178ff4) [0x55f4b1f48ff4]
      perf(+0x179a70) [0x55f4b1f49a70]
      perf(+0x17ef5d) [0x55f4b1f4ef5d]
      perf(+0x85c0b) [0x55f4b1e55c0b]
      perf(cmd_record+0xe1d) [0x55f4b1e5920d]
      perf(cmd_mem+0xc96) [0x55f4b1e80e56]
      perf(+0x130460) [0x55f4b1f00460]
      perf(main+0x689) [0x55f4b1e427d9]
      /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f4ba1c29d90]
      /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f4ba1c29e40]
      perf(_start+0x25) [0x55f4b1e42a25]
      Segmentation fault (core dumped)
      $
    
    After:
    
      $ ulimit -n 32
      $ perf mem record --all-user -- sleep 1
      [ perf record: Woken up 1 times to write data ]
      failed: can't open memory sysfs data
      [ perf record: Captured and wrote 0.005 MB perf.data (11 samples) ]
      $
    
    Fixes: f8e502b9d1b3b197 ("perf header: Ensure bitmaps are freed")
    Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
    Acked-by: Ian Rogers <irogers@xxxxxxxxxx>
    Cc: German Gomez <german.gomez@xxxxxxx>
    Cc: Ian Rogers <irogers@xxxxxxxxxx>
    Cc: James Clark <james.clark@xxxxxxx>
    Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
    Cc: Leo Yan <leo.yan@xxxxxxxxxx>
    Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20231123075848.9652-2-adrian.hunter@xxxxxxxxx
    Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index e86b9439ffee..7609b4d468dc 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1444,7 +1444,9 @@ static int build_mem_topology(struct memory_node **nodesp, u64 *cntp)
 			nodes = new_nodes;
 			size += 4;
 		}
-		ret = memory_node__read(&nodes[cnt++], idx);
+		ret = memory_node__read(&nodes[cnt], idx);
+		if (!ret)
+			cnt += 1;
 	}
 out:
 	closedir(dir);




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux