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

Segmentation fault in Perl_csighandler when receiving SIGCHLD & using threads #13515

Closed
p5pRT opened this issue Jan 8, 2014 · 14 comments
Closed

Comments

@p5pRT
Copy link

p5pRT commented Jan 8, 2014

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

Searchable as RT120951$

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2014

From thierry.vignaud@gmail.com

I'have a program which uses threads (but not willingly) and has a custom signal handler for SIGCHLD..
Those are created by libraries it rely on (GNOME's glib & wekbitgtk)

If a SIGCHLD is received & handled by a custom signal handler before the thread creation by the libraries, perl segfaults.

Here is the stacktrace from gdb​:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff969b2700 (LWP 25465)]
Perl_csighandler (sig=17, sip=<optimized out>, uap=<optimized out>) at mg.c​:1334
1334 sig == SIGSEGV ||
Missing separate debuginfos, use​: debuginfo-install adwaita-gtk2-theme-3.10.0-2.mga4.x86_64 dconf-0.18.0-4.mga4.x86_64 gnome-shell-3.10.2.1-5.mga4.x86_64 gvfs-1.18.3-1.mga4.x86_64 icedtea-web-1.4.1-2.mga4.x86_64 lib64GConf2_4-3.2.6-4.mga4.x86_64 lib64atk1.0_0-2.10.0-2.mga4.x86_64 lib64bzip2_1-1.0.6-4.mga4.x86_64 lib64cairo2-1.12.16-2.mga4.x86_64 lib64canberra-gtk0-0.30-4.mga4.x86_64 lib64canberra0-0.30-4.mga4.x86_64 lib64dbus-glib1_2-0.100.2-2.mga4.x86_64 lib64dbus1_3-1.6.12-4.mga4.x86_64 lib64drm2-2.4.50-2.mga4.x86_64 lib64enchant1-1.6.0-9.mga4.x86_64 lib64ffi6-3.0.13-2.mga4.x86_64 lib64fontconfig1-2.11.0-2.mga4.x86_64 lib64freetype6-2.5.0.1-3.mga4.tainted.x86_64 lib64gbm1-10.0.1-2.mga4.tainted.x86_64 lib64gcrypt11-1.5.3-2.mga4.x86_64 lib64gdk_pixbuf2.0_0-2.30.1-1.mga4.x86_64 lib64geoclue0-0.12.99-6.mga4.x86_64 lib64glapi0-10.0.1-2.mga4.tainted.x86_64 lib64glib-networking-2.38.2-1.mga4.x86_64 lib64gpg-error0-1.12-2.mga4.x86_64 lib64graphite2_3-1.2.4-1.mga4.x86_64 lib64gstreamer-plugins-base1.0_0-1.2.0-2.mga4.x86_64 lib64gstreamer1.0_0-1.2.0-2.mga4.x86_64 lib64gvfscommon0-1.18.3-1.mga4.x86_64 lib64harfbuzz0-0.9.22-2.mga4.x86_64 lib64hunspell1.3_0-1.3.2-8.mga4.x86_64 lib64ice6-1.0.8-4.mga4.x86_64 lib64icu52-52.1-2.mga4.x86_64 lib64javascriptcoregtk1.0_0-2.2.2-1.mga4.x86_64 lib64jpeg8-1.3.0-3.mga4.x86_64 lib64json-glib1.0_0-0.16.2-3.mga4.x86_64 lib64ltdl7-2.4.2-11.mga4.x86_64 lib64lzma5-5.1.2-0.alpha.4.mga4.x86_64 lib64mesaegl1-10.0.1-2.mga4.tainted.x86_64 lib64mesagl1-10.0.1-2.mga4.tainted.x86_64 lib64nspr4-4.10.2-1.mga4.x86_64 lib64nss3-3.15.3.1-1.mga4.x86_64 lib64ogg0-1.3.1-2.mga4.x86_64 lib64orc0.4_0-0.4.18-2.mga4.x86_64 lib64pango1.0_0-1.36.1-1.mga4.x86_64 lib64pcre1-8.33-2.mga4.x86_64 lib64pixman1_0-0.32.4-1.mga4.x86_64 lib64png16_16-1.6.8-1.mga4.x86_64 lib64proxy1-0.4.11-5.mga4.x86_64 lib64secret1_0-0.16-3.mga4.x86_64 lib64sm6-1.2.2-2.mga4.x86_64 lib64soup2.4_1-2.44.2-1.mga4.x86_64 lib64sqlite3_0-3.8.0.2-2.mga4.x86_64 lib64tdb1-1.2.12-2.mga4.x86_64 lib64totem-plparser-mini18-3.10.0-3.mga4.x86_64 lib64udev1-208-5.mga4.x86_64 lib64uuid1-2.24-2.mga4.x86_64 lib64voikko1-3.6.1-3.mga4.x86_64 lib64vorbis0-1.3.3-4.mga4.x86_64 lib64vorbisfile3-1.3.3-4.mga4.x86_64 lib64wayland-client0-1.3.0-2.mga4.x86_64 lib64wayland-server0-1.3.0-2.mga4.x86_64 lib64webkitgtk1.0_0-2.2.2-1.mga4.x86_64 lib64webp4-0.3.1-2.mga4.x86_64 lib64x11-xcb1-1.6.2-2.mga4.x86_64 lib64x11_6-1.6.2-2.mga4.x86_64 lib64xau6-1.0.8-3.mga4.x86_64 lib64xcb-dri2_0-1.9.1-2.mga4.x86_64 lib64xcb-glx0-1.9.1-2.mga4.x86_64 lib64xcb-render0-1.9.1-2.mga4.x86_64 lib64xcb-shm0-1.9.1-2.mga4.x86_64 lib64xcb-xfixes0-1.9.1-2.mga4.x86_64 lib64xcb1-1.9.1-2.mga4.x86_64 lib64xcomposite1-0.4.4-5.mga4.x86_64 lib64xcursor1-1.1.14-3.mga4.x86_64 lib64xdamage1-1.1.4-5.mga4.x86_64 lib64xdmcp6-1.1.1-5.mga4.x86_64 lib64xext6-1.3.2-3.mga4.x86_64 lib64xfixes3-5.0.1-2.mga4.x86_64 lib64xi6-1.7.2-3.mga4.x86_64 lib64xinerama1-1.1.3-2.mga4.x86_64 lib64xml2_2-2.9.1-2.mga4.x86_64 lib64xrandr2-1.4.2-2.mga4.x86_64 lib64xrender1-0.9.8-2.mga4.x86_64 lib64xslt1-1.1.28-4.mga4.x86_64 lib64xt6-1.1.4-3.mga4.x86_64 lib64xxf86vm1-1.1.3-3.mga4.x86_64 lib64zlib1-1.2.8-3.mga4.x86_64 libgcc1-4.8.2-3.mga4.x86_64 libstdc++6-4.8.2-3.mga4.x86_64 perl-Cairo-1.104.0-2.mga4.x86_64 perl-Pango-1.224-3.mga4.x86_64 totem-mozilla-3.10.1-2.mga4.x86_64
(gdb) bt
#0 Perl_csighandler (sig=17, sip=<optimized out>, uap=<optimized out>) at mg.c​:1334
#1 <signal handler called>
#2 0x00007ffff6cce302 in __libc_waitpid (pid=25466, stat_loc=stat_loc@​entry=0x7fff969b1b1c, options=options@​entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c​:40
#3 0x00007ffff599985e in g_spawn_sync (working_directory=working_directory@​entry=0x0, argv=<optimized out>, envp=envp@​entry=0x0, flags=flags@​entry=G_SPAWN_SEARCH_PATH, child_setup=child_setup@​entry=0x0,
  user_data=user_data@​entry=0x0, standard_output=standard_output@​entry=0x7fff969b1c50, standard_error=standard_error@​entry=0x7fff969b1c58, exit_status=exit_status@​entry=0x7fff969b1c4c,
  error=error@​entry=0x7fff969b1cb8) at gspawn.c​:402
