]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
perf script: Fix invalid read of directory entry after closedir()
authorAndreas Gerstmayr <agerstmayr@redhat.com>
Thu, 2 Apr 2020 12:43:38 +0000 (14:43 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 3 Apr 2020 13:03:18 +0000 (10:03 -0300)
closedir(lang_dir) frees the memory of script_dirent->d_name, which
gets accessed in the next line in a call to scnprintf().

Valgrind report:

  Invalid read of size 1
  ==413557==    at 0x483CBE6: strlen (vg_replace_strmem.c:461)
  ==413557==    by 0x4DD45FD: __vfprintf_internal (vfprintf-internal.c:1688)
  ==413557==    by 0x4DE6679: __vsnprintf_internal (vsnprintf.c:114)
  ==413557==    by 0x53A037: vsnprintf (stdio2.h:80)
  ==413557==    by 0x53A037: scnprintf (vsprintf.c:21)
  ==413557==    by 0x435202: get_script_path (builtin-script.c:3223)
  ==413557==  Address 0x52e7313 is 1,139 bytes inside a block of size 32,816 free'd
  ==413557==    at 0x483AA0C: free (vg_replace_malloc.c:540)
  ==413557==    by 0x4E303C0: closedir (closedir.c:50)
  ==413557==    by 0x4351DC: get_script_path (builtin-script.c:3222)

Signed-off-by: Andreas Gerstmayr <agerstmayr@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20200402124337.419456-1-agerstmayr@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-script.c

index 186ebf827fa16149ff2e6ad4cd9d092e286973cf..1f57a7ecdf3d0aee1eac1f5414f6d4657bc7bfc3 100644 (file)
@@ -3265,10 +3265,10 @@ static char *get_script_path(const char *script_root, const char *suffix)
                        __script_root = get_script_root(script_dirent, suffix);
                        if (__script_root && !strcmp(script_root, __script_root)) {
                                free(__script_root);
-                               closedir(lang_dir);
                                closedir(scripts_dir);
                                scnprintf(script_path, MAXPATHLEN, "%s/%s",
                                          lang_path, script_dirent->d_name);
+                               closedir(lang_dir);
                                return strdup(script_path);
                        }
                        free(__script_root);