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

Heap buffer overflow #17116

Closed
p5pRT opened this issue Aug 1, 2019 · 26 comments
Closed

Heap buffer overflow #17116

p5pRT opened this issue Aug 1, 2019 · 26 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 1, 2019

Migrated from rt.perl.org#134325 (status was 'pending release')

Searchable as RT134325$

@p5pRT
Copy link
Author

p5pRT commented Aug 1, 2019

From nguyenmanhdung1710@gmail.com

Hi All,
I found a Use-After-Free bug in the commit *a3c7756* on branch *blead*.
This bug causes Perl to crash. I use gcc v5.5.0 to compile Perl on Ubuntu
16.04 (64 bit) as follows​:
  ./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g" -Dloclibpth='
'; make

Thanks,
Manh Dung

======================================
*perl -v*
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-37-ga3c7756))
built for x86_64-linux

- Crafted PoC​:
https://github.com/strongcourage/PoCs/blob/master/perl_82007f7/PoC_uaf_regcomp.c:12238
- Command​: perl $PoC

ASAN says​:
==25228==ERROR​: AddressSanitizer​: heap-use-after-free on address
0x7fdd62cd4e35 at pc 0x00000058a4eb bp 0x7ffdd5a06710 sp 0x7ffdd5a06700
READ of size 1 at 0x7fdd62cd4e35 thread T0
  #0 0x58a4ea in S_reg
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12238
  #1 0x58bd22 in Perl_re_op_compile
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:7721
  #2 0x6b1a24 in Perl_pp_regcomp
/home/dungnguyen/gueb-testing/perl-head/pp_ctl.c​:108
  #3 0x5fa20a in Perl_runops_standard
/home/dungnguyen/gueb-testing/perl-head/run.c​:41
  #4 0x48f0b7 in S_run_body
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2696
  #5 0x48f0b7 in perl_run
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2624
  #6 0x425674 in main
/home/dungnguyen/gueb-testing/perl-head/perlmain.c​:127
  #7 0x7fdd71f9082f in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
  #8 0x425be8 in _start
(/home/dungnguyen/PoCs/perl_82007f7/perl-asan+0x425be8)

0x7fdd62cd4e35 is located 13877 bytes inside of 617548-byte region
[0x7fdd62cd1800,0x7fdd62d6844c)
freed by thread T0 here​:
  #0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
  #1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

previously allocated by thread T0 here​:
  #0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
  #1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

@p5pRT
Copy link
Author

p5pRT commented Aug 1, 2019

From nguyenmanhdung1710@gmail.com

Hi All,
I found a Use-After-Free bug in the commit *a3c7756* on branch *blead*.
This bug causes Perl to crash. I use gcc v5.5.0 to compile Perl on Ubuntu
16.04 (64 bit) as follows​:
  ./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g" -Dloclibpth='
'; make

Thanks,
Manh Dung

======================================
*perl -v*
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-37-ga3c7756))
built for x86_64-linux

- Crafted PoC​:
https://github.com/strongcourage/PoCs/blob/master/perl_82007f7/PoC_hbo
- Command​: perl $PoC

ASAN says​:
==25324==ERROR​: AddressSanitizer​: heap-buffer-overflow on address
0x7f0d2e16a7e5 at pc 0x00000058a4eb bp 0x7fff7ef03880 sp 0x7fff7ef03870
READ of size 1 at 0x7f0d2e16a7e5 thread T0
  #0 0x58a4ea in S_reg
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12238
  #1 0x57112d in S_regatom
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:13370
  #2 0x57112d in S_regpiece
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12473
  #3 0x57df9e in S_regbranch
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12393
  #4 0x57ef49 in S_reg
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12148
  #5 0x58bd22 in Perl_re_op_compile
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:7721
  #6 0x6b1a24 in Perl_pp_regcomp
/home/dungnguyen/gueb-testing/perl-head/pp_ctl.c​:108
  #7 0x5fa20a in Perl_runops_standard
/home/dungnguyen/gueb-testing/perl-head/run.c​:41
  #8 0x48f0b7 in S_run_body
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2696
  #9 0x48f0b7 in perl_run
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2624
  #10 0x425674 in main
/home/dungnguyen/gueb-testing/perl-head/perlmain.c​:127
  #11 0x7f0d34c2b82f in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
  #12 0x425be8 in _start
(/home/dungnguyen/PoCs/perl_82007f7/perl-asan+0x425be8)

0x7f0d2e16a7e5 is located 27 bytes to the left of 1197244-byte region
[0x7f0d2e16a800,0x7f0d2e28ecbc)
freed by thread T0 here​:
  #0 0x7f0d359cf9c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
  #1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

previously allocated by thread T0 here​:
  #0 0x7f0d359cf9c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
  #1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

@p5pRT
Copy link
Author

p5pRT commented Aug 1, 2019

From @jkeenan

On Thu, 01 Aug 2019 07​:15​:46 GMT, nguyenmanhdung1710@​gmail.com wrote​:

Hi All,
I found a Use-After-Free bug in the commit *a3c7756* on branch
*blead*.
This bug causes Perl to crash. I use gcc v5.5.0 to compile Perl on
Ubuntu
16.04 (64 bit) as follows​:
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g"
-Dloclibpth='
'; make

Thanks,
Manh Dung

