Skip to content

Commit

Permalink
Log more info in an mprotect record mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
rocallahan committed Jan 2, 2024
1 parent d142cc9 commit 12398d3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
14 changes: 2 additions & 12 deletions src/DumpCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,8 @@ static void dump_syscallbuf_data(TraceReader& trace, FILE* out,
}
if (flags.dump_mmaps) {
for (auto& record : frame.event().SyscallbufFlush().mprotect_records) {
char prot_flags[] = "rwx";
if (!(record.prot & PROT_READ)) {
prot_flags[0] = '-';
}
if (!(record.prot & PROT_WRITE)) {
prot_flags[1] = '-';
}
if (!(record.prot & PROT_EXEC)) {
prot_flags[2] = '-';
}
fprintf(out, " { start:'%p', size:'%" PRIx64 "', prot:%s }\n",
(void*)record.start, record.size, prot_flags);
fprintf(out, " { start:%p, size:%" PRIx64 ", prot:'%s' }\n",
(void*)record.start, record.size, prot_flags_string(record.prot).c_str());
if (flags.raw_dump) {
fprintf(out, " ");
for (unsigned long i = 0; i < sizeof(record); ++i) {
Expand Down
12 changes: 10 additions & 2 deletions src/ReplaySession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,13 @@ void ReplaySession::prepare_syscallbuf_records(ReplayTask* t, Ticks ticks) {
REMOTE_PTR_FIELD_MINUS_OFFSET(t->preload_globals, f, \
SYSCALLBUF_FDS_DISABLED_SIZE - t->session().syscallbuf_fds_disabled_size())

static string mprotect_record_string(const mprotect_record& record) {
stringstream s;
s << HEX(record.start) << "," << HEX(record.size) << ","
<< prot_flags_string(record.prot);
return s.str();
}

/**
* Returns mprotect_record_count
*/
Expand Down Expand Up @@ -1315,8 +1322,9 @@ static uint32_t apply_mprotect_records(ReplayTask* t,
ASSERT(t, r.start == recorded_r.start &&
r.size == recorded_r.size &&
r.prot == recorded_r.prot)
<< "Trace mprotect records don't match the mprotect records "
"generated by execution";
<< "Mismatched mprotect record " << (i + skip_mprotect_records)
<< ": recorded " << mprotect_record_string(recorded_r)
<< ", got " << mprotect_record_string(r);
}
t->vm()->protect(t, r.start, r.size, r.prot);
if (running_under_rr()) {
Expand Down
21 changes: 21 additions & 0 deletions src/kernel_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <signal.h>
#include <syscall.h>

#include <sstream>

#include "kernel_abi.h"
#include "kernel_supplement.h"
#include "log.h"
Expand Down Expand Up @@ -560,4 +562,23 @@ NativeArch::siginfo_t convert_to_native_siginfo(SupportedArch arch,
RR_ARCH_FUNCTION(convert_to_native_siginfo_arch, arch, data, size);
}

string prot_flags_string(int prot) {
char prot_flags[] = "rwx";
if (!(prot & PROT_READ)) {
prot_flags[0] = '-';
}
if (!(prot & PROT_WRITE)) {
prot_flags[1] = '-';
}
if (!(prot & PROT_EXEC)) {
prot_flags[2] = '-';
}
stringstream ret;
ret << prot_flags;
if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) {
ret << " (" << HEX(prot) << ")";
}
return ret.str();
}

} // namespace rr
2 changes: 2 additions & 0 deletions src/kernel_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ bool is_coredumping_signal(int signo);
NativeArch::siginfo_t convert_to_native_siginfo(SupportedArch arch,
const void* data, size_t size);

std::string prot_flags_string(int prot);

} // namespace rr

#endif

0 comments on commit 12398d3

Please sign in to comment.