crash: Include SECCOMP_POLICY_PATH env variable in the report.
For additional context see: https://r.android.com/1824238
BUG=b:199444797
TEST=FEATURES=test emerge-${BOARD} crash-reporter
TEST=tast run <host> crash.User*
TEST=/sbin/minijail0 -S /dev/null /bin/true # and verify the crash.
Change-Id: I742239b903310cdc942f8fd62668ddd0f1f111aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/3154982
Tested-by: Allen Webb <allenwebb@google.com>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: Miriam Zimmerman <mutexlox@chromium.org>
Commit-Queue: Allen Webb <allenwebb@google.com>
diff --git a/crash-reporter/crash_collector.cc b/crash-reporter/crash_collector.cc
index 73f0437..cab4eb7 100644
--- a/crash-reporter/crash_collector.cc
+++ b/crash-reporter/crash_collector.cc
@@ -81,6 +81,10 @@
// Key of the lsb-release entry containing the channel.
const char kLsbChannelKey[] = "CHROMEOS_RELEASE_TRACK";
+// Environment variable set by minijail that includes the path to a seccomp
+// policy if one is defined.
+constexpr char kEnvSecompPolicyPath[] = "SECCOMP_POLICY_PATH";
+
#if !USE_KVM_GUEST
// Directory mode of the user crash spool directory.
// This is SGID so that files created in it are also accessible to the group.
@@ -1211,7 +1215,22 @@
// Read the status file and append it to the log.
if (!base::ReadFileToString(proc_path.Append("status"), &contents))
break;
- stream << contents << std::endl;
+ stream << contents;
+
+ // Include values of interest from the environment.
+ if (!base::ReadFileToString(proc_path.Append("environ"), &contents))
+ break;
+ base::StringPairs environ;
+ if (base::SplitStringIntoKeyValuePairs(contents, '=', '\0', &environ)) {
+ for (const auto& key_value : environ) {
+ if (key_value.first == kEnvSecompPolicyPath) {
+ stream << kEnvSecompPolicyPath << '=' << key_value.second
+ << std::endl;
+ break;
+ }
+ }
+ }
+ stream << std::endl;
// Pull out the parent pid from the status file. The line will look like:
// PPid:\t1234