This is an archive of the discontinued LLVM Phabricator instance.

[LNT] lnt profile upgrade command for large Spec2017 perf.data aborts
ClosedPublic

Authored by PrzemekWirkus on May 4 2018, 8:12 AM.

Details

Summary

Hi,

This patch addresses issue with *stack smashing* while processing large perf.data files (>350 MB) e.g. obtained during Spec2017 sub-benchmarks' runs:
Example lnt profile upgrade failure:

$ lnt profile upgrade perf.data.510.parest_r.0 perf.data.510.parest_r.0.lnt
*** stack smashing detected ***: /opt/venv_lnt/bin/python terminated

Change Description

Arbitrary size of temp buffers One, Two, Three & Four in function NmOutput::fetchSymbols() is in some circumstances too small and buffer(s) overflow while processing line of data.

  1. Changes
  2. New function NmOutput::splitLine(line, vector_of_substrings) manages strings properly.
  3. Encapsulate One, Two, Three & Four into std::string objects for proper variable string length memory management.

Patch testing

Tested done by running stock LNT against my modification and comparison between output lnt profile files (size, md5).

Diff Detail

Event Timeline

PrzemekWirkus created this revision.May 4 2018, 8:12 AM

Small curly braces indent issue fixed (consistent coding style)

PrzemekWirkus edited the summary of this revision. (Show Details)May 4 2018, 8:34 AM
cmatthews resigned from this revision.May 4 2018, 9:29 AM

I cam't provide any good feedback on cpp code, and we don't use this for Mac. @kristof.beyls or @MatzeB, any feedback?

kristof.beyls accepted this revision.May 7 2018, 3:10 AM

I hope that in the long run, we can get rid of this cPerf.cpp C++ implementation, and instead make use of "perf data convert --to-ctf" to convert perf.data files into a CTF format which should be easier to parse in python.
At the time this C++ implementation was added, the "perf data convert --to-ctf" functionality tended not to be compiled in to perf as distributed by the main linux distros.
Looking at a reason stack overflow issue about this suggests that the situation may not have changed much (https://stackoverflow.com/questions/43576997/building-perf-with-babeltrace-for-perf-to-ctf-conversion), hence we'll probably need this C++ implementation for some time to come.

The code changes look fine to me to fix the stack buffer overflow bug in the current implementation.

This revision is now accepted and ready to land.May 7 2018, 3:10 AM

@MatzeB Are you able to have a quick look at this patch please?

No feedback from my side, I#m not familiar with the profile code.

@MatzeB There is nothing perf specific in this code, just plain C++ to wrap buffers into containers.

@cmatthews Can we merge ?

This revision was automatically updated to reflect the committed changes.