======================================
*perl -v*
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-37-
ga3c7756))
built for x86_64-linux

- Crafted PoC​:
https://github.com/strongcourage/PoCs/blob/master/perl_82007f7/PoC_uaf_regcomp.c:12238
- Command​: perl $PoC

ASAN says​:
==25228==ERROR​: AddressSanitizer​: heap-use-after-free on address
0x7fdd62cd4e35 at pc 0x00000058a4eb bp 0x7ffdd5a06710 sp
0x7ffdd5a06700
READ of size 1 at 0x7fdd62cd4e35 thread T0
#0 0x58a4ea in S_reg
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12238
#1 0x58bd22 in Perl_re_op_compile
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:7721
#2 0x6b1a24 in Perl_pp_regcomp
/home/dungnguyen/gueb-testing/perl-head/pp_ctl.c​:108
#3 0x5fa20a in Perl_runops_standard
/home/dungnguyen/gueb-testing/perl-head/run.c​:41
#4 0x48f0b7 in S_run_body
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2696
#5 0x48f0b7 in perl_run
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2624
#6 0x425674 in main
/home/dungnguyen/gueb-testing/perl-head/perlmain.c​:127
#7 0x7fdd71f9082f in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#8 0x425be8 in _start
(/home/dungnguyen/PoCs/perl_82007f7/perl-asan+0x425be8)

0x7fdd62cd4e35 is located 13877 bytes inside of 617548-byte region
[0x7fdd62cd1800,0x7fdd62d6844c)
freed by thread T0 here​:
#0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

previously allocated by thread T0 here​:
#0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

Thank you for this report. However, in this report -- as well as the five other reports you filed today -- it's not clear what the perl program was that you used to generated the error or crash.

Could you please *attach* the program you used to this ticket (or to your email response)?

And do so likewise for the other five tickets?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Aug 1, 2019

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Aug 1, 2019

From nguyenmanhdung1710@gmail.com

On Thu, 01 Aug 2019 11​:25​:14 -0700, jkeenan wrote​:

On Thu, 01 Aug 2019 07​:15​:46 GMT, nguyenmanhdung1710@​gmail.com wrote​:

Hi All,
I found a Use-After-Free bug in the commit *a3c7756* on branch
*blead*.
This bug causes Perl to crash. I use gcc v5.5.0 to compile Perl on
Ubuntu
16.04 (64 bit) as follows​:
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g"
-Dloclibpth='
'; make

Thanks,
Manh Dung

======================================
*perl -v*
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-37-
ga3c7756))
built for x86_64-linux

- Crafted PoC​:
https://github.com/strongcourage/PoCs/blob/master/perl_82007f7/PoC_uaf_regcomp.c:12238
- Command​: perl $PoC

ASAN says​:
==25228==ERROR​: AddressSanitizer​: heap-use-after-free on address
0x7fdd62cd4e35 at pc 0x00000058a4eb bp 0x7ffdd5a06710 sp
0x7ffdd5a06700
READ of size 1 at 0x7fdd62cd4e35 thread T0
#0 0x58a4ea in S_reg
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12238
#1 0x58bd22 in Perl_re_op_compile
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:7721
#2 0x6b1a24 in Perl_pp_regcomp
/home/dungnguyen/gueb-testing/perl-head/pp_ctl.c​:108
#3 0x5fa20a in Perl_runops_standard
/home/dungnguyen/gueb-testing/perl-head/run.c​:41
#4 0x48f0b7 in S_run_body
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2696
#5 0x48f0b7 in perl_run
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2624
#6 0x425674 in main
/home/dungnguyen/gueb-testing/perl-head/perlmain.c​:127
#7 0x7fdd71f9082f in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#8 0x425be8 in _start
(/home/dungnguyen/PoCs/perl_82007f7/perl-asan+0x425be8)

0x7fdd62cd4e35 is located 13877 bytes inside of 617548-byte region
[0x7fdd62cd1800,0x7fdd62d6844c)
freed by thread T0 here​:
#0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

previously allocated by thread T0 here​:
#0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

Thank you for this report. However, in this report -- as well as the
five other reports you filed today -- it's not clear what the perl
program was that you used to generated the error or crash.

Could you please *attach* the program you used to this ticket (or to
your email response)?

And do so likewise for the other five tickets?

Thank you very much.

Hi James,
I get the source code of Perl 5 on https://perl5.git.perl.org/perl.git. I compiled Perl (the latest commit 45f8e7b on the branch blead) using gcc (Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010 on Ubuntu 16.04 64-bit as follows​:

git clone git​://perl5.git.perl.org/perl.git perl-head

git log -n 1 HEAD
commit 45f8e7b
Author​: Karl Williamson <khw@​cpan.org>
Date​: Wed Jul 31 13​:35​:55 2019 -0600

  autodoc.pl​: Forget heuristics, we have a flag
 
  We know if something is a macro because of the 'm' flag. Don't use the
  fallible heuristics to try to determine this.

cd perl-head;
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g" -Dloclibpth=' '
# build with ASAN
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-fsanitize=address -g" -Dldflags="-fsanitize=address" -Dloclibpth=' '
make -j4
make test # output​: https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/make_test.log

Then, we have binaries as follows​:
- Binary of perl​: https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/perl
- Binary of perl with ASAN​: https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/perl-asan
./perl -v
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-48-g45f8e7b)) built for x86_64-linux

