Обсуждение: plperl segfault in plperl_trusted_init() on kfreebsd

Поиск
Список
Период
Сортировка

plperl segfault in plperl_trusted_init() on kfreebsd

От
Christoph Berg
Дата:
The newly activated "make check-world" on Debian (I haven't found the
time yet to follow up on the other threads I opened for that, sorry)
actually found something: plperl and plperlu segfault on the
kfreebsd-amd64 and kfreebsd-i386 architectures. These are FreeBSD 9
kernels with a GNU/Debian userland.

libperl 5.14.2-21
gcc (Debian 4.7.2-5) 4.7.2
libc0.1 2.13-38

Here's what I did:

./configure
cd src && make
cd pl/plperl && make clean && make CFLAGS="-g"
make check

../../../src/test/regress/pg_regress --inputdir=. --temp-install=./tmp_check --top-builddir=../../..
--dbname=pl_regression--load-extension=plperl  --load-extension=plperlu plperl plperl_lc plperl_trigger plperl_shared
plperl_elogplperl_util plperl_init plperlu plperl_array plperl_plperlu
 
============== creating temporary installation        ==============
============== initializing database system           ==============
============== starting postmaster                    ==============
running on port 57532 with PID 29715
============== creating database "pl_regression"      ==============
CREATE DATABASE
ALTER DATABASE
============== installing plperl                      ==============
CREATE EXTENSION
============== installing plperlu                     ==============
CREATE EXTENSION
============== running regression test queries        ==============
test plperl                   ... FAILED (test process exited with exit code 2)
test plperl_lc                ... FAILED (test process exited with exit code 2)
test plperl_trigger           ... FAILED (test process exited with exit code 2)
test plperl_shared            ... FAILED (test process exited with exit code 2)
test plperl_elog              ... FAILED (test process exited with exit code 2)
test plperl_util              ... FAILED (test process exited with exit code 2)
test plperl_init              ... FAILED (test process exited with exit code 2)
test plperlu                  ... FAILED (test process exited with exit code 2)
test plperl_array             ... FAILED (test process exited with exit code 2)
test plperl_plperlu           ... FAILED (test process exited with exit code 2)
============== shutting down postmaster               ==============

========================10 of 10 tests failed. 
========================

myon@debian-kfreebsd-amd64:~/postgresql-9.3/src/pl/plperl $ gdb tmp_check/install/usr/local/pgsql/bin/postgres
tmp_check/data/postgres.core
 
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 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-kfreebsd-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from
/home/myon/postgresql/postgresql-9.3/src/pl/plperl/tmp_check/install/usr/local/pgsql/bin/postgres...(nodebugging
symbolsfound)...done.
 
