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 1311172 - bld_eprog() signal leak [RHEL-7]
Summary: bld_eprog() signal leak [RHEL-7]
Keywords:
Status: CLOSED DUPLICATE of bug 1198671
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: zsh
Version: 7.2
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: rc
: ---
Assignee: Kamil Dudka
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-02-23 14:43 UTC by Filip Krska
Modified: 2019-10-10 11:18 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Previously, if the zsh process received a signal during the execution of a memory allocation function and the signal handler attempted to allocate or free memory, zsh entered a deadlock and became unresponsive. With this update, signal handlers are no longer enabled while handling the global state of zsh or while using the heap memory allocator, which ensures that the described deadlock no longer occurs.
Clone Of: 1311166
Environment:
Last Closed: 2016-03-01 12:40:07 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Filip Krska 2016-02-23 14:43:48 UTC
zsh-5.0.2-18.el7 lacks the queue_signals() block in bld_eprog() as well.

+++ This bug was initially created as a clone of Bug #1311166 +++

Description of problem:

zhandler() - free() deadlock in bld_eprog():

(gdb) bt
#0  __lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:97
#1  0x000000333827cdc0 in _L_lock_5199 () from /lib64/libc-2.12.so
#2  0x000000333827871b in _int_free (av=0x333858fe80, p=0x24b9a10, have_lock=0) at malloc.c:4963
#3  0x000000000044362d in freejob (jn=0x249a560, deleting=1) at jobs.c:1103
#4  0x000000000044486d in printjob (jn=0x249a560, lng=0, synch=0) at jobs.c:1066
#5  0x00000000004472da in update_job (jn=0x249a560) at jobs.c:508
#6  0x0000000000473bcb in wait_for_processes () at signals.c:502
#7  0x0000000000474495 in zhandler (sig=17) at signals.c:584
#8  <signal handler called>
#9  0x0000003338278443 in _int_free (av=0x333858fe80, p=0x24baf20, have_lock=0) at malloc.c:4973
#10 0x0000000000465a47 in bld_eprog () at parse.c:413
#11 0x000000000040f134 in bin_test (name=0x7f49c1ad7120 "[", argv=0x7f49c1ad7528, ops=<value optimized out>, 
    func=<value optimized out>) at builtin.c:5851

Version-Release number of selected component (if applicable):

zsh-4.3.11-4.el6_7.1.x86_64

How reproducible:

Happened in production, not reproduced in test environment so far.

Steps to Reproduce:
1.
2.
3.

Actual results:

zsh deadlocks in futex-wait state.

Expected results:

zsh doesn't deadlock

Additional info:

zsh-5.0.2-18.el7 will suffer as well. Fixed in upstream zsh-5.2, backport patch proposal:

diff -up zsh-4.3.11/Src/parse.c.bld_eprog_sigleak zsh-4.3.11/Src/parse.c
--- zsh-4.3.11/Src/parse.c.bld_eprog_sigleak	2016-02-23 15:34:15.063441138 +0100
+++ zsh-4.3.11/Src/parse.c	2016-02-23 15:35:04.369447251 +0100
@@ -391,6 +391,8 @@ bld_eprog(void)
     Eprog ret;
     int l;
 
+    queue_signals();
+
     ecadd(WCB_END());
 
     ret = (Eprog) zhalloc(sizeof(*ret));
@@ -413,6 +415,8 @@ bld_eprog(void)
     zfree(ecbuf, eclen);
     ecbuf = NULL;
 
+    unqueue_signals();
+
     return ret;
 }

Please, consider re-initiating talks about calling free() (non signal safe function i.e. not supposed to be called from signal handlers) from zhandler() and re-scan of rhel6/7/upstream zsh code for any other possible signal leaks again.

Comment 1 Kamil Dudka 2016-02-23 15:10:08 UTC
(In reply to Filip Krska from comment #0)
> zsh-5.0.2-18.el7 will suffer as well. Fixed in upstream zsh-5.2, backport
> patch proposal:
> 
> diff -up zsh-4.3.11/Src/parse.c.bld_eprog_sigleak zsh-4.3.11/Src/parse.c
> --- zsh-4.3.11/Src/parse.c.bld_eprog_sigleak	2016-02-23 15:34:15.063441138
> +0100
> +++ zsh-4.3.11/Src/parse.c	2016-02-23 15:35:04.369447251 +0100
> @@ -391,6 +391,8 @@ bld_eprog(void)
>      Eprog ret;
>      int l;
>  
> +    queue_signals();
> +
>      ecadd(WCB_END());
>  
>      ret = (Eprog) zhalloc(sizeof(*ret));
> @@ -413,6 +415,8 @@ bld_eprog(void)
>      zfree(ecbuf, eclen);
>      ecbuf = NULL;
>  
> +    unqueue_signals();
> +
>      return ret;
>  }

Thanks!  This hunk is taken from a bigger upstream commit:

https://sourceforge.net/p/zsh/code/ci/99586845

Would it also make sense to pick the other hunk for parse.c?

--- a/Src/parse.c
+++ b/Src/parse.c
@@ -456,6 +456,8 @@ init_parse_status(void)
 void
 init_parse(void)
 {
+    queue_signals();
+
     if (ecbuf) zfree(ecbuf, eclen);

     ecbuf = (Wordcode) zalloc((eclen = EC_INIT_SIZE) * sizeof(wordcode));
@@ -466,6 +468,8 @@ init_parse(void)
     ecnfunc = 0;

     init_parse_status();
+
+    unqueue_signals();
 }

 /* Build eprog. */

> Please, consider re-initiating talks about calling free() (non signal safe
> function i.e. not supposed to be called from signal handlers) from
> zhandler() and re-scan of rhel6/7/upstream zsh code for any other possible
> signal leaks again.

I keep gathering commits like this at bug #1198671.  The one you picked the hunk from is already mentioned there (bug #1198671 comment #5).  The problem is that these upstream patches are not exactly safe.  They introduced regressions when they landed upstream.  I do not think we want to propagate them to RHEL.

Comment 4 Kamil Dudka 2016-03-01 12:40:07 UTC
I am closing this as a duplicate of bug #1198671 because the proposed patch is already included in the patch for bug #1198671.

*** This bug has been marked as a duplicate of bug 1198671 ***


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