diff options
author | Sami Kerola | 2014-04-20 11:36:05 +0200 |
---|---|---|
committer | Sami Kerola | 2014-04-26 20:04:57 +0200 |
commit | 1786a9ac2b32d2259d765f54563657a2116eb792 (patch) | |
tree | c855cb92a391d925975e72b162af01bd1e6c60f0 /lib/procutils.c | |
parent | lib/procutils: reset errno before strtol() call (diff) | |
download | kernel-qcow2-util-linux-1786a9ac2b32d2259d765f54563657a2116eb792.tar.gz kernel-qcow2-util-linux-1786a9ac2b32d2259d765f54563657a2116eb792.tar.xz kernel-qcow2-util-linux-1786a9ac2b32d2259d765f54563657a2116eb792.zip |
lib/procutils: notice setuid() process ownership changes
Earlier the owner of a process was determined by owner of the
/proc/<pid>/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 <kerolasa@iki.fi>
Diffstat (limited to 'lib/procutils.c')
-rw-r--r-- | lib/procutils.c | 9 |
1 files changed, 5 insertions, 4 deletions
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; |