aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/comproot.c2
-rw-r--r--src/file.c4
-rw-r--r--src/file.h2
-rw-r--r--src/handlers/handle_chown.c6
-rw-r--r--src/handlers/handle_stat.c4
-rw-r--r--src/util.c21
-rw-r--r--src/util.h4
7 files changed, 22 insertions, 21 deletions
diff --git a/src/comproot.c b/src/comproot.c
index 1223ff7..58d4e12 100644
--- a/src/comproot.c
+++ b/src/comproot.c
@@ -46,7 +46,7 @@ static void new_notification(short revents, int notifyfd) {
if (rc < 0 || rc >= PATH_MAX)
ERR(3, "snprintf(\"/proc/%%jd\") = %d", rc);
procfd = open(procpath, O_CLOEXEC|O_DIRECTORY|O_PATH);
- if (seccomp_notify_id_valid(notifyfd, req->id) || procfd == -1) {
+ if (seccomp_notify_id_valid(notifyfd, req->id) || procfd == -1 || fchdir(procfd) == -1) {
PWARNX(req->pid, "died during trace!");
goto out;
}
diff --git a/src/file.c b/src/file.c
index e4c2a3f..3084adb 100644
--- a/src/file.c
+++ b/src/file.c
@@ -89,10 +89,10 @@ int stat_upsert_path(struct stat *st, char *path, int follow) {
}
/* Same as the above but with a file descriptor. */
-int stat_upsert_fd(struct stat *st, pid_t pid, int fd) {
+int stat_upsert_fd(struct stat *st, int fd) {
char procpath[PATH_MAX];
- if (get_fd_path(pid, fd, procpath) == -1)
+ if (get_fd_path(fd, procpath) == -1)
return -1;
return stat_upsert_path(st, procpath, 0);
diff --git a/src/file.h b/src/file.h
index 0647724..ba32e67 100644
--- a/src/file.h
+++ b/src/file.h
@@ -21,7 +21,7 @@ struct file {
struct file *file_get(dev_t dev, ino_t ino);
int stat_upsert_path(struct stat *st, char *path, int follow);
-int stat_upsert_fd(struct stat *st, pid_t pid, int fd);
+int stat_upsert_fd(struct stat *st, int fd);
struct file *file_upsert_path(char *path, int follow);
diff --git a/src/handlers/handle_chown.c b/src/handlers/handle_chown.c
index 8f78ca9..69efcac 100644
--- a/src/handlers/handle_chown.c
+++ b/src/handlers/handle_chown.c
@@ -43,7 +43,7 @@ static void handle_chown_inner(char *syscall_name, HANDLER_ARGS, int follow) {
if (pathname[0] != '/') {
char procpath[PATH_MAX];
- if (chdir_to_fd(HANDLER_PID, AT_FDCWD, procpath))
+ if (chdir_to_fd(AT_FDCWD, procpath))
goto out;
}
@@ -71,7 +71,7 @@ DECL_HANDLER(fchown) {
PDBGX(HANDLER_PID, "fchown(%d, %d, %d)", fd, owner, group);
- if (get_fd_path(HANDLER_PID, fd, procpath) == -1)
+ if (get_fd_path(fd, procpath) == -1)
goto out;
rc = record_chown(procpath, owner, group, 0);
@@ -104,7 +104,7 @@ DECL_HANDLER(fchownat) {
}
char procpath[PATH_MAX] = {0};
- if (chdir_to_fd(HANDLER_PID, fd, procpath))
+ if (chdir_to_fd(fd, procpath))
goto out;
char *fullpath = 0;
diff --git a/src/handlers/handle_stat.c b/src/handlers/handle_stat.c
index f7ff466..71aee02 100644
--- a/src/handlers/handle_stat.c
+++ b/src/handlers/handle_stat.c
@@ -22,7 +22,7 @@ static void handle_stat_inner(char *syscall_name, HANDLER_ARGS, int follow) {
if (pathname[0] != '/') {
char procpath[PATH_MAX];
- if (chdir_to_fd(HANDLER_PID, AT_FDCWD, procpath))
+ if (chdir_to_fd(AT_FDCWD, procpath))
goto out;
}
@@ -53,7 +53,7 @@ DECL_HANDLER(fstat) {
int rc = -1;
- if (stat_upsert_fd(&statbuf, HANDLER_PID, fd) == -1)
+ if (stat_upsert_fd(&statbuf, fd) == -1)
goto out;
PDBGX(HANDLER_PID, "fstat(%d, "STAT_FMT")", fd, STAT_ARG(statbuf));
diff --git a/src/util.c b/src/util.c
index d16bb92..e1b7add 100644
--- a/src/util.c
+++ b/src/util.c
@@ -7,16 +7,17 @@
#include "comproot.h"
#include "util.h"
-int get_fd_path(pid_t pid, int fd, char procpath[PATH_MAX]) {
+int get_fd_path(int fd, char procpath[PATH_MAX]) {
int rc = -1;
errno = 0;
- if (fd == AT_FDCWD)
- rc = snprintf(procpath, PATH_MAX, "/proc/%jd/cwd", (intmax_t)pid);
- else
- rc = snprintf(procpath, PATH_MAX, "/proc/%jd/fd/%d", (intmax_t)pid, fd);
+ if (fd == AT_FDCWD) {
+ strcpy(procpath, "cwd");
+ rc = 0;
+ } else
+ rc = snprintf(procpath, PATH_MAX, "fd/%d", fd);
if (rc < 0 || rc >= PATH_MAX) {
- PWARN(pid, "snprintf(procpath) = %d", rc);
+ WARN("snprintf(\"fd/%%d\") = %d", rc);
errno = EIO;
return -1;
}
@@ -24,12 +25,12 @@ int get_fd_path(pid_t pid, int fd, char procpath[PATH_MAX]) {
return 0;
}
-int chdir_to_fd(pid_t pid, int fd, char procpath[PATH_MAX]) {
- if (get_fd_path(pid, fd, procpath) == -1)
+int chdir_to_fd(int fd, char procpath[PATH_MAX]) {
+ if (get_fd_path(fd, procpath) == -1)
return -1;
- if (chdir(procpath)) {
- PWARN(pid, "chdir(%s)", procpath);
+ if (chdir(procpath) == -1) {
+ WARN("chdir(procpath)");
return -1;
}
diff --git a/src/util.h b/src/util.h
index 651c803..ca2556b 100644
--- a/src/util.h
+++ b/src/util.h
@@ -6,8 +6,8 @@
#include "comproot.h"
-int get_fd_path(pid_t pid, int fd, char procpath[PATH_MAX]);
-int chdir_to_fd(pid_t pid, int fd, char procpath[PATH_MAX]);
+int get_fd_path(int fd, char procpath[PATH_MAX]);
+int chdir_to_fd(int fd, char procpath[PATH_MAX]);
int tx_data(A_HANDLER_PROC, void *buf, uint64_t addr, size_t len, int push);