From 1786a9ac2b32d2259d765f54563657a2116eb792 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 20 Apr 2014 10:36:05 +0100 Subject: lib/procutils: notice setuid() process ownership changes Earlier the owner of a process was determined by owner of the /proc//stat file. When changes user ID privileges with setuid() the stat file ownership is not updated, that resulted kill(1) to consider such processes where running using same uid as the present process. Signed-off-by: Sami Kerola --- lib/procutils.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/procutils.c') diff --git a/lib/procutils.c b/lib/procutils.c index 31b77ff35..8da11e65a 100644 --- a/lib/procutils.c +++ b/lib/procutils.c @@ -151,13 +151,11 @@ int proc_next_pid(struct proc_processes *ps, pid_t *pid) if (!isdigit((unsigned char) *d->d_name)) continue; - snprintf(buf, sizeof(buf), "%s/stat", d->d_name); - /* filter out by UID */ if (ps->has_fltr_uid) { struct stat st; - if (fstat_at(dirfd(ps->dir), "/proc", buf, &st, 0)) + if (fstat_at(dirfd(ps->dir), "/proc", d->d_name, &st, 0)) continue; if (ps->fltr_uid != st.st_uid) continue; @@ -166,7 +164,10 @@ int proc_next_pid(struct proc_processes *ps, pid_t *pid) /* filter out by NAME */ if (ps->has_fltr_name) { char procname[256]; - FILE *f = fopen_at(dirfd(ps->dir), "/proc", buf, + FILE *f; + + snprintf(buf, sizeof(buf), "%s/stat", d->d_name); + f = fopen_at(dirfd(ps->dir), "/proc", buf, O_CLOEXEC|O_RDONLY, "r"); if (!f) continue; -- cgit v1.2.3-55-g7522