Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 555436 - kde-base/pykde4 patch gets fork() backwards and subtly breaks DBus
Summary: kde-base/pykde4 patch gets fork() backwards and subtly breaks DBus
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] KDE (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo KDE team
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2015-07-20 09:51 UTC by Hector Martin
Modified: 2016-03-18 12:17 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
kpythonpluginfactorywrapper.c-r2 (kpythonpluginfactorywrapper.c-r1,1.42 KB, text/x-csrc)
2016-01-16 04:37 UTC, Hector Martin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hector Martin 2015-07-20 09:51:45 UTC
This has been going on for years:
https://bugs.kde.org/show_bug.cgi?id=289530

In this case, adding Veromix to the plasma panel breaks the Device Notifier, but I'm sure this will cause other weird issues with Python plugins elsewhere.

Thus out this is a Gentoo patch bug. The fork() is backwards here:

--- /usr/portage/kde-base/pykde4/files/kpythonpluginfactorywrapper.c-r1 2015-07-20 18:40:17.634644788 +0900
+++ /usr/local/portage/kde-base/pykde4/files/kpythonpluginfactorywrapper.c-r1   2015-07-20 18:40:09.528667127 +0900
@@ -15,7 +15,7 @@
        int pipefd[2];
        pipe(pipefd);
        pid_t cpid = fork();
-       if (cpid == 0) {
+       if (cpid != 0) {
                close(pipefd[1]);
                read(pipefd[0], out, VERSION_LEN);
        } else {

With the broken code, the parent execs and the child lives on, effectively changing the PID of the entire process out from under itself, which borks DBus which assumes that PIDs do not change for connections.

I tested the change and confirmed that it fixes the issue.

Reproducible: Always

Steps to Reproduce:
1. Install and enable Veromix and Device Notifier in the system tray
2. Try to mount a device with Device Notifier

Actual Results:  
Mount fails, syslog error messages about not being able to access /proc/<pid>/environ from consolekit.

Expected Results:  
Mount completes successfully.

Portage 2.2.20 (python 2.7.10-final-0, hardened/linux/amd64, gcc-4.9.3, glibc-2.20-r2, 4.0.8-hardened x86_64)
=================================================================
System uname: Linux-4.0.8-hardened-x86_64-Intel-R-_Core-TM-_i7-3820QM_CPU_@_2.70GHz-with-gentoo-2.2
KiB Mem:    32844256 total,  26860484 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Sun, 19 Jul 2015 16:15:01 +0000
sh bash 4.3_p39
ld GNU ld (Gentoo 2.25 p1.2) 2.25
distcc 3.2rc1 x86_64-pc-linux-gnu [disabled]
ccache version 3.2.2 [disabled]
app-shells/bash:          4.3_p39::gentoo
dev-java/java-config:     2.2.0::gentoo
dev-lang/perl:            5.22.0::gentoo
dev-lang/python:          2.7.10::gentoo, 3.4.3::gentoo
dev-util/ccache:          3.2.2::gentoo
dev-util/cmake:           3.2.3::gentoo
dev-util/pkgconfig:       0.28-r3::gentoo
sys-apps/baselayout:      2.2::gentoo
sys-apps/openrc:          0.17::gentoo
sys-apps/sandbox:         2.6-r1::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69-r1::gentoo
sys-devel/automake:       1.11.6-r1::gentoo, 1.12.6::gentoo, 1.13.4::gentoo, 1.14.1::gentoo, 1.15::gentoo
sys-devel/binutils:       2.25-r1::gentoo
sys-devel/gcc:            4.9.3::gentoo
sys-devel/gcc-config:     1.8::gentoo
sys-devel/libtool:        2.4.6-r1::gentoo
sys-devel/make:           4.1-r1::gentoo
sys-kernel/linux-headers: 4.1::gentoo (virtual/os-headers)
sys-libs/glibc:           2.20-r2::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.es.gentoo.org/gentoo-portage
    priority: -1000

klondike
    location: /var/lib/layman/klondike
    sync-type: git
    sync-uri: git://anongit.gentoo.org/user/klondike.git
    masters: gentoo
    priority: 50

proaudio
    location: /var/lib/layman/proaudio
    masters: gentoo
    priority: 50

science
    location: /var/lib/layman/science
    masters: gentoo
    priority: 50

steam-overlay
    location: /var/lib/layman/steam-overlay
    masters: gentoo
    priority: 50

local
    location: /usr/local/portage
    masters: gentoo
    priority: 100

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="* -@EULA Google-TOS ut2003 PUEL Q3AEULA Introversion dlj-1.1 skype-eula cadsoft AdobeFlash-10.1 AdobeFlash-10 AdobeFlash-9.0.31.0 googleearth google-talkplugin Oracle-BCLA-JavaSE AdobeFlash-10.3 AdobeFlash-11.x skype-4.0.0.7-copyright google-chrome NVIDIA-CUDA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=native -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /usr/share/config /usr/share/gnupg/qualified.txt /usr/share/maven-bin-3.2/conf /usr/share/themes/oxygen-gtk/gtk-2.0 /usr/share/themes/oxygen-gtk/gtk-3.0"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.6/ext-active/ /etc/php/cgi-php5.6/ext-active/ /etc/php/cli-php5.6/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-march=native -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS="--with-bdeps=y"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://gentoo.gg3.net/ ftp://ftp.iij.ad.jp/pub/linux/gentoo/ ftp://ftp.jaist.ac.jp/pub/Linux/Gentoo/"
LANG="en_US.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j6"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_EXTRA_OPTS="--timeout=180"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
USE="7zip X a52 aac aalib acl acpi addbookmarks additions addressbook akode alias alsa amarok amd64 amd64codecs anthy apache2 apng artswrappersuid asf aspell audiofile autoreplace avahi avi bash-completion berkdb bitmap-fonts bittorrent-external blender-game bluetooth bonjour branding bzip2 bzlib cairo calendar canna cdda cddb cdio cdparanoia cdr cgi chm cjk clamav cli connectionstatus consolekit contactnotes cracklib crypt css ctype cups curl cvs cxx daap dba dbus declarative device-mapper dillo djvu dlloader dri dts dv dvb dvd dvdr dvdread egl embedded enca encode equalizer examples exif faad fam fasttrack fbcondecor ffmpeg firefox3 flac flash fluidsynth font-server foomaticdb frei0r ftdi ftp g3dvl gallium gcrypt gd gdbm gif git glamor gles2 glitz gmp gnutella go gphoto2 gpm gs gsm gtk gtk2 h323 hackrf hardened hash highlight history httpd ibus iconv icu id3tag ieee1394 imagemagick imap immqt-bc inifile inkjar innodb ipv6 irc ithreads jabber jack jadetex java java6 javascript jingle jit joystick jpeg jpeg2k justify kate kde kipi kpathsea kqemu kvm ladspa laptop lcms lensfun libass libnotify libsamplerate libtiger libv4l2 lisamplerate llvm lm_sensors logrotate lv2 lvm lzma m17n-lib mad maildir matroska mbox mbrola mdnsresponder-compat melt midi mikmod mjpeg mmx mmxext mng mod modemmanager modplug modules moodbar moviepack moviesounds mozbranding mozcalendar mozdevelop mozsvg mozxmlterm mp3 mp4 mpeg mpeg4 mplayer msn mtp multilib musicbrainz mysql mysqli mythtv ncurses network networkmanager nfs nls nodrm nowlistening nptl nptlonly ntp numa nvidia offensive ogg oggvorbis openal opencl openct openexr opengl openmp opus oscar otr pam pango parted pax_kernel pcap pcre pcsc-lite pdf perl phonon pie plasma plotutils png policykit posix postproc ppds prime projectm protutils pulseaudio pyqt4 python qemu qemu-ifup qt qt3support qt4 quicktime rar readline realtime resolvconf rt2500pci rtc rtlsdr rtsp samba scanner sdk sdl session shout skins slang sna sndfile soap sockets sox speex spell sql sqlite srt sse sse2 ssl ssp startup-notification statistics stream subtitles subversion svg swat system-libvncserver taglib tcpd test-programs texteffect tga theora threads tiff tk transcode transmitter truetype truetype-fonts twolame type1-fonts udev udisks unicode upnp upower urandom usb utempter utf8 uxa v4l v4l2 video vim-syntax virt-network visualization vlm vorbis vpx wavpack webkit webpresence wifi wininst wmf wxwidgets wxwindows x264 xattr xcb xcomposite xforms xinerama xml xmlreader xmlrpc xmlwriter xmp xprint xpsmall xscreensaver xsl xtpax xulrunner xv xvid yahoo yv12 zeroconf zip zlib zsh-completion zvbi" ABI_X86="64" ALSA_CARDS="usb-audio virmidi loopback hda-intel" APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_dbd authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock dbd deflate dir disk_cache env expires ext_filter file_cache filter headers ident imagemap include info log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_http rewrite setenvif so speling status unique_id userdir usertrack vhost_alias slotmem_shm unixd" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="canon" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx mmxext sse sse2 sse3 ssse3 avx sse4_1 sse4_2" ELIBC="glibc" FOO2ZJS_DEVICES="sa315" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ublox ubx" INITNG_PLUGINS="also bash_launcher chdir chroot conflict cpout critical ctrlaltdel daemon_clean debug_commands envparser find fmon fstat history idleprobe initctl interactive iparser last limit lockfile logfile netdev netprobe ngc4 ngcs nge pause provide reload renice rlparser simple_launcher stcmd stdout suid syncron syslog sysreq unneeded usplash" INPUT_DEVICES="evdev keyboard mouse wacom synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="en en_US es es_ES ja ja_JP" LIRC_DEVICES="serial devinput" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_4" QEMU_SOFTMMU_TARGETS="x86_64 arm armeb ppc ppc64 mips mipsel s390x aarch64" QEMU_USER_TARGETS="x86_64 s390x arm armeb mips mipsel ppc ppc64 ppc64abi32 aarch64" RUBY_TARGETS="ruby22 ruby21 ruby20" SANE_BACKENDS="plustek" USERLAND="GNU" VIDEO_CARDS="intel nvidia" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
USE_PYTHON="2.7 3.4"
Unset:  CPPFLAGS, CTARGET, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS
Comment 1 Hector Martin 2015-07-20 09:53:42 UTC
Incidentally, the code also seems to leak pipefd[0]. That should be closed after the read(). Less of a showstopper but worth fixing too.
Comment 2 Hector Martin 2015-07-20 10:56:15 UTC
Probably also worth checking for error (cpid < 0) and doing something reasonable in that case too.
Comment 3 Andreas Sturmlechner gentoo-dev 2015-12-28 22:49:38 UTC
I was not able to reproduce this after going through the process of rebuilding plasma-workspace with USE=python, building pykde4 with python2_7 and installing veromix which, incidentally, also involved pulling in pulseaudio... what else could I try?
Comment 4 Hector Martin 2016-01-16 04:37:06 UTC
Created attachment 423016 [details]
kpythonpluginfactorywrapper.c-r2

I can't build pykde4 right due due to a different issue (sigh), but either way, whether the symptom can be reproduced or not (which is a rather convoluted code path involving dbus and a bunch of other moving parts), it's clear that the code is wrong, so why not just fix it?

Attached is a corrected kpythonpluginfactorywrapper.c. It fixes the bug, the fd leak, and also better handles errors. I'm not able to test it right now (though the simpler fix used in the original report did work) due to an unrelated pykde4 build failure, but as long as it doesn't cause an obvious regression, I don't see why it doesn't make sense to just use it.
Comment 5 Hector Martin 2016-01-16 04:53:50 UTC
Addendum: I worked around the unrelated build failure and I can confirm that the kpythonpluginfactorywrapper.c-r2 attached above builds correctly, and that I can't reproduce the original problem with it.
Comment 6 Johannes Huber (RETIRED) gentoo-dev 2016-03-11 13:35:06 UTC
Sorry I can not reproduce this problem. If this is still a issue please report this upstream and re-open in the case upstream patched something.
Comment 7 Hector Martin 2016-03-11 13:53:48 UTC
Uh, what? "Sorry, I cannot reproduce the problem, so let's close the bug, even though the code is obviously broken"? How does that make *any* sense?

Anyway, Portage is now in git (which it wasn't when I filed this bug), so I'll just send a pull request.
Comment 8 Hector Martin 2016-03-11 15:04:56 UTC
Pull request: https://github.com/gentoo/gentoo/pull/1032

New steps to reproduce are listed in the PR (demonstrating the underlying PID issue, not the effects from it which depend on subtleties in other libraries).

I've tested the patch on my own system. This is not an upstream issue because the bug is in a Gentoo patch.
Comment 9 Johannes Huber (RETIRED) gentoo-dev 2016-03-18 12:17:09 UTC
(In reply to Hector Martin from comment #8)
> Pull request: https://github.com/gentoo/gentoo/pull/1032
> 
> New steps to reproduce are listed in the PR (demonstrating the underlying
> PID issue, not the effects from it which depend on subtleties in other
> libraries).
> 
> I've tested the patch on my own system. This is not an upstream issue
> because the bug is in a Gentoo patch.

Thanks. https://github.com/gentoo/gentoo/commit/22aa5c8c729841148f66fb93c2f093d240d6b9bd