mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
perf tools kvm: Fix the potential out of range memory access issue
kvm_add_default_arch_event() helper may add 2 extra options but it directly modifies the original argv[] array. This may cause out of range memory access. Fix this issue. Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
6f58cf1045
commit
45ff39f6e7
@@ -2008,11 +2008,12 @@ static int __cmd_record(const char *file_name, int argc, const char **argv)
|
||||
int rec_argc, i = 0, j, ret;
|
||||
const char **rec_argv;
|
||||
|
||||
ret = kvm_add_default_arch_event(&argc, argv);
|
||||
if (ret)
|
||||
return -EINVAL;
|
||||
|
||||
rec_argc = argc + 2;
|
||||
/*
|
||||
* Besides the 2 more options "-o" and "filename",
|
||||
* kvm_add_default_arch_event() may add 2 extra options,
|
||||
* so allocate 4 more items.
|
||||
*/
|
||||
rec_argc = argc + 2 + 2;
|
||||
rec_argv = calloc(rec_argc + 1, sizeof(char *));
|
||||
if (!rec_argv)
|
||||
return -ENOMEM;
|
||||
@@ -2025,6 +2026,10 @@ static int __cmd_record(const char *file_name, int argc, const char **argv)
|
||||
|
||||
BUG_ON(i != rec_argc);
|
||||
|
||||
ret = kvm_add_default_arch_event(&i, rec_argv);
|
||||
if (ret)
|
||||
goto EXIT;
|
||||
|
||||
ret = cmd_record(i, rec_argv);
|
||||
|
||||
EXIT:
|
||||
|
||||
Reference in New Issue
Block a user