[PATCH 5/7] util.c: pidfd_get_pid: check if pidfd refers to a non visible process

Ákos Uzonyi uzonyi.akos at gmail.com
Wed Apr 22 18:06:22 UTC 2020


If pidfd refers to a process not visible from our namespace, reading its
fdinfo file gives PID not in our namespace, which is wrong.

* util.c (pidfd_get_pid): check if referred process is visible from our
namespace, by sending a no-op signal to it

Signed-off-by: Uzonyi Ákos <uzonyi.akos at gmail.com>
---
 util.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/util.c b/util.c
index d18ebead..4a95d052 100644
--- a/util.c
+++ b/util.c
@@ -26,6 +26,7 @@
 #include "largefile_wrappers.h"
 #include "number_set.h"
 #include "print_utils.h"
+#include "scno.h"
 #include "static_assert.h"
 #include "string_to_uint.h"
 #include "xlat.h"
@@ -570,6 +571,11 @@ printdev(struct tcb *tcp, int fd, const char *path)
 pid_t
 pidfd_get_pid(pid_t pid_of_fd, int fd)
 {
+	/* send no-op signal, to check if the referred process is visible from our namespace */
+	if (syscall(__NR_pidfd_send_signal, fd, 0, NULL, 0) < 0)
+		if (errno == EINVAL)
+			return -1;
+
 	char fdi_path[sizeof("/proc/%u/fdinfo/%u") + 2 * sizeof(int) * 3];
 	xsprintf(fdi_path, "/proc/%u/fdinfo/%u", pid_of_fd, fd);
 
-- 
2.26.1



More information about the Strace-devel mailing list