Skip to content

Commit bc00a39

Browse files
kext: source stat memory/threads/state from daemon proc_taskinfo
procfs_pctx_get read vsize/rss via a VM-map walk and thread count via a thread walk, both of which need task_for_pid and so returned 0 for the SIP/hardened processes whose task port is denied — ps aux showed VSZ, RSS and thread counts of 0 for most processes. Take these from the daemon's proc_taskinfo (proc_pidinfo, no task port) instead, and refine the coarse BSD p_stat into Linux's running/sleeping split via the count of running threads so idle processes read 'S'. Falls back to the in-kernel walk when no daemon is connected. Fixes stat, statm, status and status_linux together.
1 parent 462de30 commit bc00a39

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

kext/procfs_linux.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,10 +1744,31 @@ procfs_pctx_get(pfsnode_t *pnp, struct procfs_pctx *c)
17441744
c->ppid = proc_ppid(p);
17451745
c->pgid = proc_pgrpid(p);
17461746
c->sid = proc_sessionid(p);
1747-
c->nthreads = procfs_get_task_thread_count(p);
17481747
c->state = procfs_proc_state(p->p_stat);
17491748

1750-
(void)procfs_task_vm_sizes(p, &c->vsize, &c->rsize);
1749+
/*
1750+
* Memory sizes and thread count come from the daemon's proc_taskinfo
1751+
* (proc_pidinfo, which needs no task port). The in-kernel alternatives -
1752+
* the VM-map walk in procfs_task_vm_sizes and procfs_get_task_thread_count -
1753+
* go through task_for_pid, so they return 0 for the SIP/hardened processes
1754+
* whose task port is denied; we fall back to them only when no daemon is
1755+
* connected. proc_taskinfo also reports the number of running threads, which
1756+
* refines the coarse BSD p_stat (almost always SRUN) into Linux's
1757+
* running/sleeping split the way ps and top do - so an idle daemon reports
1758+
* 'S', not 'R'. Zombie/stopped/idle states from p_stat are left as-is.
1759+
*/
1760+
struct proc_taskinfo ti;
1761+
if (procfs_task_info(pnp, &ti) == 0) {
1762+
c->vsize = ti.pti_virtual_size;
1763+
c->rsize = ti.pti_resident_size;
1764+
c->nthreads = ti.pti_threadnum;
1765+
if (c->state == 'R' && ti.pti_numrunning == 0) {
1766+
c->state = 'S';
1767+
}
1768+
} else {
1769+
c->nthreads = procfs_get_task_thread_count(p);
1770+
(void)procfs_task_vm_sizes(p, &c->vsize, &c->rsize);
1771+
}
17511772

17521773
proc_name(c->pid, c->comm, sizeof(c->comm));
17531774
proc_rele(p);

0 commit comments

Comments
 (0)