public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@elte.hu>
Subject: Re: [RFC] perf: Prevent potential null dereference
Date: Mon, 6 Dec 2010 01:13:21 +0300	[thread overview]
Message-ID: <20101205221321.GD7799@lenovo> (raw)
In-Reply-To: <20101202224609.GA31473@ghostprotocols.net>

On Thu, Dec 02, 2010 at 08:46:10PM -0200, Arnaldo Carvalho de Melo wrote:
> Em Thu, Dec 02, 2010 at 11:41:08PM +0100, Frederic Weisbecker escreveu:
> > On Fri, Dec 03, 2010 at 01:26:05AM +0300, Cyrill Gorcunov wrote:
> > > In case if there is no memory we might hit null
> > > dereference on accessing calloc'ed data.
> > > 
> > > Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
> > > CC: Arnaldo Carvalho de Melo <acme@redhat.com>
> > > CC: Peter Zijlstra <peterz@infradead.org>
> > > CC: Ingo Molnar <mingo@elte.hu>
> > > CC: Frederic Weisbecker <fweisbec@gmail.com>
> > > ---
...
> > 
> > Good.
> > 
> > As a nit, not that it matters that much because we are very close to the starting code
> > anyway, but it would be better to propagate the error to the callers.
> 
> I'm of the opinion that main() should be where exit() is allowed, and
> even there... return would be better. 8-)
> 
> - Arnaldo
> 

ok, sorry for delay, it seems the following would be liked
more than first version ;)

  Cyrill
---
[PATCH] perf: Prevent potential null dereference v2

In case if there is no memory we might hit null
dereference on accessing calloc'ed data.

v2: propagate error to a caller

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
CC: Arnaldo Carvalho de Melo <acme@redhat.com>,
CC: Peter Zijlstra <peterz@infradead.org>
CC: Ingo Molnar <mingo@elte.hu>
CC: Frederic Weisbecker <fweisbec@gmail.com>
---

NB it's unclear for me why don't we yield any message on
too long command line, but anyway even then it should not
be messed with this particular patch.

Arnaldo, I'll check builtin-kmem.c next time i be able to,
though if there anyone would like to beat me on this -- feel
free ;)

 tools/perf/builtin-record.c |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Index: linux-2.6.git/tools/perf/builtin-record.c
=====================================================================
--- linux-2.6.git.orig/tools/perf/builtin-record.c
+++ linux-2.6.git/tools/perf/builtin-record.c
@@ -507,7 +507,7 @@ static void mmap_read_all(void)
 		write_output(&finished_round_event, sizeof(finished_round_event));
 }
 
-static void comm__construct(int argc, const char **argv)
+static int comm__construct(int argc, const char **argv)
 {
 	char *comm, *tmp;
 	size_t size;
@@ -521,9 +521,13 @@ static void comm__construct(int argc, co
 	}
 
 	if ((long)size < 0)
-		return;
+		return 0;
 
 	comm = calloc(1, size);
+	if (!comm) {
+		pr_err("Not enough memory to construct internal command line.\n");
+		return -ENOMEM;
+	}
 
 	tmp = comm;
 	for (i = 0; i < argc; i++) {
@@ -533,6 +537,7 @@ static void comm__construct(int argc, co
 	}
 
 	session->command_line = comm;
+	return 0;
 }
 
 static int __cmd_record(int argc, const char **argv)
@@ -597,7 +602,10 @@ static int __cmd_record(int argc, const 
 	if (!no_buildid)
 		perf_header__set_feat(&session->header, HEADER_BUILD_ID);
 
-	comm__construct(argc, argv);
+	err = comm__construct(argc, argv);
+	if (err < 0)
+		goto out_delete_session;
+
 
 	if (!file_new) {
 		err = perf_header__read(session, output);

  parent reply	other threads:[~2010-12-05 22:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-02 22:26 [RFC] perf: Prevent potential null dereference Cyrill Gorcunov
2010-12-02 22:41 ` Frederic Weisbecker
2010-12-02 22:46   ` Arnaldo Carvalho de Melo
2010-12-02 22:48     ` Cyrill Gorcunov
2010-12-05 22:13     ` Cyrill Gorcunov [this message]
2010-12-06 14:49       ` Arnaldo Carvalho de Melo
2010-12-06 14:59         ` Cyrill Gorcunov

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=20101205221321.GD7799@lenovo \
    --to=gorcunov@gmail.com \
    --cc=acme@ghostprotocols.net \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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