diff options
author | Yabin Cui <yabinc@google.com> | 2016-07-08 11:27:48 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2016-07-12 13:52:51 -0700 |
commit | af69895fec14e33be1ac0af31d62ca87844a89b3 (patch) | |
tree | 3a114a103c3182289798e15664b6b203acee15ab | |
parent | 78f176baafaffbe5192b7565c4e7d68ce998e731 (diff) | |
download | extras-af69895fec14e33be1ac0af31d62ca87844a89b3.tar.gz |
simpleperf: check kernel symbol addresses before dumping them.
If kernel symbols have zero addresses, there is no need to dump them,
and we can give useful suggestion.
Bug: 29574526
Test: manually set /proc/sys/kernel/kptr_restrict and run simpleperf record.
Change-Id: I850531c7e4c5315a44e08cf3b73852e77fef8eb8
-rw-r--r-- | simpleperf/cmd_record.cpp | 2 | ||||
-rw-r--r-- | simpleperf/environment.cpp | 25 | ||||
-rw-r--r-- | simpleperf/environment.h | 1 |
3 files changed, 27 insertions, 1 deletions
diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp index a7988173..1d283fc0 100644 --- a/simpleperf/cmd_record.cpp +++ b/simpleperf/cmd_record.cpp @@ -643,7 +643,7 @@ bool RecordCommand::DumpKernelSymbol() { } } } - if (need_kernel_symbol) { + if (need_kernel_symbol && CheckKernelSymbolAddresses()) { if (!android::base::ReadFileToString("/proc/kallsyms", &kallsyms)) { PLOG(ERROR) << "failed to read /proc/kallsyms"; return false; diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp index 0024f961..f0203cfe 100644 --- a/simpleperf/environment.cpp +++ b/simpleperf/environment.cpp @@ -477,3 +477,28 @@ bool CheckSampleFrequency(uint64_t sample_freq) { } return true; } + +bool CheckKernelSymbolAddresses() { + const std::string kptr_restrict_file = "/proc/sys/kernel/kptr_restrict"; + std::string s; + if (!android::base::ReadFileToString(kptr_restrict_file, &s)) { + PLOG(WARNING) << "failed to read " << kptr_restrict_file; + return false; + } + s = android::base::Trim(s); + int value; + if (!android::base::ParseInt(s.c_str(), &value)) { + LOG(ERROR) << "failed to parse " << kptr_restrict_file << ": " << s; + return false; + } + if (value == 0) { + return true; + } + if (value == 1 && IsRoot()) { + return true; + } + LOG(WARNING) << "Access to kernel symbol addresses is restricted. If " + << "possible, please do `echo 0 >/proc/sys/kernel/kptr_restrict` " + << "to fix this."; + return false; +} diff --git a/simpleperf/environment.h b/simpleperf/environment.h index 7c0e279b..2f0f59c7 100644 --- a/simpleperf/environment.h +++ b/simpleperf/environment.h @@ -71,5 +71,6 @@ bool GetExecPath(std::string* exec_path); bool CheckPerfEventLimit(); bool CheckSampleFrequency(uint64_t sample_freq); +bool CheckKernelSymbolAddresses(); #endif // SIMPLE_PERF_ENVIRONMENT_H_ |