Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete fix for CVE-2018-19758 #456

Closed
ret2libc opened this issue Feb 7, 2019 · 5 comments
Closed

Incomplete fix for CVE-2018-19758 #456

ret2libc opened this issue Feb 7, 2019 · 5 comments

Comments

@ret2libc
Copy link

ret2libc commented Feb 7, 2019

Hi,

I think the fix for CVE-2018-19758 in fa667c2 is not complete and it is still possible to trigger the same flaw just by adjusting the PoC a bit.

In sndfile.h.in:

	struct
	{	int mode ;
		uint32_t start ;
		uint32_t end ;
		uint32_t count ;
	} loops [16] ; /* make variable in a sensible way */

Loops is defined as an array of 16 elements, so reducing loop_count to a 16bit number does not really solve the out-of-bound read issue. The value should be checked and wrapped to 16 (not 16bits) or the process terminated immediately because the input is malformed.

How to reproduce

$ valgrind -- sndfile-convert ./incomplete-fix-CVE-2018-19758 a.wav
==5192== Memcheck, a memory error detector           
==5192== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. 
==5192== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==5192== Command: ./programs/sndfile-convert ../incomplete-fix-CVE-2018-19758 a.wav
==5192==                                            
==5192== Invalid read of size 4                               
==5192==    at 0x42C1BE: wav_write_header (wav.c:1154)
==5192==    by 0x409CE5: sf_writef_int (sndfile.c:2328)
==5192==    by 0x4032D2: sfe_copy_data_int (common.c:88)
==5192==    by 0x402F38: main (sndfile-convert.c:352) 
==5192==  Address 0x4bd7580 is 0 bytes after a block of size 272 alloc'd
==5192==    at 0x483AB1A: calloc (vg_replace_malloc.c:762)
==5192==    by 0x43D14D: psf_instrument_alloc (common.c:1293)
==5192==    by 0x406A6D: sf_command (sndfile.c:1309) 
==5192==    by 0x4030F8: copy_metadata (sndfile-convert.c:389)          
==5192==    by 0x402EE0: main (sndfile-convert.c:344)     
==5192==                                                     
==5192== Invalid read of size 4                     
==5192==    at 0x42C237: wav_write_header (wav.c:1158)        
==5192==    by 0x409CE5: sf_writef_int (sndfile.c:2328)
==5192==    by 0x4032D2: sfe_copy_data_int (common.c:88)
==5192==    by 0x402F38: main (sndfile-convert.c:352)
==5192==  Address 0x4bd7588 is 8 bytes after a block of size 272 alloc'd
==5192==    at 0x483AB1A: calloc (vg_replace_malloc.c:762)
==5192==    by 0x43D14D: psf_instrument_alloc (common.c:1293)
...

poc.tar.gz

Extra

If the issue is confirmed, I will request a new CVE for it as the old one may have been already fixed in some distributions, which would not get the real fix otherwise.

@erikd
Copy link
Member

erikd commented Feb 14, 2019

I can confirm that the existing fix is insufficient.

@ret2libc
Copy link
Author

CVE-2019-3832 was assigned to this flaw.

@epozuelo
Copy link
Contributor

epozuelo commented Mar 1, 2019

Yeah, sounds like loop_count needs to be limited to 0xff. Looking at the code, I wonder if that's not the only problem though. In wav_read_smpl_chunk(), loop_count is read and its value is used to iterate over the loops array, without sanitizing it to [0-16] first. Thus if that functions deals with untrusted data, it can potentially read out of bounds.

@epozuelo
Copy link
Contributor

epozuelo commented Mar 5, 2019

Looks like wav_read_smpl_chunk is covered because of this check:

if (j < ARRAY_LEN (psf->instrument->loops))

I addressed wav_write_header in #460

@erikd
Copy link
Member

erikd commented Mar 7, 2019

#460 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants