Bug 1300958

Summary: segfault in script after ulimit -v [RHEL-6]
Product: Red Hat Enterprise Linux 6 Reporter: Martin Kyral <mkyral>
Component: zshAssignee: Kamil Dudka <kdudka>
Status: CLOSED WONTFIX QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: low Docs Contact:
Priority: unspecified    
Version: 6.7CC: jkejda, kdudka
Target Milestone: rcKeywords: Patch
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1302229 (view as bug list) Environment:
Last Closed: 2017-07-03 12:47:09 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:
Bug Depends On: 1302229    
Bug Blocks:    
Attachments:
Description Flags
backtrace
none
proof-of-concept reproducer none

Description Martin Kyral 2016-01-22 08:22:15 UTC
Created attachment 1117132 [details]
backtrace

Description of problem:
Script containing ulimit -v 100000 causes zsh to segfault:

[0 root@qeos-21 test]# cat segv.sh
ulimit -v 100000
ls
[0 root@qeos-21 test]# zsh segv.sh
Segmentation fault (core dumped)
[0 root@qeos-21 test]# echo $?
139

By further examination I found out, that the problem is bad handling of the memory allocation if the memory limit set by ulimit -v is too strict.

ksh and bash are ok with this particular value. When I set it really low (ulimit -v 100), the script gets killed by SIGKILL which is better than SIGSEGV.

Version-Release number of selected component (if applicable):
zsh-4.3.11-4.el6_7.1

How reproducible:
always

Steps to Reproduce:
1. see description
2.
3.

Actual results:
[0 root@qeos-21 test]# zsh segv.sh
Segmentation fault (core dumped)
[0 root@qeos-21 test]# echo $?
139

Expected results:
[0 root@qeos-21 test]# zsh segv.sh
Killed
[0 root@qeos-21 test]# echo $?
137


Additional info:
It may be necessary to use lower ulimit -v value to reproduce.

Comment 1 Kamil Dudka 2016-01-22 09:36:34 UTC
Thank you for reporting the bug.  From the backtrace it is clear that it crashes due to infinite recursion and stack overflow.  zalloc() fails to allocate memory, so it wants to print a fatal error message and exit.  The problem is that zerr(), which is used to print the error message, transitively calls back to zalloc().

In order to prevent the stack overflow, we need to:
1. either make zalloc() not call zerr(),
2. make zerr() not transitively call back to zalloc(), or
3. introduce a flag that will break the recursion in cases like this.

Comment 2 Kamil Dudka 2016-01-25 13:56:37 UTC
Created attachment 1118021 [details]
proof-of-concept reproducer

I have attached a universal reproducer script.  It is not completely reliable because dynamic linker and pthread run-time may run out of memory sooner than zsh itself in some cases.  Nevertheless, I am able to trigger the infinite recursion with upstream git HEAD if I create a statically linked executable.

Comment 3 Kamil Dudka 2016-01-25 15:22:58 UTC
reported upstream:

http://www.zsh.org/mla/workers/2016/msg00310.html

Comment 4 Martin Kyral 2016-01-25 15:53:12 UTC
.. and there's already proposed fix. Thanks!

Comment 6 Kamil Dudka 2016-01-27 09:08:07 UTC
fixed in zsh-5.2-4.fc24

Comment 9 Kamil Dudka 2017-07-03 12:47:09 UTC
Red Hat Enterprise Linux 6 transitioned to the Production 3 Phase on May 10, 2017.  During the Production 3 Phase, Critical impact Security Advisories (RHSAs) and selected Urgent Priority Bug Fix Advisories (RHBAs) may be released as they become available.

The official life cycle policy can be reviewed here:

http://redhat.com/rhel/lifecycle

This issue does not appear to meet the inclusion criteria for the Production Phase 3 and will be marked as CLOSED/WONTFIX. If this remains a critical requirement, please contact Red Hat Customer Support to request a re-evaluation of the issue, citing a clear business justification.  Red Hat Customer Support can be contacted via the Red Hat Customer Portal at the following URL:

https://access.redhat.com