rc_find_pids: ignore pids that are not in our pid namespace
X-Gentoo-Bug: 634634 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=634634
This commit is contained in:
parent
fdce4769f2
commit
f5acc66db7
@ -80,9 +80,12 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
|
|||||||
DIR *procdir;
|
DIR *procdir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
int rc;
|
||||||
bool container_pid = false;
|
bool container_pid = false;
|
||||||
bool openvz_host = false;
|
bool openvz_host = false;
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
|
char my_ns[30];
|
||||||
|
char proc_ns[30];
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
pid_t p;
|
pid_t p;
|
||||||
char buffer[PATH_MAX];
|
char buffer[PATH_MAX];
|
||||||
@ -131,6 +134,14 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(my_ns, 0, sizeof(my_ns));
|
||||||
|
memset(proc_ns, 0, sizeof(proc_ns));
|
||||||
|
if (exists("/proc/self/ns/pid")) {
|
||||||
|
rc = readlink("/proc/self/ns/pid", my_ns, sizeof(my_ns));
|
||||||
|
if (rc <= 0)
|
||||||
|
my_ns[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
while ((entry = readdir(procdir)) != NULL) {
|
while ((entry = readdir(procdir)) != NULL) {
|
||||||
if (sscanf(entry->d_name, "%d", &p) != 1)
|
if (sscanf(entry->d_name, "%d", &p) != 1)
|
||||||
continue;
|
continue;
|
||||||
@ -138,6 +149,14 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
|
|||||||
continue;
|
continue;
|
||||||
if (pid != 0 && pid != p)
|
if (pid != 0 && pid != p)
|
||||||
continue;
|
continue;
|
||||||
|
snprintf(buffer, sizeof(buffer), "/proc/%d/ns/pid", p);
|
||||||
|
if (exists(buffer)) {
|
||||||
|
rc = readlink(buffer, proc_ns, sizeof(proc_ns));
|
||||||
|
if (rc <= 0)
|
||||||
|
proc_ns[0] = '\0';
|
||||||
|
}
|
||||||
|
if (strcmp(my_ns, proc_ns))
|
||||||
|
continue;
|
||||||
if (uid) {
|
if (uid) {
|
||||||
snprintf(buffer, sizeof(buffer), "/proc/%d", p);
|
snprintf(buffer, sizeof(buffer), "/proc/%d", p);
|
||||||
if (stat(buffer, &sb) != 0 || sb.st_uid != uid)
|
if (stat(buffer, &sb) != 0 || sb.st_uid != uid)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user