Linux: update process uid on change

Always check if the user of a process changed, e.g. by using setuid(2).
This commit is contained in:
Christian Göttsche 2021-06-09 11:13:39 +02:00 committed by BenBE
parent faabbaa71e
commit 9114cf6ea3
2 changed files with 11 additions and 7 deletions

View File

@ -968,6 +968,7 @@ void Process_init(Process* this, const Settings* settings) {
this->show = true; this->show = true;
this->updated = false; this->updated = false;
this->cmdlineBasenameEnd = -1; this->cmdlineBasenameEnd = -1;
this->st_uid = (uid_t)-1;
if (Process_getuid == (uid_t)-1) { if (Process_getuid == (uid_t)-1) {
Process_getuid = getuid(); Process_getuid = getuid();

View File

@ -380,7 +380,7 @@ static bool LinuxProcessList_readStatFile(Process* process, openat_arg_t procFd,
} }
static bool LinuxProcessList_statProcessDir(Process* process, openat_arg_t procFd) { static bool LinuxProcessList_updateUser(ProcessList* processList, Process* process, openat_arg_t procFd) {
struct stat sstat; struct stat sstat;
#ifdef HAVE_OPENAT #ifdef HAVE_OPENAT
int statok = fstat(procFd, &sstat); int statok = fstat(procFd, &sstat);
@ -389,7 +389,12 @@ static bool LinuxProcessList_statProcessDir(Process* process, openat_arg_t procF
#endif #endif
if (statok == -1) if (statok == -1)
return false; return false;
if (process->st_uid != sstat.st_uid) {
process->st_uid = sstat.st_uid; process->st_uid = sstat.st_uid;
process->user = UsersTable_getRef(processList->usersTable, sstat.st_uid);
}
return true; return true;
} }
@ -1402,12 +1407,10 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
proc->percent_cpu = CLAMP(percent_cpu, 0.0F, cpus * 100.0F); proc->percent_cpu = CLAMP(percent_cpu, 0.0F, cpus * 100.0F);
proc->percent_mem = proc->m_resident / (double)(pl->totalMem) * 100.0; proc->percent_mem = proc->m_resident / (double)(pl->totalMem) * 100.0;
if (!preExisting) { if (! LinuxProcessList_updateUser(pl, proc, procFd))
if (! LinuxProcessList_statProcessDir(proc, procFd))
goto errorReadingProcess; goto errorReadingProcess;
proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid); if (!preExisting) {
#ifdef HAVE_OPENVZ #ifdef HAVE_OPENVZ
if (settings->flags & PROCESS_FLAG_LINUX_OPENVZ) { if (settings->flags & PROCESS_FLAG_LINUX_OPENVZ) {