dtprobed: use /proc/$pid/map_files, not the filename of the mapping
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
@@ -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
Quoted 17 lines · Nick Alcock
From: Eugene Loh <[email protected]>
Instead of using
prf->prf_mapname(which resolves to the mapped file's target), usePmap_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_mapnameto 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/localand /home.Signed-off-by Nick Alcock <[email protected]>
Quoted 35 lines
--- dtprobed/dtprobed.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)dtprobed/dtprobed.c +4
-3@@ -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:d178f9e04afa5cca97d93ef7659a72dff6d364b6Signature · 1 line
2.53.0.286.g870d7528e3