]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/procutils: notice setuid() process ownership changes
authorSami Kerola <kerolasa@iki.fi>
Sun, 20 Apr 2014 09:36:05 +0000 (10:36 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sat, 26 Apr 2014 18:04:57 +0000 (19:04 +0100)
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>
lib/procutils.c

index 31b77ff35950550608f0d93bc2c9681e0e02e010..8da11e65ad26b2d1ef09329f51aea023f2a9a9b2 100644 (file)
@@ -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;