#4 0x00007ffff5999cf7 in g_spawn_command_line_sync (command_line=command_line@​entry=0x7fff8c003df0 "dbus-launch --autolaunch=748d1d9f2a26c9eda63b35055081e3c1 --binary-syntax --close-stderr",
  standard_output=standard_output@​entry=0x7fff969b1c50, standard_error=standard_error@​entry=0x7fff969b1c58, exit_status=exit_status@​entry=0x7fff969b1c4c, error=error@​entry=0x7fff969b1cb8) at gspawn.c​:731
#5 0x00007fffee54025b in get_session_address_dbus_launch (error=error@​entry=0x7fff969b1cb8) at gdbusaddress.c​:1068
#6 0x00007fffee541aaa in get_session_address_platform_specific (error=0x7fff969b1cb8) at gdbusaddress.c​:1443
#7 g_dbus_address_get_for_bus_sync (bus_type=bus_type@​entry=G_BUS_TYPE_SESSION, cancellable=cancellable@​entry=0x0, error=error@​entry=0x7fff969b1da8) at gdbusaddress.c​:1526
#8 0x00007fffee54c85e in get_uninitialized_connection (bus_type=G_BUS_TYPE_SESSION, cancellable=cancellable@​entry=0x0, error=error@​entry=0x7fff969b1da8) at gdbusconnection.c​:6953
#9 0x00007fffee551d2b in g_bus_get_sync (bus_type=<optimized out>, cancellable=0x0, error=0x7fff969b1da8) at gdbusconnection.c​:7029
#10 0x00007fff969b98c0 in dconf_gdbus_get_bus_in_worker () from /usr/lib64/gio/modules/libdconfsettings.so
#11 0x00007fff969b999d in dconf_gdbus_method_call () from /usr/lib64/gio/modules/libdconfsettings.so
#12 0x00007ffff5957146 in g_main_dispatch (context=0xb07510) at gmain.c​:3066
#13 g_main_context_dispatch (context=context@​entry=0xb07510) at gmain.c​:3642
#14 0x00007ffff5957498 in g_main_context_iterate (context=context@​entry=0xb07510, block=block@​entry=1, dispatch=dispatch@​entry=1, self=<optimized out>) at gmain.c​:3713
#15 0x00007ffff595753c in g_main_context_iteration (context=0xb07510, may_block=1) at gmain.c​:3774
#16 0x00007fff969b9add in dconf_gdbus_worker_thread () from /usr/lib64/gio/modules/libdconfsettings.so
#17 0x00007ffff597be65 in g_thread_proxy (data=0xc778f0) at gthread.c​:798
#18 0x00007ffff6cc6fab in start_thread (arg=0x7fff969b2700) at pthread_create.c​:309
#19 0x00007ffff69f9d9d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S​:111

The segfaults happen since glib was upgraded from glib-2.34 to 2.36 & were seen with both perl-5.16 & 5.18.
Newer glib use threads more widely.

I've workarounded this in some tools by setting SIG{CHLD} later.
See the 7 commits related to #10289 in http​://gitweb.mageia.org/software/control-center/log/control-center
But some others are affected too.

I can still make mcc (Mageia Control Center) to reliably segfault by setting SIG{CHLD} earlier (by moving "$SIG{CHLD} =..." at top of /usr/libexec/drakconf)

Basically, we segfault in SIG_CHLD when webkit threads exit (webkit creates temporary ones on init).
Delaying setting CHLD handler workaround this...

So, as far as I'm concerned there's 2 bugs​:
- glib & webkit libraries creating threads behind our back
- perl segfaulting when having a custom signal handler for SIG_CHILD

There was an old bug that got fixed in perl-5.10.0​:
https://rt.perl.org/Public/Bug/Display.html?id=60724
https://access.redhat.com/site/solutions/425043 ("Segfault in perl Perl_csighndler when custom signal handler installed")

This report looks like a variant of this bug (and is happening b/c of glib's & webkit's threads).

It can be reproduced with either the attached script or one of the following one-liners​:

perl -MGtk2 -MGtk2​::WebKit -e '$SIG{CHLD} = sub { warn }; Gtk2->init; my $wiew = Gtk2​::WebKit​::WebView->new; $w=Gtk2​::Window->new; $w->add($view); Gtk2->main'

