Skip to content

Commit e3619ba

Browse files
Kenoclaude
authored andcommitted
Fix --check-outside-mmaps on btrfs
check_outside_mappings() compared the device number from fstat() with the device numbers in other processes' /proc/<pid>/maps. On btrfs these differ (fstat() reports the subvolume's device), so no outside mapping ever matched and mmap_shared_extern failed. Compare with the tracee's own /proc/<tid>/maps entry for the new mapping instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent aa89a94 commit e3619ba

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎src/AddressSpace.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,8 @@ class AddressSpace : public HasTaskSet {
818818

819819
/**
820820
* Reads the /proc/<pid>/maps entry for a specific address. Does no caching.
821-
* If performed on a file in a btrfs file system, this may return the
822-
* wrong device number! If you stick to anonymous or special file
823-
* mappings, this should be OK.
821+
* For a file on btrfs, the device number is the filesystem's, while
822+
* fstat() reports the subvolume's (see KernelMapping::device_).
824823
*/
825824
KernelMapping read_kernel_mapping(Task* t, remote_ptr<void> addr);
826825

‎src/record_syscall.cc‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6736,7 +6736,7 @@ static vector<WriteHole> find_holes(RecordTask* t, int desc, uint64_t offset, ui
67366736
return ret;
67376737
}
67386738

6739-
static void check_outside_mappings(const KernelMapping& tracee_km, const RecordSession& session) {
6739+
static void check_outside_mappings(RecordTask* t, remote_ptr<void> addr) {
67406740
#if defined(__i386__)
67416741
struct utsname buf;
67426742
if (uname(&buf) != 0) {
@@ -6748,6 +6748,16 @@ static void check_outside_mappings(const KernelMapping& tracee_km, const RecordS
67486748
FATAL() << "Cannot use --check_outside_mmaps with 32-bit rr at 64-bit kernel.";
67496749
}
67506750
#endif
6751+
// On btrfs, /proc/<pid>/maps shows a different device number than fstat()
6752+
// (see KernelMapping::device_), so compare the other processes' entries
6753+
// with the tracee's own /proc/<tid>/maps entry.
6754+
KernelMapping tracee_km = t->vm()->read_kernel_mapping(t, addr);
6755+
if (tracee_km.inode() == KernelMapping::NO_INODE) {
6756+
// No entry for addr (the tracee is gone). An empty entry would match
6757+
// every anonymous mapping.
6758+
return;
6759+
}
6760+
const RecordSession& session = t->session();
67516761
DIR* proc = opendir("/proc");
67526762
if (!proc) {
67536763
FATAL() << "Failed to read /proc";
@@ -6904,7 +6914,7 @@ static void process_mmap(RecordTask* t, size_t length, int prot, int flags,
69046914
}
69056915

69066916
if (t->session().check_outside_mmaps()) {
6907-
check_outside_mappings(km, t->session());
6917+
check_outside_mappings(t, addr);
69086918
}
69096919
}
69106920

0 commit comments

Comments
 (0)