Bug 22932 - child processes inherit the listening sockets opened by xsm
Summary: child processes inherit the listening sockets opened by xsm
Status: RESOLVED FIXED
Alias: None
Product: xorg
Classification: Unclassified
Component: Lib/ICE (show other bugs)
Version: unspecified
Hardware: x86 (IA32) Linux (All)
: medium normal
Assignee: Xorg Project Team
QA Contact: Xorg Project Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-24 04:54 UTC by Kalle Olavi Niemitalo
Modified: 2010-05-11 07:43 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Kalle Olavi Niemitalo 2009-07-24 04:54:18 UTC
When I run xsm from ~/.xsession, it creates several sockets and
listens to them.  The file descriptors it opens for these sockets get
pointlessly inherited by child processes, causing warnings from LVM2
utilities.  xsm should make the file descriptors close on exec.

$ ls -l /proc/$$/fd
total 0
lrwx------ 1 Kalle Kalle 64 Jul 24 13:38 0 -> /dev/pts/8
lrwx------ 1 Kalle Kalle 64 Jul 24 13:38 1 -> /dev/pts/8
lrwx------ 1 Kalle Kalle 64 Jul 24 13:38 10 -> /dev/tty
lrwx------ 1 Kalle Kalle 64 Jul 24 13:38 2 -> /dev/pts/8
lrwx------ 1 Kalle Kalle 64 Jul 24 13:38 4 -> socket:[201881]
lrwx------ 1 Kalle Kalle 64 Jul 24 13:38 5 -> socket:[201882]
lrwx------ 1 Kalle Kalle 64 Jul 24 13:38 6 -> socket:[201883]
lrwx------ 1 Kalle Kalle 64 Jul 24 13:38 7 -> socket:[201884]
$ echo $SESSION_MANAGER
local/Astalo:@/tmp/.ICE-unix/22999,unix/Astalo:/tmp/.ICE-unix/22999,inet6/Astalo:49905,inet/Astalo:52368
$ su
Password: 
# vgs
File descriptor 4 (socket:[201881]) leaked on vgs invocation. Parent PID 23063: dash
File descriptor 5 (socket:[201882]) leaked on vgs invocation. Parent PID 23063: dash
File descriptor 6 (socket:[201883]) leaked on vgs invocation. Parent PID 23063: dash
File descriptor 7 (socket:[201884]) leaked on vgs invocation. Parent PID 23063: dash
  VG    #PV #LV #SN Attr   VSize   VFree  
  vgr0a   2   1   0 wz--n- 204.44G 189.44G
  vgr1a   2   1   0 wz--n-  18.62G  16.62G
  vgr1b   2  15   0 wz--n- 185.81G  97.12G
# netstat -ape | grep '20188[1234]'
tcp        0      0 *:52368                 *:*                     LISTEN     Kalle      201882     22999/xsm           
tcp6       0      0 *:49905                 *:*                     LISTEN     Kalle      201881     22999/xsm           
unix  2      [ ACC ]     STREAM     LISTENING     201883   22999/xsm           @/tmp/.ICE-unix/22999
unix  2      [ ACC ]     STREAM     LISTENING     201884   22999/xsm           /tmp/.ICE-unix/22999
# 

To create these sockets, xsm uses libICE, which in turn uses
source code from xtrans.  In X11 Release 6 Public Patch #08
<http://www.umich.edu/~archive/x11/r6-src/fixes/fix-08>,
IceAcceptConnection() and IceOpenConnection() were changed to
call _IceTransSetOption (newconn, TRANS_CLOSEONEXEC, 1); but
IceListenForConnections() does no such thing.  Because libICE
apparently expects callers to access the listening sockets only
via the opaque typedef struct _IceListenObj *IceListenObj, and
these structures do not survive the address-space change in exec,
I don't think it makes sense to keep the file descriptors open
across exec either.

Please make IceListenForConnections() set the sockets close-on-exec.

Reproduced with Debian sources:

libICE	from libice 2:1.0.5-1
libSM	from libsm 2:1.1.0-2
libX	from libx11 2:1.0.0-6
libXaw7 from libxaw 2:1.0.5-2
libXmu	from libxmu 1:1.0.1-3
libXt	from libxt 1:1.0.0-4
xsm	from x11-session-utils 7.3+1
Xtrans	from xtrans 1.2.3-3

Forwarded from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=538248
Comment 1 Julien Cristau 2010-05-11 07:43:42 UTC
Should be fixed on git master, thanks.

commit 1967c04c021a4cfd7b3cdd4efdc13610b4385a65
Author: Julien Cristau <jcristau@debian.org>
Date:   Tue May 11 16:36:20 2010 +0200

    Set the close-on-exec flag for listening sockets
    
    This prevents xsm from leaking file descriptors to the processes it
    starts.
    
    X.Org bug#22932 <http://bugs.freedesktop.org/show_bug.cgi?id=22932>
    
    Reported-by: Kalle Olavi Niemitalo <kon@iki.fi>
    Signed-off-by: Julien Cristau <jcristau@debian.org>


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.