Skip to contentSkip to conversation

procps: fixed large pid issue with top

PATCH In review [email protected] 2 participants 2 messages Dec 11, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 procps: fixed large pid issue with top

From: Amaury Couderc <[email protected]>

procps: fixed large pid issue with top

top -b -n1 -H -p 92233720368547758071
  signal 11 (SEGV) was caught by top, please

---
 .../procps/procps/top_large_pid_fix.patch     | 52 +++++++++++++++++++
 meta/recipes-extended/procps/procps_4.0.4.bb  |  1 +
 2 files changed, 53 insertions(+)
 create mode 100644 meta/recipes-extended/procps/procps/top_large_pid_fix.patch
meta/recipes-extended/procps/procps/top_large_pid_fix.patch new file +52 -0
new file mode 100644
index 0000000000..d7e3141e06
@@ -0,0 +1,52 @@
+From f21fc624d960d12afa399af7333d4f9193fb2ffb Mon Sep 17 00:00:00 2001
+From: Jim Warner <[email protected]>
+Date: Tue, 16 Sep 2025 12:00:00 -0500
+Subject: [PATCH] library: avoid possible segmentation fault, <pids> api
+Upstream-Status: Backport
+[https://gitlab.com/procps-ng/procps/-/commit/5461b50b1a85c5e556c4cd2739ca8ffdbc69399a]
+
+In the issue referenced below, that SEGV was caused by
+passing a '-1' pid to the procps_pids_select function.
+That value, in turn, is caused by providing a LONG_MAX
+or greater number for what was assigned to an integer.
+
+So, this commit will help ensure we avoid a match when
+we should fail plus skip some unproductive libc calls.
+
+[ the same problem occurs in that old 3.3.17 library ]
+
+Reference(s):
+https://gitlab.com/procps-ng/procps/-/issues/394
+
+Signed-off-by: Jim Warner <[email protected]>
+Signed-off-by: Amaury Couderc <[email protected]>
+
+---
+ library/readproc.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/library/readproc.c b/library/readproc.c
+index 2dfe4c9e..d0e039bf 100644
+--- a/library/readproc.c
++++ b/library/readproc.c
+@@ -1434,7 +1434,7 @@ static int listed_nextpid (PROCTAB *PT, proc_t *p) {
+   pid_t pid = *(PT->pids)++;
+   char *path = PT->path;
+ 
+-  if (pid) {
++  if (pid > 0) {
+     snprintf(path, PROCPATHLEN, "/proc/%d", pid);
+     p->tid = p->tgid = pid;        // this tgid may be a huge fib |
+ 
+@@ -1546,7 +1546,7 @@ PROCTAB *openproc(unsigned flags, ...) {
+         did_stat = 1;
+     }
+     PT->taskdir = NULL;
+-    PT->taskdir_user = -1;
++    PT->taskdir_user = -2;
+     PT->taskfinder = simple_nexttid;
+     PT->taskreader = simple_readtask;
+ 
+-- 
+2.43.0
+
meta/recipes-extended/procps/procps_4.0.4.bb +1 -0
index ec8c4b0261..3c15f28a5b 100644
@@ -15,6 +15,7 @@ inherit autotools gettext pkgconfig update-alternatives
 SRC_URI = "git://gitlab.com/procps-ng/procps.git;protocol=https;branch=master \
            file://sysctl.conf \
            file://pidfd.patch \
+           file://top_large_pid_fix.patch \
            "
 SRCREV = "4ddcef2fd843170c8e2d59a83042978f41037a2b"
 
Signature · 1 line
2.50.1
#1 lore raw

Hello,

Quoted 9 lines · amaury.couderc via lists.openembedded.org

From: Amaury Couderc <[email protected]>

procps: fixed large pid issue with top

top -b -n1 -H -p 92233720368547758071
signal 11 (SEGV) was caught by top, please

It looks like this patch is also applicable&needed on master (the fixing patch has not been in a procps release yet).
Can you send it there, then, ask for a backport on scarthgap when it gets merged?

Thanks!

Quoted 88 lines
---
 .../procps/procps/top_large_pid_fix.patch     | 52 +++++++++++++++++++
 meta/recipes-extended/procps/procps_4.0.4.bb  |  1 +
 2 files changed, 53 insertions(+)
 create mode 100644 meta/recipes-extended/procps/procps/top_large_pid_fix.patch
meta/recipes-extended/procps/procps/top_large_pid_fix.patch new file +52 -0
new file mode 100644
index 0000000000..d7e3141e06
@@ -0,0 +1,52 @@
+From f21fc624d960d12afa399af7333d4f9193fb2ffb Mon Sep 17 00:00:00 2001
+From: Jim Warner <[email protected]>
+Date: Tue, 16 Sep 2025 12:00:00 -0500
+Subject: [PATCH] library: avoid possible segmentation fault, <pids> api
+Upstream-Status: Backport
+[https://gitlab.com/procps-ng/procps/-/commit/5461b50b1a85c5e556c4cd2739ca8ffdbc69399a]
+
+In the issue referenced below, that SEGV was caused by
+passing a '-1' pid to the procps_pids_select function.
+That value, in turn, is caused by providing a LONG_MAX
+or greater number for what was assigned to an integer.
+
+So, this commit will help ensure we avoid a match when
+we should fail plus skip some unproductive libc calls.
+
+[ the same problem occurs in that old 3.3.17 library ]
+
+Reference(s):
+https://gitlab.com/procps-ng/procps/-/issues/394
+
+Signed-off-by: Jim Warner <[email protected]>
+Signed-off-by: Amaury Couderc <[email protected]>
+
+---
+ library/readproc.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/library/readproc.c b/library/readproc.c
+index 2dfe4c9e..d0e039bf 100644
+--- a/library/readproc.c
++++ b/library/readproc.c
+@@ -1434,7 +1434,7 @@ static int listed_nextpid (PROCTAB *PT, proc_t *p) {
+   pid_t pid = *(PT->pids)++;
+   char *path = PT->path;
+
+-  if (pid) {
++  if (pid > 0) {
+     snprintf(path, PROCPATHLEN, "/proc/%d", pid);
+     p->tid = p->tgid = pid;        // this tgid may be a huge fib |
+
+@@ -1546,7 +1546,7 @@ PROCTAB *openproc(unsigned flags, ...) {
+         did_stat = 1;
+     }
+     PT->taskdir = NULL;
+-    PT->taskdir_user = -1;
++    PT->taskdir_user = -2;
+     PT->taskfinder = simple_nexttid;
+     PT->taskreader = simple_readtask;
+
+--
+2.43.0
+
meta/recipes-extended/procps/procps_4.0.4.bb +1 -1
index ec8c4b0261..3c15f28a5b 100644
@@ -15,6 +15,7 @@ inherit autotools gettext pkgconfig update-alternatives
 SRC_URI = "git://gitlab.com/procps-ng/procps.git;protocol=https;branch=master \
            file://sysctl.conf \
            file://pidfd.patch \
+           file://top_large_pid_fix.patch \
            "
 SRCREV = "4ddcef2fd843170c8e2d59a83042978f41037a2b"
 
--

2.50.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#227538): https://lists.openembedded.org/g/openembedded-core/message/227538
Mute This Topic: https://lists.openembedded.org/mt/116729698/4316185
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 2 lines
Yoann Congal
Smile ECS