I tested the latest version of Perl (commit 45f8e7b and also the newest version 5.31.2) and still triggered all bugs I have reported (#134322; #134324; #134325; #134326; #134327; #134328; #134329).
I hope you could reproduce these bugs on your side. Please let me know if you have any further questions.

Thanks,
Manh Dung

@p5pRT
Copy link
Author

p5pRT commented Aug 1, 2019

From nguyenmanhdung1710@gmail.com

On Thu, 01 Aug 2019 00​:16​:00 -0700, nguyenmanhdung1710@​gmail.com wrote​:

Hi All,
I found a Use-After-Free bug in the commit *a3c7756* on branch *blead*.
This bug causes Perl to crash. I use gcc v5.5.0 to compile Perl on Ubuntu
16.04 (64 bit) as follows​:
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g" -Dloclibpth='
'; make

Thanks,
Manh Dung

======================================
*perl -v*
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-37-ga3c7756))
built for x86_64-linux

- Crafted PoC​:
https://github.com/strongcourage/PoCs/blob/master/perl_82007f7/PoC_hbo
- Command​: perl $PoC

ASAN says​:
==25324==ERROR​: AddressSanitizer​: heap-buffer-overflow on address
0x7f0d2e16a7e5 at pc 0x00000058a4eb bp 0x7fff7ef03880 sp 0x7fff7ef03870
READ of size 1 at 0x7f0d2e16a7e5 thread T0
#0 0x58a4ea in S_reg
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12238
#1 0x57112d in S_regatom
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:13370
#2 0x57112d in S_regpiece
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12473
#3 0x57df9e in S_regbranch
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12393
#4 0x57ef49 in S_reg
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12148
#5 0x58bd22 in Perl_re_op_compile
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:7721
#6 0x6b1a24 in Perl_pp_regcomp
/home/dungnguyen/gueb-testing/perl-head/pp_ctl.c​:108
#7 0x5fa20a in Perl_runops_standard
/home/dungnguyen/gueb-testing/perl-head/run.c​:41
#8 0x48f0b7 in S_run_body
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2696
#9 0x48f0b7 in perl_run
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2624
#10 0x425674 in main
/home/dungnguyen/gueb-testing/perl-head/perlmain.c​:127
#11 0x7f0d34c2b82f in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#12 0x425be8 in _start
(/home/dungnguyen/PoCs/perl_82007f7/perl-asan+0x425be8)

0x7f0d2e16a7e5 is located 27 bytes to the left of 1197244-byte region
[0x7f0d2e16a800,0x7f0d2e28ecbc)
freed by thread T0 here​:
#0 0x7f0d359cf9c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

previously allocated by thread T0 here​:
#0 0x7f0d359cf9c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

As requested by James E Keenan, I add the binaries of Perl (commit 45f8e7b on the branch blead)​:
- Perl​: https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/perl
- Perl with ASAN​: https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/perl-asan

@p5pRT
Copy link
Author

p5pRT commented Aug 2, 2019

From nguyenmanhdung1710@gmail.com

Hi James,
I get the source code of Perl 5 on https://perl5.git.perl.org/perl.git. I
compiled Perl (the latest commit *45f8e7b* on the branch *blead*) using gcc
(Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010 on Ubuntu 16.04 64-bit as
follows​:

git clone git​://perl5.git.perl.org/perl.git perl-head

*git log -n 1 HEAD*
commit 45f8e7b
Author​: Karl Williamson <khw@​cpan.org>
Date​: Wed Jul 31 13​:35​:55 2019 -0600

  autodoc.pl​: Forget heuristics, we have a flag

  We know if something is a macro because of the 'm' flag. Don't use the
  fallible heuristics to try to determine this.

cd perl-head;
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g" -Dloclibpth=' '
# build with ASAN
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-fsanitize=address
-g" -Dldflags="-fsanitize=address" -Dloclibpth=' '
make -j4
make test # output​:
https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/make_test.log

Then, we have binaries as follows​:
- Binary of perl​:
https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/perl
- Binary of perl with ASAN​:
https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/perl-asan
*./perl -v*
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-48-g45f8e7b))
built for x86_64-linux

I tested the latest version of Perl (commit *45f8e7b*) and still triggered
all bugs I have reported (#134322; #134324; #134325; #134326; #134327;
#134328; #134329).
I hope you could reproduce these bugs on your side. Please let me know if
you have any further questions.

Thanks,
Manh Dung

Le jeu. 1 août 2019 à 20​:25, James E Keenan via RT <
perlbug-followup@​perl.org> a écrit :

On Thu, 01 Aug 2019 07​:15​:46 GMT, nguyenmanhdung1710@​gmail.com wrote​:

Hi All,
I found a Use-After-Free bug in the commit *a3c7756* on branch
*blead*.
This bug causes Perl to crash. I use gcc v5.5.0 to compile Perl on
Ubuntu
16.04 (64 bit) as follows​:
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g"
-Dloclibpth='
'; make

Thanks,
Manh Dung

======================================
*perl -v*
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-37-
ga3c7756))
built for x86_64-linux

- Crafted PoC​:

https://github.com/strongcourage/PoCs/blob/master/perl_82007f7/PoC_uaf_regcomp.c:12238

- Command​: perl $PoC

ASAN says​:
==25228==ERROR​: AddressSanitizer​: heap-use-after-free on address
0x7fdd62cd4e35 at pc 0x00000058a4eb bp 0x7ffdd5a06710 sp
0x7ffdd5a06700
READ of size 1 at 0x7fdd62cd4e35 thread T0
#0 0x58a4ea in S_reg
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12238
#1 0x58bd22 in Perl_re_op_compile
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:7721
#2 0x6b1a24 in Perl_pp_regcomp
/home/dungnguyen/gueb-testing/perl-head/pp_ctl.c​:108
#3 0x5fa20a in Perl_runops_standard
/home/dungnguyen/gueb-testing/perl-head/run.c​:41
#4 0x48f0b7 in S_run_body
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2696
#5 0x48f0b7 in perl_run
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2624
#6 0x425674 in main
/home/dungnguyen/gueb-testing/perl-head/perlmain.c​:127
#7 0x7fdd71f9082f in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#8 0x425be8 in _start
(/home/dungnguyen/PoCs/perl_82007f7/perl-asan+0x425be8)

0x7fdd62cd4e35 is located 13877 bytes inside of 617548-byte region
[0x7fdd62cd1800,0x7fdd62d6844c)
freed by thread T0 here​:
#0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

previously allocated by thread T0 here​:
#0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

Thank you for this report. However, in this report -- as well as the five
other reports you filed today -- it's not clear what the perl program was
that you used to generated the error or crash.

Could you please *attach* the program you used to this ticket (or to your
email response)?

And do so likewise for the other five tickets?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Aug 2, 2019

From nguyenmanhdung1710@gmail.com

On Thu, 01 Aug 2019 21​:21​:28 -0700, nguyenmanhdung1710@​gmail.com wrote​:

Hi James,
I get the source code of Perl 5 on
https://perl5.git.perl.org/perl.git. I
compiled Perl (the latest commit *45f8e7b* on the branch *blead*)
using gcc
(Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010 on Ubuntu 16.04 64-bit
as
follows​:

git clone git​://perl5.git.perl.org/perl.git perl-head

*git log -n 1 HEAD*
commit 45f8e7b
Author​: Karl Williamson <khw@​cpan.org>
Date​: Wed Jul 31 13​:35​:55 2019 -0600

autodoc.pl​: Forget heuristics, we have a flag

We know if something is a macro because of the 'm' flag. Don't use
the
fallible heuristics to try to determine this.

cd perl-head;
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g"
-Dloclibpth=' '
# build with ASAN
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-
fsanitize=address
-g" -Dldflags="-fsanitize=address" -Dloclibpth=' '
make -j4
make test # output​:
https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/make_test.log

Then, we have binaries as follows​:
- Binary of perl​:
https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/perl
- Binary of perl with ASAN​:
https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/perl-
asan
*./perl -v*
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-48-
g45f8e7b))
built for x86_64-linux

I tested the latest version of Perl (commit *45f8e7b*) and still
triggered
all bugs I have reported (#134322; #134324; #134325; #134326; #134327;
#134328; #134329).
I hope you could reproduce these bugs on your side. Please let me know
if
you have any further questions.

Thanks,
Manh Dung

Le jeu. 1 août 2019 à 20​:25, James E Keenan via RT <
perlbug-followup@​perl.org> a écrit :

On Thu, 01 Aug 2019 07​:15​:46 GMT, nguyenmanhdung1710@​gmail.com wrote​:

Hi All,
I found a Use-After-Free bug in the commit *a3c7756* on branch
*blead*.
This bug causes Perl to crash. I use gcc v5.5.0 to compile Perl on
Ubuntu
16.04 (64 bit) as follows​:
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g"
-Dloclibpth='
'; make

Thanks,
Manh Dung

======================================
*perl -v*
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-37-
ga3c7756))
built for x86_64-linux

- Crafted PoC​:

https://github.com/strongcourage/PoCs/blob/master/perl_82007f7/PoC_uaf_regcomp.c:12238

- Command​: perl $PoC

ASAN says​:
==25228==ERROR​: AddressSanitizer​: heap-use-after-free on address
0x7fdd62cd4e35 at pc 0x00000058a4eb bp 0x7ffdd5a06710 sp
0x7ffdd5a06700
READ of size 1 at 0x7fdd62cd4e35 thread T0
#0 0x58a4ea in S_reg
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12238
#1 0x58bd22 in Perl_re_op_compile
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:7721
#2 0x6b1a24 in Perl_pp_regcomp
/home/dungnguyen/gueb-testing/perl-head/pp_ctl.c​:108
#3 0x5fa20a in Perl_runops_standard
/home/dungnguyen/gueb-testing/perl-head/run.c​:41
#4 0x48f0b7 in S_run_body
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2696
#5 0x48f0b7 in perl_run
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2624
#6 0x425674 in main
/home/dungnguyen/gueb-testing/perl-head/perlmain.c​:127
#7 0x7fdd71f9082f in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#8 0x425be8 in _start
(/home/dungnguyen/PoCs/perl_82007f7/perl-asan+0x425be8)

0x7fdd62cd4e35 is located 13877 bytes inside of 617548-byte region
[0x7fdd62cd1800,0x7fdd62d6844c)
freed by thread T0 here​:
#0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

previously allocated by thread T0 here​:
#0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

Thank you for this report. However, in this report -- as well as the
five
other reports you filed today -- it's not clear what the perl program
was
that you used to generated the error or crash.

Could you please *attach* the program you used to this ticket (or to
your
email response)?

And do so likewise for the other five tickets?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

Hi James,

Sorry, I misunderstood your question. I found these bugs using fuzzing, hence the PoC inputs are crafted. I will try to create Perl programs triggering these bugs, but it is not easy for me. Also, by looking at the stacktrace, I think we can understand the root cause and propose patches.

Thanks,
Manh Dung

@p5pRT
Copy link
Author

p5pRT commented Aug 12, 2019

From @tonycoz

Attached the PoC to save people time.

@p5pRT
Copy link
Author

p5pRT commented Aug 12, 2019

From @tonycoz

134325.pl

@p5pRT
Copy link
Author

p5pRT commented Aug 12, 2019

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Aug 12, 2019

From @hvds

On Sun, 11 Aug 2019 23​:09​:07 -0700, tonyc wrote​:

Attached the PoC to save people time.

Here's a shorter version. I was unaware of the compounding effect of multiple \Q - I would have expected "\Q\Q+" to result in '\Q\+' rather than '\\\+' - and I suspect the long string resulting is a prime mover in this bug.

perl -e '
  $quote="\\Q";
  $back="\\\\";
  $ff="\xff";
  printf "/\\1|(|%s)%s%s /i",
  $quote x 8 . $back x 69,
  $quote x 5 . $back x 4,
  $ff x 48
' | ./miniperl

Hugo

@p5pRT
Copy link
Author

p5pRT commented Aug 12, 2019

From @hvds

On Mon, 12 Aug 2019 05​:46​:19 -0700, hv wrote​:

I was unaware of the compounding effect of
multiple \Q - I would have expected "\Q\Q+" to result in '\Q\+' rather
than '\\\+'

Er, I would have expected '\\Q\+', I mean.

@p5pRT
Copy link
Author

p5pRT commented Aug 12, 2019

From @khwilliamson

I vaguely recall an issue with \Q compounding years ago

Sent from my iPhone

On Aug 12, 2019, at 6​:47 AM, Hugo van der Sanden via RT <perlbug-followup@​perl.org> wrote​:

On Mon, 12 Aug 2019 05​:46​:19 -0700, hv wrote​:
I was unaware of the compounding effect of
multiple \Q - I would have expected "\Q\Q+" to result in '\Q\+' rather
than '\\\+'

Er, I would have expected '\\Q\+', I mean.

---
via perlbug​: queue​: perl5 status​: open
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=134325

@p5pRT
Copy link
Author

p5pRT commented Aug 12, 2019

From @hvds

On Mon, 12 Aug 2019 05​:46​:19 -0700, hv wrote​:

Here's a shorter version.

perl -e '
$quote="\\Q";
$back="\\\\";
$ff="\xff";
printf "/\\1|(|%s)%s%s /i",
$quote x 8 . $back x 69,
$quote x 5 . $back x 4,
$ff x 48
' | ./miniperl

We can simplify the printf pattern to "/\\1|%s%s%s /i", and we can also replace "\xff" with "\\xff" leaving us just simple ascii to pass around.

Starting to trace this through, I note that the removal of the sizing pass appears to lead to under-allocation of RExC_rxi up front - RExC_size is counted in regnodes, but we allocate only that many chars. Fixing that doesn't solve this out-of-bounds read, but I imagine we probably want it in any case .

I have a feeling Tony commented on this already, but I can't find the message - Karl, have you looked at this already?

Hugo

Inline Patch
diff --git a/regcomp.c b/regcomp.c
index cf9246473f..f8bef77f0b 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -7671,11 +7671,11 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
         RExC_size = STR_SZ(RExC_end - RExC_start);
     }
 
-    Newxc(RExC_rxi, sizeof(regexp_internal) + RExC_size, char, regexp_internal);
+    Newxc(RExC_rxi, sizeof(regexp_internal) + RExC_size * sizeof(regnode), char, regexp_internal);
     if ( RExC_rxi == NULL )
         FAIL("Regexp out of space");
 
-    Zero(RExC_rxi, sizeof(regexp_internal) + RExC_size, char);
+    Zero(RExC_rxi, sizeof(regexp_internal) + RExC_size * sizeof(regnode), char);
     RXi_SET( RExC_rx, RExC_rxi );
 
     /* We start from 0 (over from 0 in the case this is a reparse.  The first

@p5pRT
Copy link
Author

p5pRT commented Aug 12, 2019

From @tonycoz

On Mon, Aug 12, 2019 at 07​:35​:59AM -0700, Hugo van der Sanden via RT wrote​:

On Mon, 12 Aug 2019 05​:46​:19 -0700, hv wrote​:

Here's a shorter version.

perl -e '
$quote="\\Q";
$back="\\\\";
$ff="\xff";
printf "/\\1|(|%s)%s%s /i",
$quote x 8 . $back x 69,
$quote x 5 . $back x 4,
$ff x 48
' | ./miniperl

We can simplify the printf pattern to "/\\1|%s%s%s /i", and we can also replace "\xff" with "\\xff" leaving us just simple ascii to pass around.

Starting to trace this through, I note that the removal of the sizing pass appears to lead to under-allocation of RExC_rxi up front - RExC_size is counted in regnodes, but we allocate only that many chars. Fixing that doesn't solve this out-of-bounds read, but I imagine we probably want it in any case .

I have a feeling Tony commented on this already, but I can't find the message - Karl, have you looked at this already?

That was against #134329, which feels similar to this.

After some discussion with Karl in IRC the bytes vs regnodes shouldn't
be a problem, since RExC_size is set to zero almost immediately after
this, the program is reallocated in regnodes before anything else much
happens.

Tony

@p5pRT
Copy link
Author

p5pRT commented Aug 13, 2019

From @tonycoz

On Mon, 12 Aug 2019 07​:27​:10 -0700, khw@​indra.com wrote​:

I vaguely recall an issue with \Q compounding years ago

Possibly #133921, which also bisected to 7c932d0 and was fixed in bf848a1.

Tony

@p5pRT
Copy link
Author

p5pRT commented Aug 23, 2019

From @khwilliamson

On Mon, 12 Aug 2019 05​:47​:29 -0700, hv wrote​:

On Mon, 12 Aug 2019 05​:46​:19 -0700, hv wrote​:

I was unaware of the compounding effect of
multiple \Q - I would have expected "\Q\Q+" to result in '\Q\+' rather
than '\\\+'

Er, I would have expected '\\Q\+', I mean.

Using Tony's, case, this is not the same thing as #134329.

But again, it's caused by the same lack of switching to long jumps. To reduce the number of passes, if we're already having to do a pass because we need to count the parenthetical groups, the code doesn't restart immediately when it decides it needs to use long jumps. This works, except in a few cases, it can't really keep going. And this ticket is one of them.

The easiest thing is to restart immediately even when counting parens. This adds a pass. The other way would be to restart immediately only in those cases where it might be needed. I have to examine the code to decide how clear cut that is. If it isn't, err on the side of safety and always restart immediately.
--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented Aug 23, 2019

From @khwilliamson

On Mon, 12 Aug 2019 07​:49​:58 -0700, tonyc wrote​:

After some discussion with Karl in IRC the bytes vs regnodes shouldn't
be a problem, since RExC_size is set to zero almost immediately after
this, the program is reallocated in regnodes before anything else much
happens.

Tony

No this isn't the cause of the problems. I had thought the comments explained it adequately​:

  /* On the first pass of the parse, we guess how big this will be. Then
  * we grow in one operation to that amount and then give it back. As
  * we go along, we re-allocate what we need.
  *
  * XXX Currently the guess is essentially that the pattern will be an
  * EXACT node with one byte input, one byte output. This is crude, and
  * better heuristics are welcome.
  *
  * On any subsequent passes, we guess what we actually computed in the
  * latest earlier pass. Such a pass probably didn't complete so is
  * missing stuff. We could improve those guesses by knowing where the
  * parse stopped, and use the length so far plus apply the above
  * assumption to what's left. */

The point of this is to allocate a bunch of memory in one gulp. Then we give it back, and hope that the system isn't so busy that other processes gobble it up, as we allocate what we actually need as we go along parsing.

I used the guess of one output byte + overhead per one input byte. That's the only thing we know about the string at this point​: its length. I have changed other places in the core to do the same. But better heuristics are welcome. On small patterns, whatever we do won't matter much, but on larger patterns, my guess is that much of that space is literal characters that need to be matched, like in DNA sequences. So I think this is a reasonable guess. We could omit this entirely, of course. But by doing it, we make sure that the system has a sufficient amount of memory available at the beginning, and I think we reduce the number of mallocs that actually go out and have to consolidate free space.

--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented Aug 26, 2019

From @tonycoz

On Fri, 23 Aug 2019 13​:37​:55 -0700, khw wrote​:

On Mon, 12 Aug 2019 07​:49​:58 -0700, tonyc wrote​:

After some discussion with Karl in IRC the bytes vs regnodes
shouldn't
be a problem, since RExC_size is set to zero almost immediately after
this, the program is reallocated in regnodes before anything else
much
happens.

Tony

No this isn't the cause of the problems. I had thought the comments
explained it adequately​:

/* On the first pass of the parse, we guess how big this will be.
Then
* we grow in one operation to that amount and then give it back. As
* we go along, we re-allocate what we need.
*
* XXX Currently the guess is essentially that the pattern will be an
* EXACT node with one byte input, one byte output. This is crude,
and
* better heuristics are welcome.
*
* On any subsequent passes, we guess what we actually computed in the
* latest earlier pass. Such a pass probably didn't complete so is
* missing stuff. We could improve those guesses by knowing where the
* parse stopped, and use the length so far plus apply the above
* assumption to what's left. */

The point of this is to allocate a bunch of memory in one gulp. Then
we give it back, and hope that the system isn't so busy that other
processes gobble it up, as we allocate what we actually need as we go
along parsing.

I used the guess of one output byte + overhead per one input byte.
That's the only thing we know about the string at this point​: its
length. I have changed other places in the core to do the same. But
better heuristics are welcome.

If I understand a minimal exact match regexp will have 3 nodes​:

- the REG_MAGIC node at the front (regcomp.c​:7717), but this is included in the size of the regexp_internal structure, so we don't need to count it)
- an EXACT node followed by the match text
- an END node

so a better initial allocation might be to allocate 2 nodes plus the nodes needed for the text.

Right now for a 1 to 4 length input we allocate only enough for regexp_internal with it's built-in zeroth node, and 1 byte more.

As soon as we try to emit something that will be reallocated, and if the end of program[] is on an allocation boundary that requires a new block to be allocated (as opposed to there being enough free space in the block).

All that said, the performance impact is a single realloc() per compiled regexp, so it shouldn't be a big deal.

I suspect the structure of change_engine_size() is more of a problem, since it (and its callers) mostly seem to allocate what's needed right now, so emitting 100 nodes might end up doing 100 realloc calls.

$ gdb --args ./miniperl -Dr -e '/\w\W+\w+/'
...
(gdb) b S_change_engine_size
Breakpoint 1 at 0x178bcb​: file regcomp.c, line 19654.
(gdb) r
Starting program​: /home/tony/dev/perl/git/perl/miniperl -Dr -e /\\w\\W+\\w+/
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Compiling REx "\w\W+\w+"

Breakpoint 1, S_change_engine_size (pRExC_state=0x7fffffffdd10, size=1)
  at regcomp.c​:19654
19654 PERL_ARGS_ASSERT_CHANGE_ENGINE_SIZE;
(gdb) c
Continuing.

Breakpoint 1, S_change_engine_size (pRExC_state=0x7fffffffdd10, size=1)
  at regcomp.c​:19654
19654 PERL_ARGS_ASSERT_CHANGE_ENGINE_SIZE;
(gdb) c
Continuing.

Breakpoint 1, S_change_engine_size (pRExC_state=0x7fffffffdd10, size=1)
  at regcomp.c​:19654
19654 PERL_ARGS_ASSERT_CHANGE_ENGINE_SIZE;
(gdb) c
Continuing.

Breakpoint 1, S_change_engine_size (pRExC_state=0x7fffffffdd10, size=1)
  at regcomp.c​:19654
19654 PERL_ARGS_ASSERT_CHANGE_ENGINE_SIZE;
(gdb) c
Continuing.

Breakpoint 1, S_change_engine_size (pRExC_state=0x7fffffffdd10, size=1)
  at regcomp.c​:19654
19654 PERL_ARGS_ASSERT_CHANGE_ENGINE_SIZE;
(gdb) c
Continuing.

Breakpoint 1, S_change_engine_size (pRExC_state=0x7fffffffdd10, size=1)
  at regcomp.c​:19654
19654 PERL_ARGS_ASSERT_CHANGE_ENGINE_SIZE;
(gdb) c
Continuing.
~ tying lastbr POSIXD[\w] (1) to ender END (6) offset 5

(exactish nodes allocate 64 nodes to start with and cause less churn.)

On small patterns, whatever we do
won't matter much, but on larger patterns, my guess is that much of
that space is literal characters that need to be matched, like in DNA
sequences. So I think this is a reasonable guess. We could omit this
entirely, of course.

But by doing it, we make sure that the system
has a sufficient amount of memory available at the beginning, and I
think we reduce the number of mallocs that actually go out and have to
consolidate free space.

I think allocating a bit more space wouldn't hurt, any extra space is returned if the realloc implementation supports it.

Tony

@p5pRT
Copy link
Author

p5pRT commented Aug 27, 2019

From @khwilliamson

Fixed by 439a3bf

Thanks for finding and reporting this
--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented Aug 27, 2019

@khwilliamson - Status changed from 'open' to 'pending release'

@p5pRT p5pRT closed this as completed Aug 27, 2019
@p5pRT
Copy link
Author

p5pRT commented Aug 27, 2019

From nguyenmanhdung1710@gmail.com

On Mon, 26 Aug 2019 21​:01​:25 -0700, khw wrote​:

Fixed by 439a3bf

Thanks for finding and reporting this

Thanks for the patch. Do you think it is an exploitable bug? Can I request a CVE for this bug?

@p5pRT
Copy link
Author

p5pRT commented Aug 30, 2019

From @khwilliamson

On Thu, 01 Aug 2019 22​:31​:26 -0700, nguyenmanhdung1710@​gmail.com wrote​:

On Thu, 01 Aug 2019 21​:21​:28 -0700, nguyenmanhdung1710@​gmail.com
wrote​:

Hi James,
I get the source code of Perl 5 on
https://perl5.git.perl.org/perl.git. I
compiled Perl (the latest commit *45f8e7b* on the branch *blead*)
using gcc
(Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010 on Ubuntu 16.04 64-bit
as
follows​:

git clone git​://perl5.git.perl.org/perl.git perl-head

*git log -n 1 HEAD*
commit 45f8e7b
Author​: Karl Williamson <khw@​cpan.org>
Date​: Wed Jul 31 13​:35​:55 2019 -0600

autodoc.pl​: Forget heuristics, we have a flag

We know if something is a macro because of the 'm' flag. Don't use
the
fallible heuristics to try to determine this.

cd perl-head;
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g"
-Dloclibpth=' '
# build with ASAN
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-
fsanitize=address
-g" -Dldflags="-fsanitize=address" -Dloclibpth=' '
make -j4
make test # output​:
https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/make_test.log

Then, we have binaries as follows​:
- Binary of perl​:
https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/perl
- Binary of perl with ASAN​:
https://github.com/strongcourage/PoCs/blob/master/perl_45f8e7b/perl-
asan
*./perl -v*
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-48-
g45f8e7b))
built for x86_64-linux

