Vince Weaver <[email protected]> writes:

> On Thu, 17 Nov 2016, Vince Weaver wrote:
>
>> On Thu, 17 Nov 2016, Vince Weaver wrote:
>> > > 
>> > > [  911.507365] 
>> > > ==================================================================
>> > > [  911.514824] BUG: KASAN: global-out-of-bounds in 
>> > > match_token+0x268/0x310 at addr ffffffffb14ad058
>> > > [  911.523912] Read of size 8 by task perf_fuzzer/20662
>> > > [  911.528945] Address belongs to variable if_tokens+0x78/0xa0
>
> I managed to create a short reproducer that reliably causes the issue on 
> my skylake test machine.

Thanks a bunch, and ugh, this is embarrassing.

>From 139306c3bcf7abf49c51a8e56131aaae51222594 Mon Sep 17 00:00:00 2001
From: Alexander Shishkin <[email protected]>
Date: Fri, 18 Nov 2016 13:24:55 +0200
Subject: [PATCH] perf: Fix address filter parser

The token table passed into match_token() must be null-terminated, which
it currently is not in the perf's address filter string parser, as caught
by Vince's perf_fuzzer and KASAN. It doesn't blow up otherwise because of
the alignment padding of the table to the next element in the .rodata,
which is luck.

Fixing by adding a null-terminator to the token table.

Signed-off-by: Alexander Shishkin <[email protected]>
Fixes: 375637bc524 ("perf/core: Introduce address range filtering")
Reported-by: Vince Weaver <[email protected]>
Cc: [email protected] # v4.7+
---
 kernel/events/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index c6e47e97b3..63c72dee71 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8012,6 +8012,7 @@ static void perf_event_addr_filters_apply(struct 
perf_event *event)
  * if <size> is not specified, the range is treated as a single address.
  */
 enum {
+       IF_ACT_NONE = -1,
        IF_ACT_FILTER,
        IF_ACT_START,
        IF_ACT_STOP,
@@ -8035,6 +8036,7 @@ static const match_table_t if_tokens = {
        { IF_SRC_KERNEL,        "%u/%u" },
        { IF_SRC_FILEADDR,      "%u@%s" },
        { IF_SRC_KERNELADDR,    "%u" },
+       { IF_ACT_NONE,          NULL },
 };
 
 /*
-- 
2.10.2

Reply via email to