RE: Localizing %SIG in Safe.pm 2.{35,36,37} crashes POE::Wheel::Run ...

[email protected] (Markus Jansen) Tue, 16 Jul 2013 16:51:32 +0000
Newsgroups perl.poe
Message-ID <[email protected]>
Hi Rocco,

I'll revert to Safe 2.32 or 2.33 - the code change between 2.33[_01] and 2.=
35 and is minimal,
as you see from the diff below. The "local *SIG;" statement is the one and =
only that bites ...

Cheers,=09
	Markus

[6:48pm] [perl-git/dist/Safe] -> git diff 5df103ab ac4ec33e -- Safe.pm
diff --git a/dist/Safe/Safe.pm b/dist/Safe/Safe.pm
index 865a9dc..f00853e 100644
--- a/dist/Safe/Safe.pm
+++ b/dist/Safe/Safe.pm
@@ -3,7 +3,7 @@ package Safe;
 use 5.003_11;
 use Scalar::Util qw(reftype refaddr);
=20
-$Safe::VERSION =3D "2.33_01";
+$Safe::VERSION =3D "2.35";
=20
 # *** Don't declare any lexicals above this point ***
 #
@@ -21,7 +21,7 @@ sub lexless_anon_sub {
     # Uses a closure (on $__ExPr__) to pass in the code to be executed.
     # (eval on one line to keep line numbers as expected by caller)
     eval sprintf
-    'package %s; %s sub { @_=3D(); eval q[my $__ExPr__;] . $__ExPr__; }',
+    'package %s; %s sub { @_=3D(); eval q[local *SIG; my $__ExPr__;] . $__=
ExPr__; }',
                 $_[0], $_[1] ? 'use strict;' : '';
 }
