From: Sami Kerola Date: Sun, 20 Apr 2014 09:36:05 +0000 (+0100) Subject: lib/procutils: notice setuid() process ownership changes X-Git-Tag: v2.25-rc1~244^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1786a9ac2b32d2259d765f54563657a2116eb792;p=thirdparty%2Futil-linux.git 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 --- diff --git a/lib/procutils.c b/lib/procutils.c index 31b77ff359..8da11e65ad 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;