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

Assert fail in op.c without other symptoms: 0=\my%u:e=0 #15338

Open
p5pRT opened this issue May 18, 2016 · 4 comments
Open

Assert fail in op.c without other symptoms: 0=\my%u:e=0 #15338

p5pRT opened this issue May 18, 2016 · 4 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented May 18, 2016

Migrated from rt.perl.org#128183 (status was 'open')

Searchable as RT128183$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented May 18, 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 an assert fail in debugging builds of the perl interpreter. The testcase is the file below. On normal builds, this exits with the expected error. On debug builds, this returns an assert fail.

dcollins@​nightshade64​:~$ cat f3i1
0=\my%u​:e=0dcollins@​nightshade64​:~$
dcollins@​nightshade64​:~$ od -c f3i1
0000000 0 = \ m y % u : e = 0
0000013
dcollins@​nightshade64​:~$ ls -l f3i1
-rw-r----- 1 dcollins afl 11 May 18 17​:01 f3i1
dcollins@​nightshade64​:~$ ./perl/perl f3i1
Can't modify reference to subroutine entry in list assignment at f3i1 line 1, at EOF
Execution of f3i1 aborted due to compilation errors.
dcollins@​nightshade64​:~$ ./perldebug/perl f3i1
perl​: op.c​:2758​: S_lvref​: Assertion `(kid->op_flags & 3) != 1' failed.
Aborted

Debugging tool output is below. A git bisect was performed. Unfortunately, this requires attributes, so a miniperl build is not sufficient to test. Here is the result​:

7664512 is the first bad commit
commit 7664512
Author​: Father Chrysostomos <sprout@​cpan.org>
Date​: Tue Sep 30 22​:20​:56 2014 -0700

  Make \( ?​: ) assignment work

  When I first implemented list assignment to lvalue references, I
  thought I could simply modify the kids of the refgen op (\) in one
  spot. But things like ?​: make it necessary to do this recursively.
  So all that code for turning thingies into lvrefs has been moved into
  a separate function patterned after op_lvalue but handling only the
  lvref cases.

  (I thought about combining it with op_lvalue’s switch statement, but
  that would require ‘if(type == OP_LVREF) goto nomod;’ too many times,
  which would be harder to maintain.)

:100644 100644 2e163602eb33b1df99c98aeee9c803e79004f7db 9e4e8d9db15ae2e214420f67b2e6683c1611cf54 M op.c
:040000 040000 8114515a860c7aebba1d4c401f7b2aa52d8abade f65b52fd5e71e1ae0d6c098770ae4d38f7a37208 M t
bisect run success

**GDB**

dcollins@​nightshade64​:~$ gdb --args ./perldebug/perl f3i1
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 ./perldebug/perl...done.
(gdb) run
Starting program​: /home/dcollins/perldebug/perl f3i1
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
perl​: op.c​:2758​: S_lvref​: Assertion `(kid->op_flags & 3) != 1' failed.

Program received signal SIGABRT, Aborted.
0x00007ffff6cf9478 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0 0x00007ffff6cf9478 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff6cfa8fa in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff6cf23a7 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3 0x00007ffff6cf2452 in __assert_fail ()
  from /lib/x86_64-linux-gnu/libc.so.6
#4 0x000000000042611e in S_lvref (o=0xabc4d8, type=38) at op.c​:2758
#5 0x0000000000427556 in Perl_op_lvalue_flags (o=0xabc460, type=38, flags=0)
  at op.c​:3123
#6 0x0000000000432c5a in Perl_newASSIGNOP (flags=64, left=0xabc460,
  optype=0, right=0xabc420) at op.c​:6400
#7 0x00000000004d7161 in Perl_yyparse (gramtype=258) at perly.y​:781
#8 0x0000000000461482 in S_parse_body (env=0x0, xsinit=0x41e9e9 <xs_init>)
  at perl.c​:2365
#9 0x000000000045f8c8 in perl_parse (my_perl=0xa9a010,
  xsinit=0x41e9e9 <xs_init>, argc=2, argv=0x7fffffffe648, env=0x0)
  at perl.c​:1681
#10 0x000000000041e948 in main (argc=2, argv=0x7fffffffe648,
  env=0x7fffffffe660) at perlmain.c​:114
(gdb) f 4
#4 0x000000000042611e in S_lvref (o=0xabc4d8, type=38) at op.c​:2758
2758 assert((kid->op_flags & OPf_WANT) != OPf_WANT_VOID);
(gdb) info locals
kid = 0xabc5a8
__PRETTY_FUNCTION__ = "S_lvref"
(gdb) l
2753 return;
2754 }
2755 /* FALLTHROUGH */
2756 case OP_LIST​:
2757 for (kid = cLISTOPo->op_first; kid; kid = OpSIBLING(kid)) {
2758 assert((kid->op_flags & OPf_WANT) != OPf_WANT_VOID);
2759 S_lvref(aTHX_ kid, type);
2760 }
2761 return;
2762 case OP_STUB​:
(gdb) q

**PERL -V**