perl -MGtk3 -MGtk3​::WebKit -e '$SIG{CHLD} = sub { warn @​_ }; Gtk3->init; my $wiew = Gtk3​::WebKit​::WebView->new; $w=Gtk3​::Window->new; $w->add($view); Gtk3->main'

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2014

From thierry.vignaud@gmail.com

mcc

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2014

From @tonycoz

On Tue Jan 07 16​:06​:32 2014, thierry.vignaud@​gmail.com wrote​:

(gdb) bt
#0 Perl_csighandler (sig=17, sip=<optimized out>, uap=<optimized
out>) at mg.c​:1334
#1 <signal handler called>

Which version of perl is this backtrace from?

Is it a vendor patched perl?

Tony

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2014

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

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2014

From thierry.vignaud@gmail.com

This is perl-5.18.1 as provided by Mageia and is indeed patched by vendor​:
See http​://svnweb.mageia.org/packages/cauldron/perl/current/SOURCES/
for patches applied by Mageia

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2014

From @tonycoz

On Tue Jan 07 16​:48​:15 2014, tonyc wrote​:

On Tue Jan 07 16​:06​:32 2014, thierry.vignaud@​gmail.com wrote​:

(gdb) bt
#0 Perl_csighandler (sig=17, sip=<optimized out>, uap=<optimized
out>) at mg.c​:1334
#1 <signal handler called>

Which version of perl is this backtrace from?

Is it a vendor patched perl?

tony@​mars​:.../git/perl2$ gdb --args ~/perl/5.18.0-thr-debug/bin/perl -MGtk2 -MGtk2​::WebKit -e '$SIG{CHLD} = sub { warn }; Gtk2->init; my $view = Gtk2​::WebKit​::WebView->new; $w=Gtk2​::Window->new; $w->add($view); Gtk2->main'
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-linux-gnu".
For bug reporting instructions, please see​:
<http​://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/tony/perl/5.18.0-thr-debug/bin/perl...done.
(gdb) r
Starting program​: /home/tony/perl/5.18.0-thr-debug/bin/perl -MGtk2 -MGtk2​::WebKit -e \$SIG\{CHLD\}\ =\ sub\ \{\ warn\ \}\;\ Gtk2-\>init\;\ my\ \$view\ =\ Gtk2​::WebKit​::WebView-\>new\;\ \$w=Gtk2​::Window-\>new\;\ \$w-\>add\(\$view\)\;\ Gtk2-\>main
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffe8101700 (LWP 11218)]
[New Thread 0x7fffa77fe700 (LWP 11219)]
[New Thread 0x7fffa6bef700 (LWP 11220)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffa6bef700 (LWP 11220)]
Perl_csighandler (sig=17, sip=<optimized out>, uap=<optimized out>)
  at mg.c​:1334
1334 sig == SIGSEGV ||
(gdb) p my_perl
$1 = (PerlInterpreter *) 0x0

which I suspect means we need to initialize THX here in a similar way we do on Win32​:

void *
win32_signal_context(void)
{
  dTHX;
#ifdef MULTIPLICITY
  if (!my_perl) {
  my_perl = PL_curinterp;
  PERL_SET_THX(my_perl);
  }
  return my_perl;
#else
  return PL_curinterp;
#endif
}

Tony

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2014

From thierry.vignaud@gmail.com

Care to suggest a patch that I can test?

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2014

From @Leont

On Tue Jan 07 16​:06​:32 2014, thierry.vignaud@​gmail.com wrote​:

I'have a program which uses threads (but not willingly) and has a
custom signal handler for SIGCHLD..
Those are created by libraries it rely on (GNOME's glib & wekbitgtk)

If a SIGCHLD is received & handled by a custom signal handler before
the thread creation by the libraries, perl segfaults.

The segfaults happen since glib was upgraded from glib-2.34 to 2.36 &
were seen with both perl-5.16 & 5.18.
Newer glib use threads more widely.

I've workarounded this in some tools by setting SIG{CHLD} later.
See the 7 commits related to #10289 in
http​://gitweb.mageia.org/software/control-center/log/control-center
But some others are affected too.

I can still make mcc (Mageia Control Center) to reliably segfault by
setting SIG{CHLD} earlier (by moving "$SIG{CHLD} =..." at top of
/usr/libexec/drakconf)

Basically, we segfault in SIG_CHLD when webkit threads exit (webkit
creates temporary ones on init).
Delaying setting CHLD handler workaround this...

So, as far as I'm concerned there's 2 bugs​:
- glib & webkit libraries creating threads behind our back
- perl segfaulting when having a custom signal handler for SIG_CHILD

There was an old bug that got fixed in perl-5.10.0​:
https://rt.perl.org/Public/Bug/Display.html?id=60724
https://access.redhat.com/site/solutions/425043 ("Segfault in perl
Perl_csighndler when custom signal handler installed")

This report looks like a variant of this bug (and is happening b/c of
glib's & webkit's threads).

It can be reproduced with either the attached script or one of the
following one-liners​:

perl -MGtk2 -MGtk2​::WebKit -e '$SIG{CHLD} = sub { warn }; Gtk2->init;
my $wiew = Gtk2​::WebKit​::WebView->new; $w=Gtk2​::Window->new; $w-

add($view); Gtk2->main'

perl -MGtk3 -MGtk3​::WebKit -e '$SIG{CHLD} = sub { warn @​_ }; Gtk3-

init; my $wiew = Gtk3​::WebKit​::WebView->new; $w=Gtk3​::Window->new;
$w->add($view); Gtk3->main'

This sounds like csighandler is running in a thread that doesn't have any associated perl interpreter. One solution might be to block SIGCHLD (and possibly other signals) during thread creation (see also Signal​::Mask or POSIX​::sigprocmask), that way the signal will never be delivered to them (unless they accidentally unblock it).

Leon

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2014

From thierry.vignaud@gmail.com

On Tue Jan 07 18​:12​:41 2014, LeonT wrote​:

This sounds like csighandler is running in a thread that doesn't have
any associated perl interpreter. One solution might be to block
SIGCHLD (and possibly other signals) during thread creation (see also
Signal​::Mask or POSIX​::sigprocmask), that way the signal will never be
delivered to them (unless they accidentally unblock it).

As stated in my initial report, I do not have control over the threads
creation. My tools are mono threaded but some libraries they use
(GNOME's glib, WebKit) do create some threads for their own purpose.
I've no control over that.

So I would have to identify every places in the libraries that can result
in creating threads.

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2014

From @shlomif

I am able to reproduce this problem with a perl built like so​:

#!/bin/sh
rm -f config.sh Policy.sh
sh Configure -de -Dprefix="$HOME"/apps/perl/5.18.x-maint -Doptimize='-g' \
  -Duseithreads -Dusedevel

from the Git maint5.18 branch, on Mageia Linux x86-64 4 Cauldron, and after installing the Gtk2 and Gtk2​::WebKit modules from CPAN.

When I run the program as my normal user everything runs fine. When I run it as root, it crashes. When I run it under gdb as root, the program does not crash. Let me know if I can be of further assistance.

Regards,

-- Shlomi Fish

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2014

From @tonycoz

On Tue Jan 07 18​:12​:41 2014, LeonT wrote​:

This sounds like csighandler is running in a thread that doesn't have
any associated perl interpreter. One solution might be to block
SIGCHLD (and possibly other signals) during thread creation (see also
Signal​::Mask or POSIX​::sigprocmask), that way the signal will never be
delivered to them (unless they accidentally unblock it).

I'll look at fixing this as part of my 81074 work.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jan 9, 2014

From thierry.vignaud@gmail.com

On 8 January 2014 01​:48, Tony Cook via RT <perlbug-followup@​perl.org> wrote​:

Which version of perl is this backtrace from?

Is it a vendor patched perl?

This is perl-5.18.1 as provided by Mageia and is indeed patched by vendor​:
See http​://svnweb.mageia.org/packages/cauldron/perl/current/SOURCES/
for patches applied by Mageia

@soig
Copy link

soig commented Jan 31, 2020

Looks that this doesn't happen anymore as of perl-5.30.1

@xenu xenu removed the Severity Low label Dec 29, 2021
@demerphq
Copy link
Collaborator

demerphq commented Sep 8, 2022

Closing as the bug is reported to be fixed.

@demerphq demerphq closed this as completed Sep 8, 2022
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

4 participants