[New process 100072]
Core was generated by `postgres'.
Program terminated with signal 11, Segmentation fault.
#0  0x000000080a6e964e in plperl_trusted_init () at plperl.c:937
937        if (SvTRUE(ERRSV))
(gdb) bt
#0  0x000000080a6e964e in plperl_trusted_init () at plperl.c:937
#1  0x000000080a6e85dd in select_perl_context (trusted=1 '\001') at plperl.c:600
#2  0x000000080a6f133e in compile_plperl_function (fn_oid=49152, is_trigger=0 '\000') at plperl.c:2661
#3  0x000000080a6edc55 in plperl_validator (fcinfo=0x7fffffffbde0) at plperl.c:1900
#4  0x00000000007200d6 in OidFunctionCall1Coll ()
#5  0x00000000004ec30e in ProcedureCreate ()
#6  0x000000000054c44e in CreateFunction ()
#7  0x00000000006588af in ProcessUtilitySlow.isra.2 ()
#8  0x0000000000657b5c in standard_ProcessUtility ()
#9  0x0000000000655477 in PortalRunUtility ()
#10 0x0000000000656065 in PortalRunMulti ()
#11 0x0000000000656b52 in PortalRun ()
#12 0x0000000000653f03 in PostgresMain ()
#13 0x0000000000464411 in ServerLoop ()
#14 0x0000000000614491 in PostmasterMain ()
#15 0x0000000000464c4b in main ()
(gdb) l
932        /* use original require while we set up */
933        PL_ppaddr[OP_REQUIRE] = pp_require_orig;
934        PL_ppaddr[OP_DOFILE] = pp_require_orig;
935    
936        eval_pv(PLC_TRUSTED, FALSE);
937        if (SvTRUE(ERRSV))
938            ereport(ERROR,
939                    (errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
940                     errcontext("while executing PLC_TRUSTED")));
941    


LOG:  server process (PID 29740) was terminated by signal 11: Segmentation fault
DETAIL:  Failed process was running: CREATE OR REPLACE FUNCTION perl_int(int) RETURNS INTEGER AS $$       return undef;
     $$ LANGUAGE plperl;
 
LOG:  terminating any other active server processes

I'm not an expert in libperl, so please excuse if I didn't include
something in this report. I have the coredumps here so I can provide
more information.

Christoph
-- 
cb@df7cb.de | http://www.df7cb.de/



Re: plperl segfault in plperl_trusted_init() on kfreebsd

От
Tom Lane
Дата:
Christoph Berg <cb@df7cb.de> writes:
> Here's what I did:

> ./configure
> cd src && make
> cd pl/plperl && make clean && make CFLAGS="-g"
> make check

You sure that wholesale override of CFLAGS is a good idea?
This report doesn't show what flags the rest of your system was built
with, but seems like there could be a compatibility issue.  Or maybe
you prevented plperl from being built with -fpic, or something like
that.

I tend to usemake PROFILE="-g"
for this sort of tweak to the compile flags --- that adds the flags
you specify, without removing any.
        regards, tom lane



Re: plperl segfault in plperl_trusted_init() on kfreebsd

От
Christoph Berg
Дата:
Re: Tom Lane 2013-05-15 <244.1368675320@sss.pgh.pa.us>
> You sure that wholesale override of CFLAGS is a good idea?
> This report doesn't show what flags the rest of your system was built
> with, but seems like there could be a compatibility issue.  Or maybe
> you prevented plperl from being built with -fpic, or something like
> that.

That was because the plain "./configure" version (for a minimal way to
reproduce) didn't built with debug symbols. The original gcc line from the
Debian build log is:

cd build && ../configure \          --with-tcl \          --with-perl \          --with-python \          --with-pam \
       --with-krb5 \          --with-gssapi \          --with-openssl \          --with-libxml \
--with-libxslt\          --with-ldap \          --with-tclconfig=/usr/lib/tcl8.5 \
--with-tkconfig=/usr/lib/tk8.5\          --with-includes=/usr/include/tcl8.5 \          PYTHON=/usr/bin/python \
 --mandir=/usr/share/postgresql/9.3/man --docdir=/usr/share/doc/postgresql-doc-9.3 --sysconfdir=/etc/postgresql-common
--datarootdir=/usr/share/--datadir=/usr/share/postgresql/9.3 --bindir=/usr/lib/postgresql/9.3/bin --libdir=/usr/lib/
--libexecdir=/usr/lib/postgresql/--includedir=/usr/include/postgresql/ --enable-nls --enable-integer-datetimes
--enable-thread-safety--enable-debug --disable-rpath --with-ossp-uuid --with-gnu-ld --with-pgport=5432
--with-system-tzdata=/usr/share/zoneinfoCFLAGS='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat
-Werror=format-security-fPIC -pie -I/usr/include/mit-krb5' LDFLAGS='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed
-L/usr/lib/mit-krb5-L/usr/lib/x86_64-kfreebsd-gnu/mit-krb5'
 


/usr/bin/make -C plperl all
make[5]: Entering directory
`/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/src/pl/plperl'
msgfmt -o po/cs.mo
/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/pl/plperl/po/cs.po
[...]
'/usr/bin/perl'
/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/pl/plperl/text2macro.pl
--strip='^(\#.*|\s*)$'
/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/pl/plperl/plc_perlboot.pl
/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/pl/plperl/plc_trusted.pl
>perlchunks.h
 
'/usr/bin/perl'
/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/pl/plperl/plperl_opmask.pl
plperl_opmask.h
gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -pie
-I/usr/include/mit-krb5-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -fpic -I.
-I/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/pl/plperl
-I../../../src/include
-I/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/include
-D_FORTIFY_SOURCE=2-D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include/tcl8.5 -I/usr/lib/perl/5.14/CORE  -c -o
plperl.o
/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/pl/plperl/plperl.c
'/usr/bin/perl' /usr/share/perl/5.14/ExtUtils/xsubpp -typemap /usr/share/perl/5.14/ExtUtils/typemap
/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/pl/plperl/SPI.xs
>SPI.c
gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -pie
-I/usr/include/mit-krb5-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -fpic -I.
-I/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/pl/plperl
-I../../../src/include
-I/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/include
-D_FORTIFY_SOURCE=2-D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include/tcl8.5 -I/usr/lib/perl/5.14/CORE  -c -o SPI.o
SPI.c
'/usr/bin/perl' /usr/share/perl/5.14/ExtUtils/xsubpp -typemap /usr/share/perl/5.14/ExtUtils/typemap
/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/pl/plperl/Util.xs
>Util.c
gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -pie
-I/usr/include/mit-krb5-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -fpic -I.
-I/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/pl/plperl
-I../../../src/include
-I/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/../src/include
-D_FORTIFY_SOURCE=2-D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include/tcl8.5 -I/usr/lib/perl/5.14/CORE  -c -o Util.o
Util.c
gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -pie
-I/usr/include/mit-krb5-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -fpic -shared
-oplperl.so plperl.o SPI.o Util.o -L../../../src/port -L../../../src/common -Wl,-z,relro -Wl,-z,now -Wl,--as-needed
-L/usr/lib/mit-krb5-L/usr/lib/x86_64-kfreebsd-gnu/mit-krb5 -L/usr/lib  -Wl,--as-needed  -fstack-protector
-L/usr/local/lib -L/usr/lib/perl/5.14/CORE -lperl -ldl -lm -lpthread -lc -lcrypt 
 
