|
|
760e82 |
From bba566504901b2c07885ecf325829875a96381a7 Mon Sep 17 00:00:00 2001
|
|
|
760e82 |
From: =?UTF-8?q?=C3=81kos=20Uzonyi?= <uzonyi.akos@gmail.com>
|
|
|
760e82 |
Date: Tue, 30 Jun 2020 17:20:12 +0200
|
|
|
760e82 |
Subject: [PATCH 136/138] Use get_proc_pid for /proc paths
|
|
|
760e82 |
|
|
|
760e82 |
* mmap_cache.c (mmap_cache_rebuild_if_invalid): Use proc pid instead of
|
|
|
760e82 |
tcp->pid for /proc path.
|
|
|
760e82 |
* util.c (getfdproto): Likewise.
|
|
|
760e82 |
(pidfd_get_pid): Likewise.
|
|
|
760e82 |
* pathtrace.c (getfdpath_pid): Likewise.
|
|
|
760e82 |
* strace.c (attach_tcb): Likewise.
|
|
|
760e82 |
---
|
|
|
760e82 |
mmap_cache.c | 2 +-
|
|
|
760e82 |
pathtrace.c | 7 ++++++-
|
|
|
760e82 |
strace.c | 2 +-
|
|
|
760e82 |
util.c | 9 +++++++--
|
|
|
760e82 |
4 files changed, 15 insertions(+), 5 deletions(-)
|
|
|
760e82 |
|
|
|
760e82 |
diff --git a/mmap_cache.c b/mmap_cache.c
|
|
|
760e82 |
index 89c6225..9825df2 100644
|
|
|
760e82 |
--- a/mmap_cache.c
|
|
|
760e82 |
+++ b/mmap_cache.c
|
|
|
760e82 |
@@ -84,7 +84,7 @@ mmap_cache_rebuild_if_invalid(struct tcb *tcp, const char *caller)
|
|
|
760e82 |
return MMAP_CACHE_REBUILD_READY;
|
|
|
760e82 |
|
|
|
760e82 |
char filename[sizeof("/proc/4294967296/maps")];
|
|
|
760e82 |
- xsprintf(filename, "/proc/%u/maps", tcp->pid);
|
|
|
760e82 |
+ xsprintf(filename, "/proc/%u/maps", get_proc_pid(tcp));
|
|
|
760e82 |
|
|
|
760e82 |
FILE *fp = fopen_stream(filename, "r");
|
|
|
760e82 |
if (!fp) {
|
|
|
760e82 |
diff --git a/pathtrace.c b/pathtrace.c
|
|
|
760e82 |
index f85cf14..87dc64b 100644
|
|
|
760e82 |
--- a/pathtrace.c
|
|
|
760e82 |
+++ b/pathtrace.c
|
|
|
760e82 |
@@ -87,7 +87,12 @@ getfdpath_pid(pid_t pid, int fd, char *buf, unsigned bufsize)
|
|
|
760e82 |
if (fd < 0)
|
|
|
760e82 |
return -1;
|
|
|
760e82 |
|
|
|
760e82 |
- xsprintf(linkpath, "/proc/%u/fd/%u", pid, fd);
|
|
|
760e82 |
+ int proc_pid = 0;
|
|
|
760e82 |
+ translate_pid(NULL, pid, PT_TID, &proc_pid);
|
|
|
760e82 |
+ if (!proc_pid)
|
|
|
760e82 |
+ return -1;
|
|
|
760e82 |
+
|
|
|
760e82 |
+ xsprintf(linkpath, "/proc/%u/fd/%u", proc_pid, fd);
|
|
|
760e82 |
n = readlink(linkpath, buf, bufsize - 1);
|
|
|
760e82 |
/*
|
|
|
760e82 |
* NB: if buf is too small, readlink doesn't fail,
|
|
|
760e82 |
diff --git a/strace.c b/strace.c
|
|
|
760e82 |
index 249533e..ef23f08 100644
|
|
|
760e82 |
--- a/strace.c
|
|
|
760e82 |
+++ b/strace.c
|
|
|
760e82 |
@@ -1196,7 +1196,7 @@ attach_tcb(struct tcb *const tcp)
|
|
|
760e82 |
unsigned int ntid = 0, nerr = 0;
|
|
|
760e82 |
|
|
|
760e82 |
if (followfork && tcp->pid != strace_child &&
|
|
|
760e82 |
- xsprintf(procdir, task_path, tcp->pid) > 0 &&
|
|
|
760e82 |
+ xsprintf(procdir, task_path, get_proc_pid(tcp)) > 0 &&
|
|
|
760e82 |
(dir = opendir(procdir)) != NULL) {
|
|
|
760e82 |
struct_dirent *de;
|
|
|
760e82 |
|
|
|
760e82 |
diff --git a/util.c b/util.c
|
|
|
760e82 |
index 2568021..481144b 100644
|
|
|
760e82 |
--- a/util.c
|
|
|
760e82 |
+++ b/util.c
|
|
|
760e82 |
@@ -501,7 +501,7 @@ getfdproto(struct tcb *tcp, int fd)
|
|
|
760e82 |
if (fd < 0)
|
|
|
760e82 |
return SOCK_PROTO_UNKNOWN;
|
|
|
760e82 |
|
|
|
760e82 |
- xsprintf(path, "/proc/%u/fd/%u", tcp->pid, fd);
|
|
|
760e82 |
+ xsprintf(path, "/proc/%u/fd/%u", get_proc_pid(tcp), fd);
|
|
|
760e82 |
r = getxattr(path, "system.sockprotoname", buf, bufsize - 1);
|
|
|
760e82 |
if (r <= 0)
|
|
|
760e82 |
return SOCK_PROTO_UNKNOWN;
|
|
|
760e82 |
@@ -582,8 +582,13 @@ printdev(struct tcb *tcp, int fd, const char *path)
|
|
|
760e82 |
pid_t
|
|
|
760e82 |
pidfd_get_pid(pid_t pid_of_fd, int fd)
|
|
|
760e82 |
{
|
|
|
760e82 |
+ int proc_pid = 0;
|
|
|
760e82 |
+ translate_pid(NULL, pid_of_fd, PT_TID, &proc_pid);
|
|
|
760e82 |
+ if (!proc_pid)
|
|
|
760e82 |
+ return -1;
|
|
|
760e82 |
+
|
|
|
760e82 |
char fdi_path[sizeof("/proc/%u/fdinfo/%u") + 2 * sizeof(int) * 3];
|
|
|
760e82 |
- xsprintf(fdi_path, "/proc/%u/fdinfo/%u", pid_of_fd, fd);
|
|
|
760e82 |
+ xsprintf(fdi_path, "/proc/%u/fdinfo/%u", proc_pid, fd);
|
|
|
760e82 |
|
|
|
760e82 |
FILE *f = fopen_stream(fdi_path, "r");
|
|
|
760e82 |
if (!f)
|
|
|
760e82 |
--
|
|
|
760e82 |
2.1.4
|
|
|
760e82 |
|