]> granicus.if.org Git - procps-ng/commitdiff
library: eliminate insidious 'LIBPROC_HIDE_KERNEL' bug
authorJim Warner <james.warner@comcast.net>
Sun, 1 May 2022 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Tue, 3 May 2022 09:21:21 +0000 (19:21 +1000)
When support for the 'LIBPROC_HIDE_KERNEL' environment
variable was introduced, a deficiency was present that
allowed any rejected proc_t (i.e. a kworker thread) to
preserve the strdup'd 'cmd' value. That residual value
would prevent stat2proc or status2proc from updating a
cmd field with the proper program name for some tasks.

This patch just ensures a proc_t is freshened whenever
it has been rejected due to an active PT->hide_kernel.

[ again thanks to Björn for initiating the extension ]

Reference(s):
. original hide_kernel implementation
commit 2a7ec67ac806d91520f59c384684e2332774368b
. original hide_kernel proposal
https://gitlab.com/procps-ng/procps/-/merge_requests/147

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/readproc.c

index bf1606d655a47a649658ddf4a9f3ad0c02b7fc59..bd71d950f4b4dd31d639bd01ac63b987c0473edf 100644 (file)
@@ -1229,9 +1229,13 @@ static proc_t *simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
         autogroup_fill(path, p);
 
     // openproc() ensured that a ppid will be present when needed ...
-    if (rc == 0)
-        return (PT->hide_kernel && (p->ppid == 2 || p->tid == 2)) ? NULL : p;
-
+    if (rc == 0) {
+        if (PT->hide_kernel && (p->ppid == 2 || p->tid == 2)) {
+           free_acquired(p);
+           return NULL;
+        }
+        return p;
+    }
     errno = ENOMEM;
 next_proc:
     return NULL;