make[5]: Leaving directory
`/build/buildd-postgresql-9.3_9.3~beta1-2-kfreebsd-amd64-3i_y9K/postgresql-9.3-9.3~beta1/build/src/pl/plperl'

It segfaults on kfreebsd, too (and works fine elsewhere).

> I tend to use
>     make PROFILE="-g"
> for this sort of tweak to the compile flags --- that adds the flags
> you specify, without removing any.

Good to know, thanks.

Christoph
-- 
cb@df7cb.de | http://www.df7cb.de/



Re: plperl segfault in plperl_trusted_init() on kfreebsd

От
Stephen Frost
Дата:
* Christoph Berg (cb@df7cb.de) wrote:
> That was because the plain "./configure" version (for a minimal way to
> reproduce) didn't built with debug symbols. The original gcc line from the
> Debian build log is:

It did, but Debian (and Ubuntu and friends) pull the debugging symbols
out of the binaries and stick them into independent packages, allowing
you to only install them if you need/want to.

Try installing postgresql-9.3-dbg.  At least the postgresql-9.2-dbg
package on my system also includes the plperl.so debugging symbols.
Thanks,
    Stephen

Re: plperl segfault in plperl_trusted_init() on kfreebsd

От
Christoph Berg
Дата:
Re: Stephen Frost 2013-05-16 <20130516123344.GT4361@tamriel.snowman.net>
> * Christoph Berg (cb@df7cb.de) wrote:
> > That was because the plain "./configure" version (for a minimal way to
> > reproduce) didn't built with debug symbols. The original gcc line from the
> > Debian build log is:
> 
> It did, but Debian (and Ubuntu and friends) pull the debugging symbols
> out of the binaries and stick them into independent packages, allowing
> you to only install them if you need/want to.
> 
> Try installing postgresql-9.3-dbg.  At least the postgresql-9.2-dbg
> package on my system also includes the plperl.so debugging symbols.

This wasn't the Debian build, but just plain "./configure --with-perl"
without any other arguments. As said in the previous mail, both this
and the Debian build segfault here. (Which means there is no -dbg
package because the build fails.)

I don't think this makes a difference anyway - I can pull more
information out from that core, but that needs someone saying which
info, because that's the place where I'm lost at.

(I'll be away until monday.)

Christoph
-- 
cb@df7cb.de | http://www.df7cb.de/



Re: plperl segfault in plperl_trusted_init() on kfreebsd

От
Stephen Frost
Дата:
* Christoph Berg (cb@df7cb.de) wrote:
> This wasn't the Debian build, but just plain "./configure --with-perl"
> without any other arguments. As said in the previous mail, both this
> and the Debian build segfault here. (Which means there is no -dbg
> package because the build fails.)

Oh, I see what you mean- this is the actual *build* failing.

Interesting..
Thanks,
    Stephen

Re: plperl segfault in plperl_trusted_init() on kfreebsd

От
Andrew Dunstan
Дата:
On 05/16/2013 09:14 AM, Christoph Berg wrote:
> Re: Stephen Frost 2013-05-16 <20130516123344.GT4361@tamriel.snowman.net>
>> * Christoph Berg (cb@df7cb.de) wrote:
>>> That was because the plain "./configure" version (for a minimal way to
>>> reproduce) didn't built with debug symbols. The original gcc line from the
>>> Debian build log is:
>> It did, but Debian (and Ubuntu and friends) pull the debugging symbols
>> out of the binaries and stick them into independent packages, allowing
>> you to only install them if you need/want to.
>>
>> Try installing postgresql-9.3-dbg.  At least the postgresql-9.2-dbg
>> package on my system also includes the plperl.so debugging symbols.
> This wasn't the Debian build, but just plain "./configure --with-perl"
> without any other arguments. As said in the previous mail, both this
> and the Debian build segfault here. (Which means there is no -dbg
> package because the build fails.)
>
> I don't think this makes a difference anyway - I can pull more
> information out from that core, but that needs someone saying which
> info, because that's the place where I'm lost at.
>
> (I'll be away until monday.)
>
>


I have reproduced this. It happens with both the distro perl and a 
home-built perl 5.14. AFAICT this is a Perl bug. Any reference at all to 
ERRSV at the point this occurs causes a core dump, even just assigning 
it to a local SV * variable. Maybe you should take this up with the Perl 
people. It certainly seems mysterious that this should only occur on 
this platform.

cheers

andrew



Re: plperl segfault in plperl_trusted_init() on kfreebsd

От
Christoph Berg
Дата:
Re: Andrew Dunstan 2013-05-17 <51964770.6070405@dunslane.net>
> I have reproduced this. It happens with both the distro perl and a
> home-built perl 5.14. AFAICT this is a Perl bug. Any reference at
> all to ERRSV at the point this occurs causes a core dump, even just
> assigning it to a local SV * variable. Maybe you should take this up
> with the Perl people. It certainly seems mysterious that this should
> only occur on this platform.

I've just tried to look into this but got lost in chasing about 5
nested layers of ERRSV #defines. :-/

The crash also happens with libperl5.18 (5.18.0-1) on unstable/kfreebsd-amd64.

./configure --with-perl; make; cd src/pl/perl; make clean

postgresql-9.3/src/pl/plperl $ make PROFILE="-g -O0"
'/usr/bin/perl' ./text2macro.pl --strip='^(\#.*|\s*)$' plc_perlboot.pl plc_trusted.pl > perlchunks.h
'/usr/bin/perl' plperl_opmask.pl plperl_opmask.h
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fpic -I.
-I.-I../../../src/include -D_GNU_SOURCE  -I/usr/lib/perl/5.18/CORE  -c -o plperl.o plperl.c
 
'/usr/bin/perl' /usr/share/perl/5.18/ExtUtils/xsubpp -typemap /usr/share/perl/5.18/ExtUtils/typemap SPI.xs >SPI.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fpic -I.
-I.-I../../../src/include -D_GNU_SOURCE  -I/usr/lib/perl/5.18/CORE  -c -o SPI.o SPI.c
 
'/usr/bin/perl' /usr/share/perl/5.18/ExtUtils/xsubpp -typemap /usr/share/perl/5.18/ExtUtils/typemap Util.xs >Util.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fpic -I.
-I.-I../../../src/include -D_GNU_SOURCE  -I/usr/lib/perl/5.18/CORE  -c -o Util.o Util.c
 
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fpic
-shared-o plperl.so plperl.o SPI.o Util.o -L../../../src/port -L../../../src/common -Wl,--as-needed
-Wl,-rpath,'/usr/lib/perl/5.18/CORE',--enable-new-dtags-g -O0  -fstack-protector -L/usr/local/lib
-L/usr/lib/perl/5.18/CORE-lperl -ldl -lm -lpthread -lc -lcrypt 
 

postgresql-9.3/src/pl/plperl $ make check
[...]
../../../src/test/regress/pg_regress --inputdir=. --temp-install=./tmp_check --top-builddir=../../..
--dbname=pl_regression--load-extension=plperl  --load-extension=plperlu plperl plperl_lc plperl_trigger plperl_shared
plperl_elogplperl_util plperl_init plperlu plperl_array plperl_plperlu
 
[...]
============== running regression test queries        ==============
test plperl                   ... FAILED (test process exited with exit code 2)
[...]

#0  0x000000080a4274ed in plperl_trusted_init () at plperl.c:937
937        if (SvTRUE(ERRSV))
#1  0x000000080a42602d in select_perl_context (trusted=1 '\001') at plperl.c:600
#2  0x000000080a430cb1 in compile_plperl_function (fn_oid=49152, is_trigger=0 '\000') at plperl.c:2661
#3  0x000000080a42ca4d in plperl_validator (fcinfo=0x7fffffffbeb0) at plperl.c:1900
#4  0x000000000071ffb6 in OidFunctionCall1Coll ()
#5  0x00000000004ec3b7 in ProcedureCreate ()
#6  0x000000000054c4ee in CreateFunction ()
#7  0x000000000065889f in ProcessUtilitySlow.isra.2 ()
#8  0x0000000000657b4c in standard_ProcessUtility ()
#9  0x0000000000655467 in PortalRunUtility ()
#10 0x0000000000656055 in PortalRunMulti ()
#11 0x0000000000656b42 in PortalRun ()
#12 0x0000000000653ef3 in PostgresMain ()
#13 0x0000000000464471 in ServerLoop ()
#14 0x00000000006144e1 in PostmasterMain ()
#15 0x0000000000464cab in main ()

Christoph
-- 
cb@df7cb.de | http://www.df7cb.de/