diff --git a/infra/experimental/SystemSan/SystemSan.cpp b/infra/experimental/SystemSan/SystemSan.cpp index 4fdd6c12c..9836b8fde 100644 --- a/infra/experimental/SystemSan/SystemSan.cpp +++ b/infra/experimental/SystemSan/SystemSan.cpp @@ -30,6 +30,7 @@ /* Linux */ #include #include +#include #include #include @@ -272,6 +273,25 @@ void inspect_for_corruption(pid_t pid, const user_regs_struct ®s) { match_error_pattern(buffer, g_shell_pids[pid]); } +void log_file_open(std::string path, int flags) { + report_bug(kArbitraryFileOpenError); + std::cerr << "===File opened: " << path << ", flags = " << flags << ","; + switch (flags & 3) { + case O_RDONLY: + std::cerr << "O_RDONLY"; + break; + case O_WRONLY: + std::cerr << "O_WRONLY"; + break; + case O_RDWR: + std::cerr << "O_RDWR"; + break; + default: + std::cerr << "unknown"; + } + std::cerr << "===\n"; +} + void inspect_for_arbitrary_file_open(pid_t pid, const user_regs_struct ®s) { // Inspect a PID's register for the sign of arbitrary file open. std::string path = read_string(pid, regs.rsi, kRootDirMaxLength); @@ -279,7 +299,8 @@ void inspect_for_arbitrary_file_open(pid_t pid, const user_regs_struct ®s) { return; } if (path.substr(0, kFzAbsoluteDirectory.length()) == kFzAbsoluteDirectory) { - report_bug(kArbitraryFileOpenError); + log_file_open(path, regs.rdx); + return; } if (path[0] == '/' && path.length() > 1) { std::string path_absolute_topdir = path; @@ -289,7 +310,7 @@ void inspect_for_arbitrary_file_open(pid_t pid, const user_regs_struct ®s) { } struct stat dirstat; if (stat(path_absolute_topdir.c_str(), &dirstat) != 0) { - report_bug(kArbitraryFileOpenError); + log_file_open(path, regs.rdx); } } }