=20
@@ -355,6 +355,8 @@ sub _clean_stash {
=20
 sub reval {
     my ($obj, $expr, $strict) =3D @_;
+    die "Bad Safe object" unless $obj->isa('Safe');
+
     my $root =3D $obj->{Root};
=20
     my $evalsub =3D lexless_anon_sub($root, $strict, $expr);
@@ -405,6 +407,7 @@ sub _find_code_refs {
=20
 sub wrap_code_ref {
     my ($obj, $sub) =3D @_;
+    die "Bad safe object" unless $obj->isa('Safe');
=20
     # wrap code ref $sub with _safe_call_sv so that, when called, the
     # execution will happen with the compartment fully 'in effect'.
@@ -440,6 +443,8 @@ sub wrap_code_ref {
=20
 sub rdo {
     my ($obj, $file) =3D @_;
+    die "Bad Safe object" unless $obj->isa('Safe');
+
     my $root =3D $obj->{Root};
=20
     my $sg =3D sub_generation();

-----Original Message-----
From: Rocco Caputo [mailto:[email protected]]=20
Sent: Tuesday, July 16, 2013 6:40 PM
To: Markus Jansen
Cc: [email protected]; [email protected]
Subject: Re: Localizing %SIG in Safe.pm 2.{35,36,37} crashes POE::Wheel::Ru=
n ...

Thank you for the alert.  Is there any reasonable way to work around this?

--
Rocco Caputo <[email protected]>

On Jul 16, 2013, at 12:00, Markus Jansen wrote:

> Hi,
>=20
> FYI ... hope none of you wastes time with this really nasty trap ...
>=20
> Best regards,
>        Markus
>=20
> -----Original Message-----
> From: Markus Jansen
> Sent: Tuesday, July 16, 2013 5:57 PM
> To: [email protected]
> Cc: Markus Jansen
> Subject: Localizing %SIG in Safe.pm 2.{35,36,37} crashes POE::Wheel::Run =
...
>=20
>=20
> This is a bug report for perl from [email protected], generated =
with the help of perlbug 1.39 running under perl 5.18.0.
>=20
>=20
> -----------------------------------------------------------------
> [Please describe your issue here]
>=20
> Dear Perl5 Porters,
>=20
> localizing %SIG in Safe.pm 2.35 (on CPAN, 2.{35,36,37} in Perl core) may =
be a great step for security, but it unfortunatately spoils POE::Wheel::Run=
 (basically POE and all other asynchronous frameworks dealing with external=
 processes).
>=20
> The symptom experienced is that your application might sooner or later cr=
ash (reliably when using POE::Component::Resolver upon exiting a Sidecar su=
bprocess) with the following famous last words:
>=20
>        Signal SIGCHLD received, but no signal handler set.
>=20
> Please consider a version (also on CPAN) of Safe.pm which has e.g. the lo=
calization of %SIG as a switchable feature.
>=20
> Best regards,
>        Markus
>=20
>=20
>=20
> [Please do not change anything below this line]
> -----------------------------------------------------------------
> ---
> Flags:
>    category=3Dlibrary
>    severity=3Dcritical
>    module=3DSafe
> ---
> Site configuration information for perl 5.18.0:
>=20
> Configured by ericsson at Fri Jul 12 19:17:48 CEST 2013.
>=20
> Summary of my perl5 (revision 5 version 18 subversion 0) configuration:
>=20
>  Platform:
>    osname=3Dlinux, osvers=3D2.6.16.60-0.42.10-smp, archname=3Dx86_64-linu=
x-thread-multi
>    uname=3D'linux sekix562 2.6.16.60-0.42.10-smp #1 smp tue apr 27 05:11:=
27 utc 2010 x86_64 x86_64 x86_64 gnulinux '
>    config_args=3D'-d -e -O -D cc=3Dgcc -D=20
> prefix=3D/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_pat
> h/prod -D usemultiplicity -U use5005threads -D usedl -D useshrplib -D=20
> libperl=3Dlibcmacperl.so -U usemymalloc -D cf_by=3Dericsson -D=20
> [email protected] -D=20
> [email protected] -D uselargefiles -D usethreads=20
> -D useithreads -D use64bitall -D ldcc=3DCC -D optimize=3D-O3 -D=20
> locincpth=3D/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_
> path/plib/include=20
> /vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path/plib/
> apache/include -D=20
> loclibpth=3D/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_
> path/plib/lib=20
> /vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path/plib/
> apache/lib -D lddlflags=3D-shared -lpthread=20
> -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path
> /prod/lib/5.18.0/x86_64-linux-thread-multi/CORE=20
> -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char
> _path/prod/lib/5.18.0 /x86_64-linux-thread-multi/CORE=20
> -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path
> /plib/lib=20
> -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char
> _path/plib/lib=20
> -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path
> /plib/apache/lib=20
> -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char
> _path/plib/apache/lib -Wl,--enable-new-dtags -D ldflags=3D-lpthread=20
> -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path
> /prod/lib/5.18.0/x86_64-linux-thread-multi/CORE=20
> -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char
> _path/prod/lib/5.18.0/x86_64-linux-thread-multi/CORE=20
> -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path
> /plib/lib=20
> -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char
> _path/plib/lib=20
> -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path
> /plib/apache/lib=20
> -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char
> _path/ plib/apache/lib -Wl,--enable-new-dtags -D ccdlflags=3D-Bdynamic=20
> -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path/pr=
od/lib/5.18.0/x86_64-linux-thread-multi/CORE -Wl,-rpath,/vobs/cc/CCA-perl01=
/perl5_Linux_x64__________sixtyfive_char_path/prod/lib/5.18.0/x86_64-linux-=
thread-multi/CORE -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyf=
ive_char_path/plib/lib -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64______=
____sixtyfive_char_path/plib/lib -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64_=
_________sixtyfive_char_path/plib/apache/lib -Wl,-rpath,/vobs/cc/CCA-perl01=
/perl5_Linux_x64__________sixtyfive_char_path/plib/apache/lib -D ldlibpthna=
me=3DLD_LIBRARY_PATH -D cccdlflags=3D-fPIC -D dlsrc=3Ddl_dlopen.xs -D ccfla=
gs=3D-O2 -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -pthread -DPERL_IMP=
LICIT_CONTEXT -DPERL_USE_SAFE_PUTENV -m64 -pipe -D_LARGEFILE_SOURCE -D_FILE=
_OFFSET_BITS=3D64 -fPIC -D so=3Dso -D libswanted=3Dnsl dl m crypt pthread c=
'
>    hint=3Drecommended, useposix=3Dtrue, d_sigaction=3Ddefine
>    useithreads=3Ddefine, usemultiplicity=3Ddefine
>    useperlio=3Ddefine, d_sfio=3Dundef, uselargefiles=3Ddefine, usesocks=
=3Dundef
>    use64bitint=3Ddefine, use64bitall=3Ddefine, uselongdouble=3Dundef
>    usemymalloc=3Dn, bincompat5005=3Dundef
>  Compiler:
>    cc=3D'gcc', ccflags =3D'-D_REENTRANT -D_GNU_SOURCE -O2 -D_REENTRANT -D=
_GNU_SOURCE -DTHREADS_HAVE_PIDS -pthread -DPERL_IMPLICIT_CONTEXT -DPERL_USE=
_SAFE_PUTENV -m64 -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=3D64 -fPIC =
-fno-strict-aliasing -fstack-protector -I/vobs/cc/CCA-perl01/perl5_Linux_x6=
4__________sixtyfive_char_path/plib/include -I/vobs/cc/CCA-perl01/perl5_Lin=
ux_x64__________sixtyfive_char_path/plib/apache/include -D_LARGEFILE_SOURCE=
 -D_FILE_OFFSET_BITS=3D64',
>    optimize=3D'-O3',
>    cppflags=3D'-D_REENTRANT -D_GNU_SOURCE -O2 -D_REENTRANT -D_GNU_SOURCE =
-DTHREADS_HAVE_PIDS -pthread -DPERL_IMPLICIT_CONTEXT -DPERL_USE_SAFE_PUTENV=
 -m64 -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=3D64 -fPIC -fno-strict-=
aliasing -fstack-protector -I/vobs/cc/CCA-perl01/perl5_Linux_x64__________s=
ixtyfive_char_path/plib/include -I/vobs/cc/CCA-perl01/perl5_Linux_x64______=
____sixtyfive_char_path/plib/apache/include'
>    ccversion=3D'', gccversion=3D'4.1.2 20070115 (SUSE Linux)', gccosandve=
rs=3D''
>    intsize=3D4, longsize=3D8, ptrsize=3D8, doublesize=3D8, byteorder=3D12=
345678
>    d_longlong=3Ddefine, longlongsize=3D8, d_longdbl=3Ddefine, longdblsize=
=3D16
>    ivtype=3D'long', ivsize=3D8, nvtype=3D'double', nvsize=3D8, Off_t=3D'o=
ff_t', lseeksize=3D8
>    alignbytes=3D8, prototype=3Ddefine
>  Linker and Libraries:
>    ld=3D'gcc', ldflags =3D'-lpthread -Wl,-L/vobs/cc/CCA-perl01/perl5_Linu=
x_x64__________sixtyfive_char_path/prod/lib/5.18.0/x86_64-linux-thread-mult=
i/CORE -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_ch=
ar_path/prod/lib/5.18.0/x86_64-linux-thread-multi/CORE -Wl,-L/vobs/cc/CCA-p=
erl01/perl5_Linux_x64__________sixtyfive_char_path/plib/lib -Wl,-rpath,/vob=
s/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path/plib/lib -Wl,-=
L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path/plib/apac=
he/lib -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_ch=
ar_path/plib/apache/lib -Wl,--enable-new-dtags -fstack-protector'
>    libpth=3D/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_p=
ath/plib/lib /vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_pa=
th/plib/apache/lib /lib/../lib64 /usr/lib/../lib64 /lib /usr/lib /usr/local=
/lib /lib64 /usr/lib64 /usr/local/lib64
>    libs=3D-lnsl -ldl -lm -lcrypt -lpthread -lc
>    perllibs=3D-lnsl -ldl -lm -lcrypt -lpthread -lc
>    libc=3D/lib/libc-2.4.so, so=3Dso, useshrplib=3Dtrue, libperl=3Dlibcmac=
perl.so
>    gnulibc_version=3D'2.4'
>  Dynamic Linking:
>    dlsrc=3Ddl_dlopen.xs, dlext=3Dso, d_dlsymun=3Dundef, ccdlflags=3D'-Bdy=
namic -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_pat=
h/prod/lib/5.18.0/x86_64-linux-thread-multi/CORE -Wl,-rpath,/vobs/cc/CCA-pe=
rl01/perl5_Linux_x64__________sixtyfive_char_path/prod/lib/5.18.0/x86_64-li=
nux-thread-multi/CORE -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________si=
xtyfive_char_path/plib/lib -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64__=
________sixtyfive_char_path/plib/lib -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_=
x64__________sixtyfive_char_path/plib/apache/lib -Wl,-rpath,/vobs/cc/CCA-pe=
rl01/perl5_Linux_x64__________sixtyfive_char_path/plib/apache/lib'
>    cccdlflags=3D'-fPIC', lddlflags=3D'-shared -lpthread -Wl,-L/vobs/cc/CC=
A-perl01/perl5_Linux_x64__________sixtyfive_char_path/prod/lib/5.18.0/x86_6=
4-linux-thread-multi/CORE -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64___=
_______sixtyfive_char_path/prod/lib/5.18.0/x86_64-linux-thread-multi/CORE -=
Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path/plib/=
lib -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_=
path/plib/lib -Wl,-L/vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_=
char_path/plib/apache/lib -Wl,-rpath,/vobs/cc/CCA-perl01/perl5_Linux_x64___=
_______sixtyfive_char_path/plib/apache/lib -Wl,--enable-new-dtags -fstack-p=
rotector'
>=20
> Locally applied patches:
>=20
>=20
> ---
> @INC for perl 5.18.0:
>    /vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path/prod/=
lib/site_perl/5.18.0/x86_64-linux-thread-multi
>    /vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path/prod/=
lib/site_perl/5.18.0
>    /vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path/prod/=
lib/5.18.0/x86_64-linux-thread-multi
>    /vobs/cc/CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path/prod/=
lib/5.18.0
>    .
>=20
> ---
> Environment for perl 5.18.0:
>    HOME=3D/home/eedmja
>    LANG=3Den_US.UTF-8
>    LANGUAGE (unset)
>    LD_LIBRARY_PATH (unset)
>    LOGDIR (unset)
>    PATH=3D/tmp/_cc_CCA-perl01/perl5_Linux_x64__________sixtyfive_char_pat=
h/prod/bin:/tmp/_cc_CCA-perl01/perl5_Linux_x64__________sixtyfive_char_path=
/plib/bin:/bin:/usr/bin:/sbin:/usr/sbin:/opt/gnome/bin:/opt/kde3/bin:/usr/b=
in/X11:/home/eedmja/bin:/opt/rational/clearcase/bin
>    PERL_BADLANG (unset)
>    SHELL=3D/bin/tcsh