From: Greg Kroah-Hartman <gregkh@linuxfoundation•org>
To: linux-kernel@vger•kernel.org
Cc: Song Liu <songliubraving@fb•com>,
Konstantin Khlebnikov <khlebnikov@yandex-team•ru>,
Rasmus Villemoes <linux@rasmusvillemoes•dk>,
Jin Yao <yao.jin@linux•intel.com>,
Sasha Levin <sashal@kernel•org>, Andi Kleen <ak@linux•intel.com>,
Alexey Budankov <alexey.budankov@linux•intel.com>,
Alexander Shishkin <alexander.shishkin@linux•intel.com>,
Suzuki Poulouse <suzuki.poulose@arm•com>,
Arnaldo Carvalho de Melo <acme@redhat•com>,
Alexios Zavras <alexios.zavras@intel•com>,
Davidlohr Bueso <dave@stgolabs•net>,
Namhyung Kim <namhyung@kernel•org>,
Thomas Gleixner <tglx@linutronix•de>,
linux-arm-kernel@lists•infradead.org,
Mathieu Poirier <mathieu.poirier@linaro•org>,
Greg Kroah-Hartman <gregkh@linuxfoundation•org>,
Thomas Richter <tmricht@linux•ibm.com>,
Adrian Hunter <adrian.hunter@intel•com>,
stable@vger•kernel.org, "David S. Miller" <davem@davemloft•net>,
Changbin Du <changbin.du@intel•com>,
Peter Zijlstra <peterz@infradead•org>,
Jiri Olsa <jolsa@kernel•org>, Leo Yan <leo.yan@linaro•org>,
Eric Saint-Etienne <eric.saint.etienne@oracle•com>
Subject: [PATCH 4.19 071/113] perf annotate: Fix dereferencing freed memory found by the smatch tool
Date: Mon, 29 Jul 2019 21:22:38 +0200 [thread overview]
Message-ID: <20190729190712.439276151@linuxfoundation.org> (raw)
In-Reply-To: <20190729190655.455345569@linuxfoundation.org>
[ Upstream commit 600c787dbf6521d8d07ee717ab7606d5070103ea ]
Based on the following report from Smatch, fix the potential
dereferencing freed memory check.
tools/perf/util/annotate.c:1125
disasm_line__parse() error: dereferencing freed memory 'namep'
tools/perf/util/annotate.c
1100 static int disasm_line__parse(char *line, const char **namep, char **rawp)
1101 {
1102 char tmp, *name = ltrim(line);
[...]
1114 *namep = strdup(name);
1115
1116 if (*namep == NULL)
1117 goto out_free_name;
[...]
1124 out_free_name:
1125 free((void *)namep);
^^^^^
1126 *namep = NULL;
^^^^^^
1127 return -1;
1128 }
If strdup() fails to allocate memory space for *namep, we don't need to
free memory with pointer 'namep', which is resident in data structure
disasm_line::ins::name; and *namep is NULL pointer for this failure, so
it's pointless to assign NULL to *namep again.
Committer note:
Freeing namep, which is the address of the first entry of the 'struct
ins' that is the first member of struct disasm_line would in fact free
that disasm_line instance, if it was allocated via malloc/calloc, which,
later, would a dereference of freed memory.
Signed-off-by: Leo Yan <leo.yan@linaro•org>
Acked-by: Jiri Olsa <jolsa@kernel•org>
Cc: Adrian Hunter <adrian.hunter@intel•com>
Cc: Alexander Shishkin <alexander.shishkin@linux•intel.com>
Cc: Alexey Budankov <alexey.budankov@linux•intel.com>
Cc: Alexios Zavras <alexios.zavras@intel•com>
Cc: Andi Kleen <ak@linux•intel.com>
Cc: Changbin Du <changbin.du@intel•com>
Cc: David S. Miller <davem@davemloft•net>
Cc: Davidlohr Bueso <dave@stgolabs•net>
Cc: Eric Saint-Etienne <eric.saint.etienne@oracle•com>
Cc: Jin Yao <yao.jin@linux•intel.com>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team•ru>
Cc: Mathieu Poirier <mathieu.poirier@linaro•org>
Cc: Namhyung Kim <namhyung@kernel•org>
Cc: Peter Zijlstra <peterz@infradead•org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes•dk>
Cc: Song Liu <songliubraving@fb•com>
Cc: Suzuki Poulouse <suzuki.poulose@arm•com>
Cc: Thomas Gleixner <tglx@linutronix•de>
Cc: Thomas Richter <tmricht@linux•ibm.com>
Cc: linux-arm-kernel@lists•infradead.org
Link: http://lkml.kernel.org/r/20190702103420.27540-5-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat•com>
Signed-off-by: Sasha Levin <sashal@kernel•org>
---
tools/perf/util/annotate.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index c357051dd2b6..daea1fdf7385 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1079,16 +1079,14 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp)
*namep = strdup(name);
if (*namep == NULL)
- goto out_free_name;
+ goto out;
(*rawp)[0] = tmp;
*rawp = ltrim(*rawp);
return 0;
-out_free_name:
- free((void *)namep);
- *namep = NULL;
+out:
return -1;
}
--
2.20.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists•infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-07-29 19:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190729190655.455345569@linuxfoundation.org>
2019-07-29 19:22 ` [PATCH 4.19 068/113] perf stat: Fix use-after-freed pointer detected by the smatch tool Greg Kroah-Hartman
2019-07-29 19:22 ` [PATCH 4.19 069/113] perf top: Fix potential NULL pointer dereference " Greg Kroah-Hartman
2019-07-29 19:22 ` [PATCH 4.19 070/113] perf session: Fix potential NULL pointer dereference found " Greg Kroah-Hartman
2019-07-29 19:22 ` Greg Kroah-Hartman [this message]
2019-07-29 19:22 ` [PATCH 4.19 072/113] perf hists browser: " Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190729190712.439276151@linuxfoundation.org \
--to=gregkh@linuxfoundation$(echo .)org \
--cc=acme@redhat$(echo .)com \
--cc=adrian.hunter@intel$(echo .)com \
--cc=ak@linux$(echo .)intel.com \
--cc=alexander.shishkin@linux$(echo .)intel.com \
--cc=alexey.budankov@linux$(echo .)intel.com \
--cc=alexios.zavras@intel$(echo .)com \
--cc=changbin.du@intel$(echo .)com \
--cc=dave@stgolabs$(echo .)net \
--cc=davem@davemloft$(echo .)net \
--cc=eric.saint.etienne@oracle$(echo .)com \
--cc=jolsa@kernel$(echo .)org \
--cc=khlebnikov@yandex-team$(echo .)ru \
--cc=leo.yan@linaro$(echo .)org \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linux@rasmusvillemoes$(echo .)dk \
--cc=mathieu.poirier@linaro$(echo .)org \
--cc=namhyung@kernel$(echo .)org \
--cc=peterz@infradead$(echo .)org \
--cc=sashal@kernel$(echo .)org \
--cc=songliubraving@fb$(echo .)com \
--cc=stable@vger$(echo .)kernel.org \
--cc=suzuki.poulose@arm$(echo .)com \
--cc=tglx@linutronix$(echo .)de \
--cc=tmricht@linux$(echo .)ibm.com \
--cc=yao.jin@linux$(echo .)intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox