]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf header: Use a max number of command line args
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 8 Apr 2026 17:32:00 +0000 (14:32 -0300)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 9 Apr 2026 02:21:05 +0000 (19:21 -0700)
Sashiko suggests we use some reasonable max number of args to avoid
overflows when reading perf.data files, do it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/header.c

index a3b7b796639b42c02cb37e97f664e53f1a45ccb6..a18f216f77c27430adba2b9b8021445c278ef594 100644 (file)
@@ -2795,6 +2795,9 @@ process_event_desc(struct feat_fd *ff, void *data __maybe_unused)
        return 0;
 }
 
+// Some reasonable arbitrary max for the number of command line arguments
+#define MAX_CMDLINE_NR 32768
+
 static int process_cmdline(struct feat_fd *ff, void *data __maybe_unused)
 {
        struct perf_env *env = &ff->ph->env;
@@ -2804,6 +2807,9 @@ static int process_cmdline(struct feat_fd *ff, void *data __maybe_unused)
        if (do_read_u32(ff, &nr))
                return -1;
 
+       if (nr > MAX_CMDLINE_NR)
+               return -1;
+
        env->nr_cmdline = nr;
 
        cmdline = zalloc(ff->size + nr + 1);