summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Lisov <dennis.lissov@gmail.com>2022-02-14 00:32:28 +0300
committerBenBE <BenBE@geshi.org>2022-05-05 10:00:34 +0200
commite07fce701433f79f925eef66508d1ada53ce5d53 (patch)
tree214231ba618877a8f5448a30e2e640c360192658
parente08eec813cb0a5fa8ff3f2d5b57cc62ccc265b78 (diff)
LinuxProcessList_recurseProcTree: open dirfd first
A process can die between reading the directory listing and opening the directory FD (if HAVE_OPENAT) or /proc files (otherwise) for reading the process data. This race would cause LinuxProcessList_recurseProcTree to remove it from the list immediately, which is unexpected in the "highlight dying processes" mode and can break the tree structure. This patch closes this race in the HAVE_OPENAT case by only accessing the process entry after the directory FD has been opened.
-rw-r--r--linux/LinuxProcessList.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index e23af209..0d4be558 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -1446,22 +1446,22 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
if (parent && pid == parent->pid)
continue;
- bool preExisting;
- Process* proc = ProcessList_getProcess(pl, pid, &preExisting, LinuxProcess_new);
- LinuxProcess* lp = (LinuxProcess*) proc;
-
- proc->tgid = parent ? parent->pid : pid;
- proc->isUserlandThread = proc->pid != proc->tgid;
-
#ifdef HAVE_OPENAT
int procFd = openat(dirFd, entry->d_name, O_RDONLY | O_DIRECTORY | O_NOFOLLOW);
if (procFd < 0)
- goto errorReadingProcess;
+ continue;
#else
char procFd[4096];
xSnprintf(procFd, sizeof(procFd), "%s/%s", dirFd, entry->d_name);
#endif
+ bool preExisting;
+ Process* proc = ProcessList_getProcess(pl, pid, &preExisting, LinuxProcess_new);
+ LinuxProcess* lp = (LinuxProcess*) proc;
+
+ proc->tgid = parent ? parent->pid : pid;
+ proc->isUserlandThread = proc->pid != proc->tgid;
+
LinuxProcessList_recurseProcTree(this, procFd, "task", proc, period);
/*

© 2014-2024 Faster IT GmbH | imprint | privacy policy