RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2153813 - Out of bounds read in ps that might show inconsistent output
Summary: Out of bounds read in ps that might show inconsistent output
Keywords:
Status: CLOSED ERRATA
Alias: None
Deadline: 2023-01-30
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: procps-ng
Version: 8.3
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Jan Rybar
QA Contact: Karel Volný
URL:
Whiteboard:
Depends On:
Blocks: 2161648
TreeView+ depends on / blocked
 
Reported: 2022-12-15 14:31 UTC by Paulo Andrade
Modified: 2023-06-05 14:35 UTC (History)
2 users (show)

Fixed In Version: procps-ng-3.3.15-12.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 2161648 (view as bug list)
Environment:
Last Closed: 2023-05-16 09:10:39 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-142452 0 None None None 2022-12-15 14:36:18 UTC
Red Hat Product Errata RHBA-2023:3019 0 None None None 2023-05-16 09:10:43 UTC

Description Paulo Andrade 2022-12-15 14:31:01 UTC
Sample reproducer:

$ sleep 600 &
$ PID=$!
$ valgrind ps -e -q $PID
...
==66579== Invalid read of size 4
==66579==    at 0x4E43E0E: listed_nextpid (readproc.c:1264)
==66579==    by 0x4E46866: readproc (readproc.c:1301)
==66579==    by 0x112E80: simple_spew (display.c:373)
==66579==    by 0x112E80: main (display.c:673)
==66579==  Address 0x76971c4 is 0 bytes after a block of size 4 alloc'd
==66579==    at 0x4C30BEB: malloc (vg_replace_malloc.c:299)
==66579==    by 0x112F82: simple_spew (display.c:355)
==66579==    by 0x112F82: main (display.c:673)
...

  Cause of the problem is the two bugs below:

ps/display.c:simple_spew()
...
  pidlist = NULL;
...
    pidlist = (pid_t*) malloc(selection_list->n * sizeof(pid_t));
    <<< BUG 1 >>>
...
    for (i = 0; i < selection_list->n; i++) {
      pidlist[i] = selection_list->u[selection_list->n-i-1].pid;
    }
    <<<< BUG 2 >>>
...
  ptp = openproc(flags, pidlist);

BUG 1 means it should allocate one extra entry.
BUG 2 means it should set the last entry to zero.

  The problem happens in:

proc/readproc.c:openproc()
...
    va_start(ap, flags);
    if (flags & PROC_PID)
        PT->pids = va_arg(ap, pid_t*);
...

in the above, the PT->pids list does not end with an explicit zero.
The problem manifests in:

proc/readproc.c:listed_nextpid()
...
  pid_t tgid = *(PT->pids)++;
  if(likely(tgid)){
    snprintf(path, PROCPATHLEN, "/proc/%d", tgid);
    p->tgid = tgid;
    p->tid = tgid;  // they match for leaders
  }
  return tgid;
...

Causing undefined behaviour in output. Most times it is just an
invalid read and by accident, correct output.

Comment 12 errata-xmlrpc 2023-05-16 09:10:39 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (procps-ng bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:3019


Note You need to log in before you can comment on or make changes to this bug.