Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
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 2007364

Summary: ksh segfault due to read of free'd memory
Product: Red Hat Enterprise Linux 7 Reporter: Paulo Andrade <pandrade>
Component: kshAssignee: Vincent Mihalkovič <vmihalko>
Status: CLOSED ERRATA QA Contact: Karel Volný <kvolny>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.9CC: jreznik, kdudka, vmihalko
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: ---Flags: pm-rhel: mirror+
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: ksh-20120801-143.el7_9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-23 17:13:10 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Paulo Andrade 2021-09-23 16:42:43 UTC
A build with system malloc, and valgrind logs (without debuginfo) show:

==29580== Invalid read of size 8
==29580==    at 0x45890A: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x45AAF9: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x457C6A: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x459A3A: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x459A3A: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x459A3A: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x459A3A: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x459A3A: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x459A3A: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x45ACF6: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x457C6A: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x456CD9: sh_funscope (in /usr/bin/ksh93)
==29580==  Address 0x5c1a888 is 8,184 bytes inside a block of size 8,192 free'd
==29580==    at 0x4C2B06D: free (vg_replace_malloc.c:540)
==29580==    by 0x49C768: stkset (in /usr/bin/ksh93)
==29580==    by 0x4587A2: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x457C6A: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x456CD9: sh_funscope (in /usr/bin/ksh93)
==29580==    by 0x4570E7: sh_funct (in /usr/bin/ksh93)
==29580==    by 0x459658: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x457C89: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x45AAF9: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x406AD7: exfile (in /usr/bin/ksh93)
==29580==    by 0x4075C4: sh_main (in /usr/bin/ksh93)
==29580==    by 0x5562554: (below main) (libc-start.c:266)
==29580==  Block was alloc'd at
==29580==    at 0x4C2C089: calloc (vg_replace_malloc.c:762)
==29580==    by 0x49C19D: stkgrow (in /usr/bin/ksh93)
==29580==    by 0x49CA22: stkalloc (in /usr/bin/ksh93)
==29580==    by 0x45AE5D: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x457C6A: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x456CD9: sh_funscope (in /usr/bin/ksh93)
==29580==    by 0x4570E7: sh_funct (in /usr/bin/ksh93)
==29580==    by 0x459658: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x457C89: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x45AAF9: sh_exec (in /usr/bin/ksh93)
==29580==    by 0x406AD7: exfile (in /usr/bin/ksh93)
==29580==    by 0x4075C4: sh_main (in /usr/bin/ksh93)

The issue should be fixed with https://github.com/ksh93/ksh/commit/4604df9ada906e0a6537157a63b6ce7c0509f34d
[Stack robustness fixes from OpenSUSE]

Comment 8 Karel Volný 2021-10-13 09:14:28 UTC
pls, do we have a reproducer for this?

(the OpenSuse bug is not public and the scripts from the customer case on their own are not enough)

Comment 9 Vincent Mihalkovič 2021-10-13 12:37:57 UTC
I'm sorry, don't know about any reproducer. Maybe Paulo knows?

Comment 10 Paulo Andrade 2021-10-13 12:54:33 UTC
Probably could ask someone from OpenSuSE, with a bugzilla account with enough
permissions, to check if there is a reproducer.

I was aware something was wrong in this code path for some time, and the
few other cases I saw it as root cause ended up with minor modifications
to shell code, to avoid hitting the condition.

Did not find time to work on a patch, and did not know OpenSuSE had a patch
for it. Also, not fully understanding the code, could just end up with a
patch that could break elsewhere...

It should be triggered by local function variables and some kind of control
flow change in some stack of function calls.

Possibly due to, in C code, some longjmp back to stack base, and due to saving
state in the stack, restoring an invalid value.

Comment 15 errata-xmlrpc 2021-11-23 17:13:10 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 (ksh 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-2021:4776