2019-02-28 01:56:33

by Tony Jones

[permalink] [raw]
Subject: [PATCH] tools lib traceevent: Fix buffer overflow in arg_eval

Fix buffer overflow observed when running perf test.

The overflow is when trying to evaluate "1ULL << (64 - 1)" which
is resulting in -9223372036854775808 which overflows the 20 character
buffer.

If is possible this bug has been reported before but I still don't
see any fix checked in:

See: https://www.spinics.net/lists/linux-perf-users/msg07714.html

Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: [email protected]
Cc: Steven Rostedt <[email protected]>
Signed-off-by: Tony Jones <[email protected]>
---
tools/lib/traceevent/event-parse.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index abd4fa5d3088..87494c7c619d 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/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[24];

switch (arg->type) {
case TEP_PRINT_ATOM:
--
2.20.1



2019-02-28 03:13:55

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] tools lib traceevent: Fix buffer overflow in arg_eval

On Wed, 27 Feb 2019 17:55:32 -0800
Tony Jones <[email protected]> wrote:

> Fix buffer overflow observed when running perf test.
>
> The overflow is when trying to evaluate "1ULL << (64 - 1)" which
> is resulting in -9223372036854775808 which overflows the 20 character
> buffer.
>
> If is possible this bug has been reported before but I still don't
> see any fix checked in:
>
> See: https://www.spinics.net/lists/linux-perf-users/msg07714.html
>
> Cc: Arnaldo Carvalho de Melo <[email protected]>
> Cc: [email protected]
> Cc: Steven Rostedt <[email protected]>
> Signed-off-by: Tony Jones <[email protected]>

Acked-by: Steven Rostedt (VMware) <[email protected]>

I have to say I've let this slide and it is not the first time a patch
went out with this fix. But this one has the correct fix because we
should use a buffer with a multiple of 4. Anyway, Tony I believe was
the first to report this anyway.

For reference we have:

I first heard about Tony's complaint on a post to linux-perf-users on Jan 18.

But then we had after that:

Michael Sartain reported it on 1/24 (and fixed by Tzvetomir)
https://lore.kernel.org/linux-trace-devel/[email protected]/

It was later fixed again by Mathias Krause
https://lore.kernel.org/linux-trace-devel/[email protected]/

But since Tony was first to report it, and we discussed that it should
be 24 bytes, I would say this is the patch to take.

Again, sorry for not getting this acknowledged earlier and everyone doing
the same thing multiple times. :-/

Arnaldo, please take this patch. But also add:

Reported-by: Michael Sartain <[email protected]>
Reported-by: Mathias Krause <[email protected]>

Thanks,

-- Steve


> ---
> tools/lib/traceevent/event-parse.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/traceevent/event-parse.c
> b/tools/lib/traceevent/event-parse.c index abd4fa5d3088..87494c7c619d
> 100644 --- a/tools/lib/traceevent/event-parse.c
> +++ b/tools/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[24];
>
> switch (arg->type) {
> case TEP_PRINT_ATOM:


2019-02-28 19:10:17

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] tools lib traceevent: Fix buffer overflow in arg_eval

Em Thu, Feb 28, 2019 at 04:01:23PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Feb 27, 2019 at 10:12:50PM -0500, Steven Rostedt escreveu:
> > On Wed, 27 Feb 2019 17:55:32 -0800
> > Tony Jones <[email protected]> wrote:
> >
> > > Fix buffer overflow observed when running perf test.
> > >
> > > The overflow is when trying to evaluate "1ULL << (64 - 1)" which
> > > is resulting in -9223372036854775808 which overflows the 20 character
> > > buffer.
> > >
> > > If is possible this bug has been reported before but I still don't
> > > see any fix checked in:
> > >
> > > See: https://www.spinics.net/lists/linux-perf-users/msg07714.html
> > >
> > > Cc: Arnaldo Carvalho de Melo <[email protected]>
> > > Cc: [email protected]
> > > Cc: Steven Rostedt <[email protected]>
> > > Signed-off-by: Tony Jones <[email protected]>
> >
> > Acked-by: Steven Rostedt (VMware) <[email protected]>
> >
> > I have to say I've let this slide and it is not the first time a patch
> > went out with this fix. But this one has the correct fix because we
> > should use a buffer with a multiple of 4. Anyway, Tony I believe was
> > the first to report this anyway.
> >
> > For reference we have:
> >
> > I first heard about Tony's complaint on a post to linux-perf-users on Jan 18.
> >
> > But then we had after that:
> >
> > Michael Sartain reported it on 1/24 (and fixed by Tzvetomir)
> > https://lore.kernel.org/linux-trace-devel/[email protected]/
> >
> > It was later fixed again by Mathias Krause
> > https://lore.kernel.org/linux-trace-devel/[email protected]/
> >
> > But since Tony was first to report it, and we discussed that it should
> > be 24 bytes, I would say this is the patch to take.
> >
> > Again, sorry for not getting this acknowledged earlier and everyone doing
> > the same thing multiple times. :-/
> >
> > Arnaldo, please take this patch. But also add:
> >
> > Reported-by: Michael Sartain <[email protected]>
> > Reported-by: Mathias Krause <[email protected]>
>
> Will do.
>
> Thanks for the credit research,

