Skip to content

Commit a22d167

Browse files
captain5050acmel
authored andcommitted
perf parse-events: Fix parsing of >30kb event strings
Metrics may generate many particularly uncore event references. The resulting event string may then be >32kb. The parse events lex is using "%option reject" which stores backtracking state in a buffer sized at roughtly 30kb. If the event string is larger than this then a buffer overflow and typically a crash happens. The need for "%option reject" was for BPF events which were removed in commit 3d6dfae ("perf parse-events: Remove BPF event support"). As "%option reject" is both a memory and performance cost let's remove it and fix the parsing case for event strings being over ~30kb. Whilst cleaning up "%option reject" make the header files accurately reflect functions used in the code and tidy up not requiring yywrap. Measuring on the "PMU JSON event tests" a modest reduction of 0.41% user time and 0.27% max resident size was observed. More importantly this change fixes parsing large metrics and event strings. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 56be0fe commit a22d167

1 file changed

Lines changed: 3 additions & 14 deletions

File tree

tools/perf/util/parse-events.l

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
%option stack
66
%option bison-locations
77
%option yylineno
8-
%option reject
8+
%option noyywrap
99

1010
%{
1111
#include <errno.h>
12-
#include <sys/types.h>
13-
#include <sys/stat.h>
14-
#include <unistd.h>
12+
#include <stdlib.h>
13+
#include <stdio.h>
1514
#include "parse-events.h"
1615
#include "parse-events-bison.h"
17-
#include "evsel.h"
1816

1917
char *parse_events_get_text(yyscan_t yyscanner);
2018
YYSTYPE *parse_events_get_lval(yyscan_t yyscanner);
@@ -223,10 +221,6 @@ do { \
223221
yycolumn += yyleng; \
224222
} while (0);
225223

226-
#define USER_REJECT \
227-
yycolumn -= yyleng; \
228-
REJECT
229-
230224
%}
231225

232226
%x mem
@@ -425,8 +419,3 @@ r{num_raw_hex} { return str(yyscanner, PE_RAW); }
425419
. { }
426420

427421
%%
428-
429-
int parse_events_wrap(void *scanner __maybe_unused)
430-
{
431-
return 1;
432-
}

0 commit comments

Comments
 (0)