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.
I can reproduce with ksh distributed with RHEL-7 and Fedora 27 but not with the latest upstream version of ksh. We will need to check whether it was fixed on purpose, or as a side effect of other code or configuration changes.
Comment 9Siteshwar Vashisht
2018-03-16 15:09:06 UTC
Created attachment 1408847[details]
Fix a leak in subshell when trap is used
This has been picked up from latest upstream.
Comment on attachment 1408847[details]
Fix a leak in subshell when trap is used
I did not try to build/run it but the backport looks good. I think you can remove the 'isig' variable, which becomes unused after applying this patch. The assignment nsig += sizeof(char *); looks redundant but safe. It is also not clear why shp->st.otrapcom is assigned. It does not seem to be read anywhere in the code or am I missing something?
Comment 11Siteshwar Vashisht
2018-03-19 09:39:54 UTC
Indeed. I overlooked this one. Then we should probably nullify shp->st.otrapcom after calling free(savsig) to avoid a use after free, but not necessarily in this RHEL-7 fix.
Comment 13Siteshwar Vashisht
2018-03-19 11:31:16 UTC
Created attachment 1409826[details]
Fix a leak in subshell when trap is used
Updated patch to remove isig variable.
Comment 19Siteshwar Vashisht
2018-05-15 13:26:20 UTC
Comment on attachment 1436790[details]
Fix a leak in subshell when trap is used
As noted on IRC, I would modify the code to assign NULL immediately after free() to minimize the window where the array references already freed objects.
Comment 22Siteshwar Vashisht
2018-09-10 14:57:31 UTC
*** Bug 1577907 has been marked as a duplicate of this bug. ***
Comment 23Siteshwar Vashisht
2019-08-14 12:04:31 UTC
Patch posted in comment 19 introduces a regression:
test basic failed at 2019-08-14+13:49:32 with exit code 1 [ 102 tests 1 error ]
test basic(C.UTF-8) begins at 2019-08-14+13:49:32
basic.sh[257]: traps ignored by parent not ignored
test basic(C.UTF-8) failed at 2019-08-14+13:50:01 with exit code 1 [ 102 tests 1 error ]
test basic(shcomp) begins at 2019-08-14+13:50:01
shcomp-basic.ksh[257]: traps ignored by parent not ignored
Comment 24RHEL Program Management
2019-08-14 12:05:11 UTC
Development Management has reviewed and declined this request. You may appeal this decision by reopening this request.
(In reply to Siteshwar Vashisht from comment #23)
> Patch posted in comment 19 introduces a regression:
>
> test basic failed at 2019-08-14+13:49:32 with exit code 1 [ 102 tests 1
> error ]
> test basic(C.UTF-8) begins at 2019-08-14+13:49:32
> basic.sh[257]: traps ignored by parent not ignored
> test basic(C.UTF-8) failed at 2019-08-14+13:50:01 with exit code 1 [ 102
> tests 1 error ]
> test basic(shcomp) begins at 2019-08-14+13:50:01
> shcomp-basic.ksh[257]: traps ignored by parent not ignored
The issue should be corrected by reverting ksh-20120801-trapcom.patch
and adding this pseudo patch to sh/subshell.c:
nsig += sizeof(char*);
memcpy(savsig=malloc(nsig),(char*)&shp->st.trapcom[0],nsig);
+ memset((char*)&shp->st.trapcom[0],0,nsig);
/* this nonsense needed for $(trap) */
shp->st.otrapcom = (char**)savsig;
and equivalent change to sh/xec.c.
ksh-20120801-trapcom.patch was a rather complex/incorrect correction to #1117404
The leak happens in sh_sigreset(0) that does set the shp->st.trapcom[X] to
NULL, and only calls free if the mode argument is non zero.
The upstream code was buggy in that it would save a vector of string pointers,
release the pointers and later restore the vector of string pointers.
Since sh_sigreset is always called with a zero argument, it means it will always
set the pointers to NULL in sh.st.trapcom[X], calling memset will prevent it from
releasing the pointers in the later call to sh_sigreset(1), *or* to the right thing
at that moment, contrary to ksh-20120801-trapcom.patch.