Some more research, an approximation, adding:

Cc: Frederic Weisbecker <[email protected]>
Fixes: f7d82350e597 ("tools/events: Add files to create libtraceevent.a")

That is the 'git blame' entry for when that line was added with sizeof
== 20

- Arnaldo

2019-02-28 21:25:17

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] tools lib traceevent: Fix buffer overflow in arg_eval

Em Wed, Feb 27, 2019 at 10:12:50PM -0500, Steven Rostedt escreveu:
> On Wed, 27 Feb 2019 17:55:32 -0800
> Tony Jones <[email protected]> wrote:
>
> > Fix buffer overflow observed when running perf test.
> >
> > The overflow is when trying to evaluate "1ULL << (64 - 1)" which
> > is resulting in -9223372036854775808 which overflows the 20 character
> > buffer.
> >
> > If is possible this bug has been reported before but I still don't
> > see any fix checked in:
> >
> > See: https://www.spinics.net/lists/linux-perf-users/msg07714.html
> >
> > Cc: Arnaldo Carvalho de Melo <[email protected]>
> > Cc: [email protected]
> > Cc: Steven Rostedt <[email protected]>
> > Signed-off-by: Tony Jones <[email protected]>
>
> Acked-by: Steven Rostedt (VMware) <[email protected]>
>
> I have to say I've let this slide and it is not the first time a patch
> went out with this fix. But this one has the correct fix because we
> should use a buffer with a multiple of 4. Anyway, Tony I believe was
> the first to report this anyway.
>
> For reference we have:
>
> I first heard about Tony's complaint on a post to linux-perf-users on Jan 18.
>
> But then we had after that:
>
> Michael Sartain reported it on 1/24 (and fixed by Tzvetomir)
> https://lore.kernel.org/linux-trace-devel/[email protected]/
>
> It was later fixed again by Mathias Krause
> https://lore.kernel.org/linux-trace-devel/[email protected]/
>
> But since Tony was first to report it, and we discussed that it should
> be 24 bytes, I would say this is the patch to take.
>
> Again, sorry for not getting this acknowledged earlier and everyone doing
> the same thing multiple times. :-/
>
> Arnaldo, please take this patch. But also add:
>
> Reported-by: Michael Sartain <[email protected]>
> Reported-by: Mathias Krause <[email protected]>

Will do.

Thanks for the credit research,

- Arnaldo

Subject: [tip:perf/urgent] tools lib traceevent: Fix buffer overflow in arg_eval

Commit-ID: 7c5b019e3a638a5a290b0ec020f6ca83d2ec2aaa
Gitweb: https://git.kernel.org/tip/7c5b019e3a638a5a290b0ec020f6ca83d2ec2aaa
Author: Tony Jones <[email protected]>
AuthorDate: Wed, 27 Feb 2019 17:55:32 -0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 28 Feb 2019 16:06:47 -0300

tools lib traceevent: Fix buffer overflow in arg_eval

Fix buffer overflow observed when running perf test.

The overflow is when trying to evaluate "1ULL << (64 - 1)" which is
resulting in -9223372036854775808 which overflows the 20 character
buffer.

If is possible this bug has been reported before but I still don't see
any fix checked in:

See: https://www.spinics.net/lists/linux-perf-users/msg07714.html

Reported-by: Michael Sartain <[email protected]>
Reported-by: Mathias Krause <[email protected]>
Signed-off-by: Tony Jones <[email protected]>
Acked-by: Steven Rostedt (VMware) <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Fixes: f7d82350e597 ("tools/events: Add files to create libtraceevent.a")
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/lib/traceevent/event-parse.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index abd4fa5d3088..87494c7c619d 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/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[24];

switch (arg->type) {
case TEP_PRINT_ATOM: