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

SIGSEGV in Perl_sv_resetpvn when "reset" catches a sub #15314

Closed
p5pRT opened this issue May 9, 2016 · 8 comments

Comments

@p5pRT
Copy link

commented May 9, 2016

Migrated from rt.perl.org#128106 (status was 'resolved')

Searchable as RT128106$

@p5pRT

This comment has been minimized.

Copy link
Author

commented May 9, 2016

From @dcollinsn

Greetings Porters,

I have compiled bleadperl with the afl-gcc compiler using​:

./Configure -Dusedevel -Dprefix='/usr/local/perl-afl' -Dcc='ccache afl-gcc' -Uuselongdouble -Duse64bitall -Doptimize=-g -Uversiononly -Uman1dir -Uman3dir -Dusequadmath -des
AFL_HARDEN=1 make && make test

And then fuzzed the resulting binary using​:

AFL_NO_VAR_CHECK=1 afl-fuzz -i in -o out bin/perl @​@​

After reducing testcases using `afl-tmin` and performing additional minimization by hand, I have located the following testcase that triggers a segmentation fault in the perl interpreter. The testcase is the 15-character file​:

0,reset u;sub u

On normal builds, this crashes with a segmentation fault. On debug builds, this returns a segmentation fault.

dcollins@​nightshade64​:~/perl$ ~/perl/perl -e 'reset u;sub u'
Segmentation fault
dcollins@​nightshade64​:~/perl$ ~/perldebug/perl -e 'reset u;sub u'
perl​: sv.c​:9707​: Perl_sv_resetpvn​: Assertion `((svtype)((_gvgp)->sv_flags & 0xff)) == SVt_PVGV || ((svtype)((_gvgp)->sv_flags & 0xff)) == SVt_PVLV' failed.
Aborted

Debugging tool output is below. This bug exists at least going back to my installed system perl, 5.20.2.

**GDB**

dcollins@​nightshade64​:~/perl$ gdb --args ~/perl/perl -e 'reset u;sub u' GNU gdb (GDB) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+​: GNU GPL version 3 or later <http​://gnu.org/licenses/gpl.html>
This is free software​: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see​:
<http​://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at​:
<http​://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/dcollins/perl/perl...done.
(gdb) run
Starting program​: /home/dcollins/perl/perl -e reset\ u\;sub\ u
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00000000008339f4 in Perl_sv_resetpvn (s=<optimized out>,
  len=<optimized out>, stash=0xe84ec8) at sv.c​:9707
9707 sv = GvSV(gv);
(gdb) bt
#0 0x00000000008339f4 in Perl_sv_resetpvn (s=<optimized out>,
  len=<optimized out>, stash=0xe84ec8) at sv.c​:9707
#1 0x000000000091b8b4 in Perl_pp_reset () at pp_ctl.c​:1966
#2 0x000000000079148b in Perl_runops_standard () at run.c​:41
#3 0x00000000004ebf9f in S_run_body (oldscope=1) at perl.c​:2483
#4 perl_run (my_perl=<optimized out>) at perl.c​:2406
#5 0x00000000004276a8 in main (argc=3, argv=0x7fffffffe668,
  env=0x7fffffffe688) at perlmain.c​:116
(gdb) info locals
gv = 0xe997d8
sv = <optimized out>
entry = 0xe8fc60
max = <optimized out>
i = 19
todo = '\000' <repeats 117 times>, "\001", '\000' <repeats 137 times>
send = 0xea1fe1 ""
stash = 0xe84ec8
len = <optimized out>
s = 0xea1fe1 ""
(gdb)

dcollins@​nightshade64​:~/perl$ gdb --args ~/perldebug/perl -e 'reset u;sub u'
GNU gdb (GDB) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+​: GNU GPL version 3 or later <http​://gnu.org/licenses/gpl.html>
This is free software​: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see​:
<http​://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at​:
<http​://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/dcollins/perldebug/perl...done.
(gdb) run
Starting program​: /home/dcollins/perldebug/perl -e reset\ u\;sub\ u
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
perl​: sv.c​:9707​: Perl_sv_resetpvn​: Assertion `((svtype)((_gvgp)->sv_flags & 0xff)) == SVt_PVGV || ((svtype)((_gvgp)->sv_flags & 0xff)) == SVt_PVLV' failed.

Program received signal SIGABRT, Aborted.
0x00007ffff6cf4107 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0 0x00007ffff6cf4107 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff6cf54e8 in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff6ced226 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3 0x00007ffff6ced2d2 in __assert_fail ()
  from /lib/x86_64-linux-gnu/libc.so.6
#4 0x00000000009f2b4d in Perl_sv_resetpvn (s=0x120f731 "",
  len=<optimized out>, stash=0x11f1ec8) at sv.c​:9707
#5 0x00000000009f2f1d in Perl_sv_resetpvn (s=<optimized out>,
  len=<optimized out>, stash=<optimized out>) at sv.c​:9721
#6 0x0000000000b83994 in Perl_pp_reset () at pp_ctl.c​:1966
#7 0x00000000007e4324 in Perl_runops_debug () at dump.c​:2239
#8 0x0000000000534e01 in S_run_body (oldscope=1) at perl.c​:2483
#9 perl_run (my_perl=<optimized out>) at perl.c​:2406
#10 0x0000000000428e48 in main (argc=3, argv=0x7fffffffe658,
  env=0x7fffffffe678) at perlmain.c​:116
(gdb) f 4
#4 0x00000000009f2b4d in Perl_sv_resetpvn (s=0x120f731 "",
  len=<optimized out>, stash=0x11f1ec8) at sv.c​:9707
9707 sv = GvSV(gv);
(gdb) info locals
_gvgp = 0x12068e8
gv = 0x12068e8
sv = <optimized out>
entry = 0x11fcd70
max = <optimized out>
i = 31
todo = '\000' <repeats 117 times>, "\001", '\000' <repeats 137 times>
send = 0x120f731 ""
(gdb)

**VALGRIND**

dcollins@​nightshade64​:~/perl$ valgrind ~/perl/perl -e 'reset u;sub u'
==41582== Memcheck, a memory error detector
==41582== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==41582== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==41582== Command​: /home/dcollins/perl/perl -e reset\ u;sub\ u
==41582==
==41582== Invalid read of size 8
==41582== at 0x8339F4​: Perl_sv_resetpvn (sv.c​:9707)
==41582== by 0x91B8B3​: Perl_pp_reset (pp_ctl.c​:1966)
==41582== by 0x79148A​: Perl_runops_standard (run.c​:41)
==41582== by 0x4EBF9E​: S_run_body (perl.c​:2483)
==41582== by 0x4EBF9E​: perl_run (perl.c​:2406)
==41582== by 0x4276A7​: main (perlmain.c​:116)
==41582== Address 0xffffffffffffffff is not stack'd, malloc'd or (recently) free'd
==41582==
==41582==
==41582== Process terminating with default action of signal 11 (SIGSEGV)
==41582== Access not within mapped region at address 0xFFFFFFFFFFFFFFFF
==41582== at 0x8339F4​: Perl_sv_resetpvn (sv.c​:9707)
==41582== by 0x91B8B3​: Perl_pp_reset (pp_ctl.c​:1966)
==41582== by 0x79148A​: Perl_runops_standard (run.c​:41)
==41582== by 0x4EBF9E​: S_run_body (perl.c​:2483)
==41582== by 0x4EBF9E​: perl_run (perl.c​:2406)
==41582== by 0x4276A7​: main (perlmain.c​:116)
==41582== If you believe this happened as a result of a stack
==41582== overflow in your program's main thread (unlikely but
==41582== possible), you can try to increase the size of the
==41582== main thread stack using the --main-stacksize= flag.
==41582== The main thread stack size used in this run was 8388608.
==41582==
==41582== HEAP SUMMARY​:
==41582== in use at exit​: 108,767 bytes in 536 blocks
==41582== total heap usage​: 640 allocs, 104 frees, 124,007 bytes allocated
==41582==
==41582== LEAK SUMMARY​:
==41582== definitely lost​: 176 bytes in 1 blocks
==41582== indirectly lost​: 1,972 bytes in 20 blocks
==41582== possibly lost​: 0 bytes in 0 blocks
==41582== still reachable​: 106,619 bytes in 515 blocks
==41582== suppressed​: 0 bytes in 0 blocks
==41582== Rerun with --leak-check=full to see details of leaked memory
==41582==
==41582== For counts of detected and suppressed errors, rerun with​: -v
==41582== ERROR SUMMARY​: 1 errors from 1 contexts (suppressed​: 0 from 0)
Segmentation fault

**PERL -V**

dcollins@​nightshade64​:~/perl$ ./perl -Ilib -V
Summary of my perl5 (revision 5 version 24 subversion 0) configuration​:
  Commit id​: 10d36cf
  Platform​:
  osname=linux, osvers=3.16.0-4-amd64, archname=x86_64-linux-ld
  uname='linux nightshade64 3.16.0-4-amd64 #1 smp debian 3.16.7-ckt20-1+deb8u3 (2016-01-17) x86_64 gnulinux '
  config_args='-Dusedevel -Dprefix=/usr/local/perl-afl -Dcc=ccache afl-gcc -Duselongdouble -Duse64bitall -Doptimize=-g -Uversiononly -Uman1dir -Uman3dir -des'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=undef, usemultiplicity=undef
  use64bitint=define, use64bitall=define, uselongdouble=define
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='ccache afl-gcc', ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-g',
  cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
  ccversion='', gccversion='5.2.0', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
  ivtype='long', ivsize=8, nvtype='long double', nvsize=16, Off_t='off_t', lseeksize=8
  alignbytes=16, prototype=define
  Linker and Libraries​:
  ld='ccache afl-gcc', ldflags =' -fstack-protector-strong -L/usr/local/lib'
  libpth=/usr/local/lib /usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
  libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
  perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
  libc=libc-2.19.so, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.19'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -g -L/usr/local/lib -fstack-protector-strong'

Characteristics of this binary (from libperl)​:
  Compile-time options​: HAS_TIMES PERLIO_LAYERS PERL_COPY_ON_WRITE
  PERL_DONT_CREATE_GVSV
  PERL_HASH_FUNC_ONE_AT_A_TIME_HARD PERL_MALLOC_WRAP
  PERL_PRESERVE_IVUV PERL_USE_DEVEL USE_64_BIT_ALL
  USE_64_BIT_INT USE_LARGE_FILES USE_LOCALE
  USE_LOCALE_COLLATE USE_LOCALE_CTYPE
  USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_LONG_DOUBLE
  USE_PERLIO USE_PERL_ATOF
  Locally applied patches​:
  RC3
  Built under linux
  Compiled at Apr 30 2016 15​:50​:19
  @​INC​:
  lib
  /usr/local/perl-afl/lib/site_perl/5.24.0/x86_64-linux-ld
  /usr/local/perl-afl/lib/site_perl/5.24.0
  /usr/local/perl-afl/lib/5.24.0/x86_64-linux-ld
  /usr/local/perl-afl/lib/5.24.0
  .

@p5pRT

This comment has been minimized.

Copy link
Author

commented May 10, 2016

From @cpansprout

On Mon May 09 16​:16​:07 2016, dcollinsn@​gmail.com wrote​:

Greetings Porters,

I have compiled bleadperl with the afl-gcc compiler using​:

./Configure -Dusedevel -Dprefix='/usr/local/perl-afl' -Dcc='ccache
afl-gcc' -Uuselongdouble -Duse64bitall -Doptimize=-g -Uversiononly
-Uman1dir -Uman3dir -Dusequadmath -des
AFL_HARDEN=1 make && make test

And then fuzzed the resulting binary using​:

AFL_NO_VAR_CHECK=1 afl-fuzz -i in -o out bin/perl @​@​

After reducing testcases using `afl-tmin` and performing additional
minimization by hand, I have located the following testcase that
triggers a segmentation fault in the perl interpreter. The testcase is
the 15-character file​:

0,reset u;sub u

This bug is old​:

$ perl5.8.8 -e 'reset "u"; sub u;'
$ perl5.8.8 -e 'reset "u"; sub u($);'
Bus error​: 10

$ perl5.10 -e 'reset "u"; sub u;'
Segmentation fault​: 11
$ perl5.10 -e 'reset "u"; sub u($);'
Segmentation fault​: 11

I made it worse in 5.22​:

$ perl5.20.2 -e 'reset u; sub u{}'
$ perl5.22.0 -e 'reset u; sub u{}'
Segmentation fault​: 11

--

Father Chrysostomos

@p5pRT

This comment has been minimized.

Copy link
Author

commented May 10, 2016

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

@p5pRT

This comment has been minimized.

Copy link
Author

commented May 10, 2016

From @cpansprout

On Tue May 10 12​:54​:11 2016, sprout wrote​:

On Mon May 09 16​:16​:07 2016, dcollinsn@​gmail.com wrote​:

Greetings Porters,

I have compiled bleadperl with the afl-gcc compiler using​:

./Configure -Dusedevel -Dprefix='/usr/local/perl-afl' -Dcc='ccache
afl-gcc' -Uuselongdouble -Duse64bitall -Doptimize=-g -Uversiononly
-Uman1dir -Uman3dir -Dusequadmath -des
AFL_HARDEN=1 make && make test

And then fuzzed the resulting binary using​:

AFL_NO_VAR_CHECK=1 afl-fuzz -i in -o out bin/perl @​@​

After reducing testcases using `afl-tmin` and performing additional
minimization by hand, I have located the following testcase that
triggers a segmentation fault in the perl interpreter. The testcase is
the 15-character file​:

0,reset u;sub u

This bug is old​:

$ perl5.8.8 -e 'reset "u"; sub u;'
$ perl5.8.8 -e 'reset "u"; sub u($);'
Bus error​: 10

$ perl5.10 -e 'reset "u"; sub u;'
Segmentation fault​: 11
$ perl5.10 -e 'reset "u"; sub u($);'
Segmentation fault​: 11

I made it worse in 5.22​:

$ perl5.20.2 -e 'reset u; sub u{}'
$ perl5.22.0 -e 'reset u; sub u{}'
Segmentation fault​: 11

It’s worse than I thought. reset assumes that everything in a stash is a glob​:

$ ./perl -Ilib -e '$​::{u}=undef; reset "u"'
Assertion failed​: (SvTYPE(_gvgp) == SVt_PVGV || SvTYPE(_gvgp) == SVt_PVLV), function Perl_sv_resetpvn, file sv.c, line 9715.
Abort trap​: 6

--

Father Chrysostomos

@p5pRT

This comment has been minimized.

Copy link
Author

commented May 10, 2016

From @cpansprout

On Tue May 10 12​:58​:53 2016, sprout wrote​:

On Tue May 10 12​:54​:11 2016, sprout wrote​:

On Mon May 09 16​:16​:07 2016, dcollinsn@​gmail.com wrote​:

Greetings Porters,

I have compiled bleadperl with the afl-gcc compiler using​:

./Configure -Dusedevel -Dprefix='/usr/local/perl-afl' -Dcc='ccache
afl-gcc' -Uuselongdouble -Duse64bitall -Doptimize=-g -Uversiononly
-Uman1dir -Uman3dir -Dusequadmath -des
AFL_HARDEN=1 make && make test

And then fuzzed the resulting binary using​:

AFL_NO_VAR_CHECK=1 afl-fuzz -i in -o out bin/perl @​@​

After reducing testcases using `afl-tmin` and performing additional
minimization by hand, I have located the following testcase that
triggers a segmentation fault in the perl interpreter. The testcase
is
the 15-character file​:

0,reset u;sub u

This bug is old​:

$ perl5.8.8 -e 'reset "u"; sub u;'
$ perl5.8.8 -e 'reset "u"; sub u($);'
Bus error​: 10

$ perl5.10 -e 'reset "u"; sub u;'
Segmentation fault​: 11
$ perl5.10 -e 'reset "u"; sub u($);'
Segmentation fault​: 11

I made it worse in 5.22​:

$ perl5.20.2 -e 'reset u; sub u{}'
$ perl5.22.0 -e 'reset u; sub u{}'
Segmentation fault​: 11

It’s worse than I thought. reset assumes that everything in a stash
is a glob​:

$ ./perl -Ilib -e '$​::{u}=undef; reset "u"'
Assertion failed​: (SvTYPE(_gvgp) == SVt_PVGV || SvTYPE(_gvgp) ==
SVt_PVLV), function Perl_sv_resetpvn, file sv.c, line 9715.
Abort trap​: 6

Fixed in fcd1306.

--

Father Chrysostomos

@p5pRT

This comment has been minimized.

Copy link
Author

commented May 10, 2016

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

@p5pRT

This comment has been minimized.

Copy link
Author

commented May 30, 2017

From @khwilliamson

Thank you for filing this report. You have helped make Perl better.

With the release today of Perl 5.26.0, this and 210 other issues have been
resolved.

Perl 5.26.0 may be downloaded via​:
https://metacpan.org/release/XSAWYERX/perl-5.26.0

If you find that the problem persists, feel free to reopen this ticket.

@p5pRT p5pRT closed this May 30, 2017
@p5pRT

This comment has been minimized.

Copy link
Author

commented May 30, 2017

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

@p5pRT p5pRT added the Severity Low label Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.