Skip to contentSkip to conversation

dtprobed: use /proc/$pid/map_files, not the filename of the mapping

PATCH In review Nick Alcock 2 participants 2 messages Feb 12

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 dtprobed: use /proc/$pid/map_files, not the filename of the mapping

From: Eugene Loh <[email protected]>

Instead of using prf->prf_mapname (which resolves to the mapped file's target), use Pmap_mapfile_name() to get the actual /proc/$pid/map_files/* path. These magic symlinks can be opened even when their corresponding files are deleted or in an inaccessible filesystem namespace, ensuring we can read the mapping contents reliably. DTrace already does this to read mappings during USDT probe lookup.

(We still use prf->prf_mapname to determine the module name used in the dof helper, and thus ultimately in the probespec, because that should be an actual user-readable module name, not some random address-space-like
filename: it doesn't matter that that name might not exist on the filesystem. Thanks to Eugene Loh for spotting this and Kris van Hees for fixing it.)

Fixes issues with probes in paths like /home when dtprobed is sandboxed by systemd.

Tested on both systemd and non-systemd (non-jailed) systems, with USDT programs running out of /tmp, /usr/local and /home.

---
 dtprobed/dtprobed.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
dtprobed/dtprobed.c +4 -3
index a808586559d96..34349deb028be 100644
@@ -487,16 +487,17 @@ handle_usdt_notes(pid_t pid, uintptr_t addr)
 		fuse_log(FUSE_LOG_ERR, "%i: dtprobed: cannot look up mapping (process dead?)\n",
 			 pid);
 		goto out;
-	} else if ((fn = prf->prf_mapname) == NULL) {
+	} else if (prf->prf_mapname == NULL ||
+		   (fn = Pmap_mapfile_name(P, mapp)) == NULL) {
 		fuse_log(FUSE_LOG_ERR, "%i: dtprobed: cannot look up mapname (process dead?)\n",
 			 pid);
 		goto out;
 	}
-	mod = strrchr(fn, '/');
+	mod = strrchr(prf->prf_mapname, '/');
 	if (mod)
 		mod++;
 	else
-		mod = fn;
+		mod = prf->prf_mapname;
 	snprintf(dh.dofhp_mod, sizeof(dh.dofhp_mod), "%s", mod);
 
 	dh.dofhp_addr = mapp->pr_vaddr;

base-commit: 9abccde65bd924a5b63258eebb5210952709768d
prerequisite-patch-id: d178f9e04afa5cca97d93ef7659a72dff6d364b6

Signature · 1 line
2.53.0.286.g870d7528e3
Reviewed-by on v3 1/1
#1 lore raw
Quoted 17 lines · Nick Alcock

From: Eugene Loh <[email protected]>

Instead of using prf->prf_mapname (which resolves to the mapped file's target), use Pmap_mapfile_name() to get the actual /proc/$pid/map_files/* path. These magic symlinks can be opened even when their corresponding files are deleted or in an inaccessible filesystem namespace, ensuring we can read the mapping contents reliably. DTrace already does this to read mappings during USDT probe lookup.

(We still use prf->prf_mapname to determine the module name used in the dof helper, and thus ultimately in the probespec, because that should be an actual user-readable module name, not some random address-space-like
filename: it doesn't matter that that name might not exist on the filesystem. Thanks to Eugene Loh for spotting this and Kris van Hees for fixing it.)

Quoted 7 lines

Fixes issues with probes in paths like /home when dtprobed is sandboxed by systemd.

Tested on both systemd and non-systemd (non-jailed) systems, with USDT programs running out of /tmp, /usr/local and /home.

Quoted 35 lines
---
 dtprobed/dtprobed.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
dtprobed/dtprobed.c +4 -3
index a808586559d96..34349deb028be 100644
@@ -487,16 +487,17 @@ handle_usdt_notes(pid_t pid, uintptr_t addr)
 		fuse_log(FUSE_LOG_ERR, "%i: dtprobed: cannot look up mapping (process dead?)\n",
 			 pid);
 		goto out;
-	} else if ((fn = prf->prf_mapname) == NULL) {
+	} else if (prf->prf_mapname == NULL ||
+		   (fn = Pmap_mapfile_name(P, mapp)) == NULL) {
 		fuse_log(FUSE_LOG_ERR, "%i: dtprobed: cannot look up mapname (process dead?)\n",
 			 pid);
 		goto out;
 	}
-	mod = strrchr(fn, '/');
+	mod = strrchr(prf->prf_mapname, '/');
 	if (mod)
 		mod++;
 	else
-		mod = fn;
+		mod = prf->prf_mapname;
 	snprintf(dh.dofhp_mod, sizeof(dh.dofhp_mod), "%s", mod);
 
 	dh.dofhp_addr = mapp->pr_vaddr;

base-commit: 9abccde65bd924a5b63258eebb5210952709768d
prerequisite-patch-id: d178f9e04afa5cca97d93ef7659a72dff6d364b6

Signature · 1 line
2.53.0.286.g870d7528e3