Bug 1368591

Summary: ksh strdup result leak in sh_subshell() when trap used
Product: Red Hat Enterprise Linux 6 Reporter: Ilya Basin <basinilya>
Component: kshAssignee: Siteshwar Vashisht <svashisht>
Status: CLOSED CANTFIX QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.8CC: rblakley
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1460940 (view as bug list) Environment:
Last Closed: 2017-06-13 08:18:04 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:    
Bug Blocks: 1460940    

Description Ilya Basin 2016-08-19 21:08:35 UTC
Description of problem:

After setting a trap each new subshell leaks some memory. Our long-running script reserves 1gb/week.

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

    ksh-20120801-33.el6.x86_64

How reproducible:

Run the following command:

    ksh -c "trap exit INT ; while true; do ( : ) ; done ; :"

Monitor memory reserved by ksh. It should grow significanlty in less than a minute.


Additional info:

Compiled the package with '-fsanitize=address' on a machine with modern gcc 6. I think the solution is to call sh_sigreset() with mode=1.

	[il@reallin ksh-20120801]$ /home/il/ksh-20120801/arch/linux.i386-64/bin/ksh -c "trap exit INT ; while true; do ( : ) ; done ; :"
	^C
	=================================================================
	==22760==ERROR: LeakSanitizer: detected memory leaks
	
	Direct leak of 15954060 byte(s) in 3190812 object(s) allocated from:
	    #0 0x7f8ca99ab100 in __interceptor_strdup /build/gcc-multilib/src/gcc/libsanitizer/asan/asan_interceptors.cc:560
	    #1 0x50a193 in sh_subshell /home/il/ksh-20120801/src/cmd/ksh93/sh/subshell.c:570
	    #2 0x522b8e in sh_exec /home/il/ksh-20120801/src/cmd/ksh93/sh/xec.c:2075
	    #3 0x52677f in sh_exec /home/il/ksh-20120801/src/cmd/ksh93/sh/xec.c:2500
	    #4 0x524298 in sh_exec /home/il/ksh-20120801/src/cmd/ksh93/sh/xec.c:2257
	    #5 0x40a9a3 in exfile /home/il/ksh-20120801/src/cmd/ksh93/sh/main.c:581
	    #6 0x408449 in sh_main /home/il/ksh-20120801/src/cmd/ksh93/sh/main.c:353
	    #7 0x40652a in main /home/il/ksh-20120801/src/cmd/ksh93/sh/pmain.c:45
	    #8 0x7f8ca8ec5740 in __libc_start_main (/lib/libc.so.6+0x20740)
	
	Direct leak of 5 byte(s) in 1 object(s) allocated from:
	    #0 0x7f8ca99ab100 in __interceptor_strdup /build/gcc-multilib/src/gcc/libsanitizer/asan/asan_interceptors.cc:560
	    #1 0x57d879 in b_trap /home/il/ksh-20120801/src/cmd/ksh93/bltins/trap.c:156
	    #2 0x51c5da in sh_exec /home/il/ksh-20120801/src/cmd/ksh93/sh/xec.c:1410
	    #3 0x524298 in sh_exec /home/il/ksh-20120801/src/cmd/ksh93/sh/xec.c:2257
	    #4 0x40a9a3 in exfile /home/il/ksh-20120801/src/cmd/ksh93/sh/main.c:581
	    #5 0x408449 in sh_main /home/il/ksh-20120801/src/cmd/ksh93/sh/main.c:353
	    #6 0x40652a in main /home/il/ksh-20120801/src/cmd/ksh93/sh/pmain.c:45
	    #7 0x7f8ca8ec5740 in __libc_start_main (/lib/libc.so.6+0x20740)
	
	SUMMARY: AddressSanitizer: 15954065 byte(s) leaked in 3190813 allocation(s).