diff --git a/lib/get_pid.c b/lib/get_pid.c index 5b6d9da4..8e5e6014 100644 --- a/lib/get_pid.c +++ b/lib/get_pid.c @@ -41,6 +41,8 @@ int get_pidfd_from_fd(const char *pidfdstr) { long long int val; char *endptr; + struct stat st; + dev_t proc_st_dev, proc_st_rdev; errno = 0; val = strtoll (pidfdstr, &endptr, 10); @@ -51,6 +53,21 @@ int get_pidfd_from_fd(const char *pidfdstr) return -1; } + if (stat("/proc/self/uid_map", &st) < 0) { + return -1; + } + + proc_st_dev = st.st_dev; + proc_st_rdev = st.st_rdev; + + if (fstat(val, &st) < 0) { + return -1; + } + + if (st.st_dev != proc_st_dev || st.st_rdev != proc_st_rdev) { + return -1; + } + return (int)val; }