Bug 1267912 - malloc() signal leak in lexsave() [RHEL-7]
malloc() signal leak in lexsave() [RHEL-7]
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: zsh (Show other bugs)
7.2
Unspecified Unspecified
urgent Severity high
: rc
: ---
Assigned To: Kamil Dudka
Jan Kepler
Robert Krátký
: EasyFix, Patch, ZStream
Depends On:
Blocks: 1203710 1295396 1313485 1267903 1289025 1295829 1338885
  Show dependency treegraph
 
Reported: 2015-10-01 07:38 EDT by Kamil Dudka
Modified: 2016-11-03 19:02 EDT (History)
6 users (show)

See Also:
Fixed In Version: zsh-5.0.2-17.el7
Doc Type: Bug Fix
Doc Text:
*zsh* no longer deadlocks on `malloc()` execution 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. This ensures that the described deadlock no longer occurs.
Story Points: ---
Clone Of: 1267903
: 1338885 (view as bug list)
Environment:
Last Closed: 2016-11-03 19:02:21 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Kamil Dudka 2015-10-01 07:38:48 EDT
+++ This bug was initially created as a clone of Bug #1267903 +++

Description of problem:

zsh deadlocks in futex-wait state when signal hit in malloc() called by lexsave():


#0  __lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:97
97	2:	movl	%edx, %eax
(gdb) bt
#0  __lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:97
#1  0x0000003eb427d0a0 in _L_lock_5189 () from /lib64/libc-2.12.so
#2  0x0000003eb42789fb in _int_free (av=0x3eb458fe80, p=0x2174940, have_lock=0) at malloc.c:4959
...
#7  0x0000000000474495 in zhandler (sig=17) at signals.c:584
#8  <signal handler called>
#9  _int_malloc (av=0x3eb458fe80, bytes=<value optimized out>) at malloc.c:4538
#10 0x0000003eb427a991 in __libc_malloc (bytes=264) at malloc.c:3664
#11 0x000000000044a96b in lexsave () at lex.c:252

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

zsh-4.3.11-4.el6.x86_64

How reproducible:

happens in production environment, not reproduced in labs so far

Steps to Reproduce:
1.
2.
3.

Actual results:

zsh deadlocks in futex-wait state

Expected results:

no deadlocks

Additional info:

The bug appears not to affect upstream master, where the function

lexsave(void)
 ... 1x malloc, 1x zalloc

was rewritten to

lex_context_save(struct lex_stack *ls, int toplevel)
  ... no *alloc at all

Recheck of any possible malloc() signal leaks in current RHEL 6 zsh code needed.

--- Additional comment from Kamil Dudka on 2015-10-01 13:30:30 CEST ---

(In reply to Filip Krska from comment #0)
> Description of problem:
> 
> zsh deadlocks in futex-wait state when signal hit in malloc() called by
> lexsave():
> 
> 
> #0  __lll_lock_wait_private () at
> ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:97
> 97	2:	movl	%edx, %eax
> (gdb) bt
> #0  __lll_lock_wait_private () at
> ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:97
> #1  0x0000003eb427d0a0 in _L_lock_5189 () from /lib64/libc-2.12.so
> #2  0x0000003eb42789fb in _int_free (av=0x3eb458fe80, p=0x2174940,
> have_lock=0) at malloc.c:4959
> ...
> #7  0x0000000000474495 in zhandler (sig=17) at signals.c:584
> #8  <signal handler called>
> #9  _int_malloc (av=0x3eb458fe80, bytes=<value optimized out>) at
> malloc.c:4538
> #10 0x0000003eb427a991 in __libc_malloc (bytes=264) at malloc.c:3664
> #11 0x000000000044a96b in lexsave () at lex.c:252

I agree that replacing malloc() by zalloc() will prevent the above backtrace.

> Recheck of any possible malloc() signal leaks in current RHEL 6 zsh code
> needed.

It is unfortunately not that easy.  Calling [z]free() can also cause such a deadlock.  Upstream discouraged from wrapping [z]free() by signal queuing globally because it could hide unprotected accesses to the global state and result in wrong behavior (which is actually worse than the deadlock).

The handling of signals is still not perfect even in the latest upstream version of zsh.  See bug #1198671 for the list of related upstream fixes.  Unfortunately, new bug reports are still coming on the upstream mailing list.
Comment 8 Robert Krátký 2016-08-21 11:40:33 EDT
Hi Kamil,

Could you please check the Release Notes text?

Thank you.
Comment 13 errata-xmlrpc 2016-11-03 19:02:21 EDT
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, 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://rhn.redhat.com/errata/RHBA-2016-2152.html

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