dcollins@​nightshade64​:~$ perl/perl -V
Summary of my perl5 (revision 5 version 25 subversion 1) configuration​:
  Commit id​: 9e17953
  Platform​:
  osname=linux, osvers=4.5.0-2-amd64, archname=x86_64-linux-ld
  uname='linux nightshade64 4.5.0-2-amd64 #1 smp debian 4.5.3-2 (2016-05-08) x86_64 gnulinux '
  config_args='-Dusedevel -Dprefix=/usr/local/perl-afl -Dcc=ccache afl-gcc -Duselongdouble -Duse64bitall -Doptimize=-g -Uversiononly -Uman1dir -Uman3dir -DDEBUGGING -DDEBUG_LEAKING_SCALARS -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 -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-g',
  cppflags='-fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
  ccversion='', gccversion='6.1.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-pc-linux-gnu/6.1.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.22.so, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.22'
  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_OP_PARENT 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
  Built under linux
  Compiled at May 17 2016 20​:01​:23
  @​INC​:
  /usr/local/perl-afl/lib/site_perl/5.25.1/x86_64-linux-ld
  /usr/local/perl-afl/lib/site_perl/5.25.1
  /usr/local/perl-afl/lib/5.25.1/x86_64-linux-ld
  /usr/local/perl-afl/lib/5.25.1
  /usr/local/perl-afl/lib/site_perl/5.24.0
  /usr/local/perl-afl/lib/site_perl
  .

@p5pRT
Copy link
Author

@p5pRT p5pRT commented May 19, 2016

From @cpansprout

On Wed May 18 16​:59​:31 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 an assert fail in debugging builds of the perl interpreter.
The testcase is the file below. On normal builds, this exits with the
expected error. On debug builds, this returns an assert fail.

dcollins@​nightshade64​:~$ cat f3i1
0=\my%u​:e=0dcollins@​nightshade64​:~$
dcollins@​nightshade64​:~$ od -c f3i1
0000000 0 = \ m y % u : e = 0
0000013
dcollins@​nightshade64​:~$ ls -l f3i1
-rw-r----- 1 dcollins afl 11 May 18 17​:01 f3i1
dcollins@​nightshade64​:~$ ./perl/perl f3i1
Can't modify reference to subroutine entry in list assignment at f3i1
line 1, at EOF
Execution of f3i1 aborted due to compilation errors.
dcollins@​nightshade64​:~$ ./perldebug/perl f3i1
perl​: op.c​:2758​: S_lvref​: Assertion `(kid->op_flags & 3) != 1' failed.
Aborted

The initial 0= is unnecessary. I completely failed to take attributes into account when implementing refaliasing.

$ ./perl -Ilib -e '\my %x​:e = 1'
Assertion failed​: ((kid->op_flags & OPf_WANT) != OPf_WANT_VOID), function S_lvref, file op.c, line 2758.
Abort trap​: 6

$ ./perl -Ilib -e '\CORE​::state %x :e = 1'
Assertion failed​: ((kid->op_flags & OPf_WANT) != OPf_WANT_VOID), function S_lvref, file op.c, line 2758.
Abort trap​: 6

$ ./perl -Ilib -XMfeature=​:all -e 'sub MODIFY_HASH_ATTRIBUTES{} \our %x​:e = \%a; print "ok\n"'
ok

The last one works, because the attribute does not modify the op tree with ‘our’.

--

Father Chrysostomos

@p5pRT
Copy link
Author

@p5pRT p5pRT commented May 19, 2016

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

@p5pRT
Copy link
Author

@p5pRT p5pRT commented May 27, 2016

From @dcollinsn

Experts​: is the following bug related? (Also uses attributes, same assert, but in a different place.)

dcollins@​nightshade64​:~/perldebug$ ./perl -Ilib -W -e 'tie my$r​:n'
perl​: op.c​:2799​: Perl_op_lvalue_flags​: Assertion `(o->op_flags & 3) != 1' failed.
Aborted

Without debug​:

dcollins@​nightshade64​:~/perl$ ./perl -Ilib -W -e 'tie my$r​:n'
Can't modify non-lvalue subroutine call of &attributes​::import at -e line 1.
dcollins@​nightshade64​:~/perl$ ./perl -MO=Deparse -Ilib -e 'tie my$r​:n'
use attributes ();
tie 'attributes'->import('main', \$r, 'n'), my $r;
-e syntax OK

Bisect

5c90603 is the first bad commit
commit 5c90603
Author​: Gerard Goossen <gerard@​ggoossen.net>
Date​: Sat Aug 13 18​:38​:13 2011 +0200

  Propagate lvalue context only to children of list ops which are not in void context.

  Children list ops might be in void context because the list is in scalar
  context. A test that discarded elements in a list are not assigned lvalue
  context is added.
  Children of a list op might also be in void context because they are
  special entersub ops for attributes. This patch makes the
  OPpENTERSUB_NOMOD flag redundant.

:100644 100644 775705b55e4c0f69255527942edbf8ae7b4f0bbf c4c0e762493df04c66d924090cde0c87e2bea018 M op.c
:040000 040000 8b96ea734cee36175aef04088948ead0744c5b03 a5c0ce3a48597ac07dadb8340649a878dad3877b M t
bisect run success

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

2 participants