I tested the latest version of Perl (commit *45f8e7b*) and still
triggered
all bugs I have reported (#134322; #134324; #134325; #134326;
#134327;
#134328; #134329).
I hope you could reproduce these bugs on your side. Please let me
know
if
you have any further questions.

Thanks,
Manh Dung

Le jeu. 1 août 2019 à 20​:25, James E Keenan via RT <
perlbug-followup@​perl.org> a écrit :

On Thu, 01 Aug 2019 07​:15​:46 GMT, nguyenmanhdung1710@​gmail.com
wrote​:

Hi All,
I found a Use-After-Free bug in the commit *a3c7756* on branch
*blead*.
This bug causes Perl to crash. I use gcc v5.5.0 to compile Perl
on
Ubuntu
16.04 (64 bit) as follows​:
./Configure -des -Dusedevel -Dprefix=`pwd` -Dccflags="-g"
-Dloclibpth='
'; make

Thanks,
Manh Dung

======================================
*perl -v*
This is perl 5, version 31, subversion 3 (v5.31.3 (v5.31.2-37-
ga3c7756))
built for x86_64-linux

- Crafted PoC​:

https://github.com/strongcourage/PoCs/blob/master/perl_82007f7/PoC_uaf_regcomp.c:12238

- Command​: perl $PoC

ASAN says​:
==25228==ERROR​: AddressSanitizer​: heap-use-after-free on address
0x7fdd62cd4e35 at pc 0x00000058a4eb bp 0x7ffdd5a06710 sp
0x7ffdd5a06700
READ of size 1 at 0x7fdd62cd4e35 thread T0
#0 0x58a4ea in S_reg
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:12238
#1 0x58bd22 in Perl_re_op_compile
/home/dungnguyen/gueb-testing/perl-head/regcomp.c​:7721
#2 0x6b1a24 in Perl_pp_regcomp
/home/dungnguyen/gueb-testing/perl-head/pp_ctl.c​:108
#3 0x5fa20a in Perl_runops_standard
/home/dungnguyen/gueb-testing/perl-head/run.c​:41
#4 0x48f0b7 in S_run_body
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2696
#5 0x48f0b7 in perl_run
/home/dungnguyen/gueb-testing/perl-head/perl.c​:2624
#6 0x425674 in main
/home/dungnguyen/gueb-testing/perl-head/perlmain.c​:127
#7 0x7fdd71f9082f in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#8 0x425be8 in _start
(/home/dungnguyen/PoCs/perl_82007f7/perl-asan+0x425be8)

0x7fdd62cd4e35 is located 13877 bytes inside of 617548-byte
region
[0x7fdd62cd1800,0x7fdd62d6844c)
freed by thread T0 here​:
#0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

previously allocated by thread T0 here​:
#0 0x7fdd72d349c1 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.2+0x989c1)
#1 0x5aa2b1 in Perl_safesysrealloc
/home/dungnguyen/gueb-testing/perl-head/util.c​:279

Thank you for this report. However, in this report -- as well as
the
five
other reports you filed today -- it's not clear what the perl
program
was
that you used to generated the error or crash.

Could you please *attach* the program you used to this ticket (or
to
your
email response)?

And do so likewise for the other five tickets?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

Hi James,

Sorry, I misunderstood your question. I found these bugs using
fuzzing, hence the PoC inputs are crafted. I will try to create Perl
programs triggering these bugs, but it is not easy for me. Also, by
looking at the stacktrace, I think we can understand the root cause
and propose patches.

Thanks,
Manh Dung

This was fixed by

commit 439a3bf
Author​: Karl Williamson <khw@​cpan.org>
Date​: Sat Aug 24 19​:17​:19 2019 -0600

  PATCH​: [perl #134325] Heap buffer overflow

so I'm merging this ticket into that ticket
--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2019

From nguyenmanhdung1710@gmail.com

Thanks for the patch. Do you think it is an exploitable bug? Can I request
a CVE for this bug?

Le mar. 27 août 2019 à 06​:01, Karl Williamson via RT <
perlbug-followup@​perl.org> a écrit :

Fixed by 439a3bf

Thanks for finding and reporting this
--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented Sep 19, 2019

From @xsawyerx

On Sat, 31 Aug 2019 11​:15​:36 -0700, nguyenmanhdung1710@​gmail.com wrote​:

Thanks for the patch. Do you think it is an exploitable bug? Can I request
a CVE for this bug?

Hi,

I'm quoting Tony Cook here​:

  All cases for both tickets are bad reads, either of freed memory, or
  beyond the end of a buffer.

  None of the reads result in returning data to a potential attacker
  that I can see.

  According to our usual criteria such reads aren't a security issue.

  Can an attacker craft a regexp with data at the offset 65535 point to
  do undesirable things? Could they make the engine loop at regexp
  compile time or runtime so control isn't returned to the calling perl
  code?

  I'm not sure.

While we are looking into this, we would appreciate any help in proving this. If we can answer Tony's questions, we can discern better if this suits as a security issue.

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

1 participant