Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Mathias Krause <minipli@googlemail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-devel@vger.kernel.org,
	Mathias Krause <minipli@googlemail.com>
Subject: [PATCH] tools lib traceevent: Fix BOF in arg_eval() when printing large negative values
Date: Sat, 23 Feb 2019 13:24:04 +0100
Message-ID: <20190223122404.21137-1-minipli@googlemail.com> (raw)

The buffer for printing large negative values is one byte too small as
can be seen below when trying to print LONG_MIN:

  $ printf "%lld" $[0x8000000000000000] | wc -c
  20

The number already needs 20 bytes, plus the '\0' terminator makes it 21
bytes. This results in a buffer overflow that gets detected by the
_FORTIFY_SOURCE logic and, in turn, ends up in an abort(3) call.

Resize the buffer to 22 bytes to have yet another spare byte.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
This commit should probably be backported to, at least, the
trace-cmd-stable-v2.6 branch as I ran into the issue there by using the
stock Debian/testing version of trace-cmd, trying to do a 'trace-cmd report'
on a large trace file.
---
 lib/traceevent/event-parse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/traceevent/event-parse.c b/lib/traceevent/event-parse.c
index 6f7f4be3c4ea..a8a4366d51cc 100644
--- a/lib/traceevent/event-parse.c
+++ b/lib/traceevent/event-parse.c
@@ -2457,7 +2457,7 @@ static int arg_num_eval(struct tep_print_arg *arg, long long *val)
 static char *arg_eval (struct tep_print_arg *arg)
 {
 	long long val;
-	static char buf[20];
+	static char buf[22];
 
 	switch (arg->type) {
 	case TEP_PRINT_ATOM:
-- 
2.20.1


                 reply index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190223122404.21137-1-minipli@googlemail.com \
    --to=minipli@googlemail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.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

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git