aboutsummaryrefslogtreecommitdiffstats
path: root/executor/common_linux.h
diff options
context:
space:
mode:
Diffstat (limited to 'executor/common_linux.h')
-rw-r--r--executor/common_linux.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/executor/common_linux.h b/executor/common_linux.h
index f887551cc..13014e33e 100644
--- a/executor/common_linux.h
+++ b/executor/common_linux.h
@@ -77,9 +77,10 @@
#include <stdio.h>
#include <sys/stat.h>
#endif
-#if defined(SYZ_EXECUTOR) || defined(__NR_syz_open_dev)
+#if defined(SYZ_EXECUTOR) || defined(__NR_syz_open_dev) || defined(__NR_syz_open_procfs)
#include <fcntl.h>
#include <stdio.h>
+#include <string.h>
#include <sys/stat.h>
#endif
#if defined(SYZ_EXECUTOR) || defined(__NR_syz_fuse_mount) || defined(__NR_syz_fuseblk_mount)
@@ -561,6 +562,27 @@ static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2)
}
#endif
+#if defined(SYZ_EXECUTOR) || defined(__NR_syz_open_procfs)
+static uintptr_t syz_open_procfs(uintptr_t a0, uintptr_t a1)
+{
+ // syz_open_procfs(pid pid, file ptr[in, string[procfs_file]]) fd
+
+ char buf[128];
+ memset(buf, 0, sizeof(buf));
+ if (a0 == 0) {
+ NONFAILING(snprintf(buf, sizeof(buf), "/proc/self/%s", (char*)a1));
+ } else if (a0 == (uintptr_t)-1) {
+ NONFAILING(snprintf(buf, sizeof(buf), "/proc/thread-self/%s", (char*)a1));
+ } else {
+ NONFAILING(snprintf(buf, sizeof(buf), "/proc/self/task/%d/%s", (int)a0, (char*)a1));
+ }
+ int fd = open(buf, O_RDWR);
+ if (fd == -1)
+ fd = open(buf, O_RDONLY);
+ return fd;
+}
+#endif
+
#if defined(SYZ_EXECUTOR) || defined(__NR_syz_open_pts)
static uintptr_t syz_open_pts(uintptr_t a0, uintptr_t a1)
{