Bug 18879 - File-Deskriptor Leck in univention-session
File-Deskriptor Leck in univention-session
Status: CLOSED FIXED
Product: Z_Univention Corporate Client (UCC)
Classification: Unclassified
Component: Terminal services
unspecified
Other Linux
: P5 normal
: UCC 1.0
Assigned To: Moritz Muehlenhoff
Felix Botner
: interim-3
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-07-01 12:42 CEST by Philipp Hahn
Modified: 2013-03-26 09:14 CET (History)
2 users (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:
hahn: Patch_Available+


Attachments
Fix file descriptor leak and compiler warnings (5.22 KB, patch)
2010-07-08 15:44 CEST, Philipp Hahn
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp Hahn univentionstaff 2010-07-01 12:42:31 CEST
Nach einem "exec >&3- ; lsof -p $$" ist meine Session abgestürzt. Ohne das 'exec' davor zeigt ein "lsof -np $$ | tail -n 3" folgendes:

bash    4647 phahn    3u  IPv4 155761620              TCP XXX.YYY.0.81:kshell->XXX.YYY.0.143:39643 (ESTABLISHED)
bash    4647 phahn    4u  IPv4 155761620              TCP XXX.YYY.0.81:kshell->XXX.YYY.0.143:39643 (ESTABLISHED)
bash    4647 phahn  255u   CHR    136,44               47 /dev/pts/44

Diese beiden TCP-Verbindungen scheinen von univention-session geöffnet worden zu sein und werden an alle davon geforkten (in diesem Falls sind das alle meine) Prozesse weitervererbt.

Bisher nur bei mir aufgetreten, nicht bei einem Kollegen. Aus- und Wiederanmelden führt zur gleichen Situation. Ein Neustart des Thin-Clients brachte auch keine Änderung.

Keine Ahnung, wofür diese beiden Sockets genau verwendet werden (Session-Verwaltung und remove-Befehlsausführung), aber ein unvorsichtiges Schreiben sollte nicht zu einem Beenden der Sitzung führen. Auf jeden Fall sollten die File-Descriptoren per close() geschlossen werden oder zumindest nicht weiter an Kindprozesse vererbt werden. Am einfachsten durch FD_CLOEXEC:

--- univention-thin-client-login/src/command_socket.c   (Revision 18117)
+++ univention-thin-client-login/src/command_socket.c   (Arbeitskopie)
@@ -114,12 +114,19 @@

 void command_socket_init ( const char* path )
 {
+  int flags;
   if ( debug_level )
     debug_printf( "init new command socket: %s\n", path );
   memset ( &sock_name, 0, sizeof ( struct sockaddr_un ) );
   sock_name.sun_family = AF_UNIX;
   strncpy ( sock_name.sun_path, path, UNIX_MAX_PATH );
   sock_fd = socket ( PF_UNIX, SOCK_STREAM, 0 );
+  flags = fcntl(sock_fd, F_GETFD);
+  if (flags == -1)
+        fatal_perror("Error getting socket status\n");
+  flags |= FD_CLOEXEC;
+  if (fcntl(sock_fd, F_SETFD, flags) == -1)
+        fatal_perror("Error setting socket status\n");
 }

 void command_socket_server_init ( const char* sockname )
Comment 1 Andreas Büsching univentionstaff 2010-07-01 12:58:27 CEST
> ssh  root@server lsof -p 4454
root@server's password:
COMMAND    PID  USER   FD   TYPE    DEVICE    SIZE     NODE NAME
univentio 4454 user1  cwd    DIR       8,1    4096 19940362 /home/user1
univentio 4454 user1  rtd    DIR       8,1    4096        2 /
univentio 4454 user1  txt    REG       8,1   29176 35134938 /usr/bin/univention-session
univentio 4454 user1  mem    REG       8,1 1375536 45803425 /lib/libc-2.7.so
univentio 4454 user1  mem    REG       8,1    7816 35131622 /usr/lib/libuniventiondebug.so.0.0.1
univentio 4454 user1  mem    REG       8,1    9024 35128461 /usr/lib/libuniventionconfig.so.0.0.1
univentio 4454 user1  mem    REG       8,1  119288 45804075 /lib/ld-2.7.so
univentio 4454 user1    1w   REG       8,1     199 19940548 /home/user1/.KDE-stdout
univentio 4454 user1    2w   REG       8,1   12341 19940571 /home/user1/.KDE-stderr
univentio 4454 user1    3u  IPv4 155761620              TCP server.domain.local:kshell->HPt5735-04.domain.local:39643 (ESTABLISHED)
univentio 4454 user1    4u  IPv4 155761620              TCP server.domain.local:kshell->HPt5735-04.domain.local:39643 (ESTABLISHED)
Comment 2 Philipp Hahn univentionstaff 2010-07-08 14:09:14 CEST
Der Patch aus Comment 1 geht in die falsche Richtung, in "srv/connection.c" ist das eigentliche Problem:

void init_server_pipes ( void )
{
»···/* FIXME: what is fd 3? maybe use dup() instead */
»···send_fd = dup2 ( STDOUT_FILENO, 3 );
»···if ( send_fd < 0 )
»···»···fatal_perror ( "dup failed" );
»···close ( STDOUT_FILENO );
»···if ( debug_level )
»···»···debug_printf ( "to_client fd=%d\n", send_fd );
»···/* FIXME: see above */
»···recv_fd = dup2 ( STDIN_FILENO, 4);
»···if ( recv_fd < 0 )
»···»···fatal_perror ( "dup failed" );
»···close ( STDIN_FILENO );

Der Client(univention-login) baut per kshell eine Verbindung zum Terminal-Server auf, wo der Server(univention-session) gestartet wird. Diese kshell-Verbindung ist besagte TCP-Verbindung. Warum wird aber diese bidirektionale Verbindung auf die File-Deskriptoren 3 und 4 dupliziert? (Gemerged wurde das ganze in svn1790)

Am sinnvollsten sollte dieser Code-Abschnitt entfernt werden.
Alternativ sessions/KDE.Session so modifizieren, daß ein Wrapper statt "startkde" aufgerufen wird, der FD 3 und 4 schließt.
Mein Work-Around: ~/.kde/env/000cloexec.sh
#! /bin/sh
# Bug #18879: univention-session file descriptor leak
# sourced by /usr/bin/startkde
test -S /proc/self/fd/3 && exec 3>&-
test -S /proc/self/fd/4 && exec 4>&-

Sicherheitsbedenken: Über die noch offenen File-Deskriptoren ist es möglich, auf dem Thin-Client Programme ausführen zu lassen. Das ist aber sowieso bereits über ~/.univention-thin-client-session/ möglich, von daher unkritisch.
Comment 3 Philipp Hahn univentionstaff 2010-07-08 15:44:36 CEST
Created attachment 2491 [details]
Fix file descriptor leak and compiler warnings

* Fix file descriptor leak in univention-session (Bug #18879)
* Fix compiler warning and typo in Makefile.
Comment 4 Moritz Muehlenhoff univentionstaff 2012-09-12 11:46:12 CEST
Der Patch wurde im Rahmen der Integration von univention-session übernommen.
Comment 5 Stefan Gohmann univentionstaff 2012-10-31 08:33:42 CET
Die QA kann erst sinnvoll nach der Umsetzung von Bug #28349 erfolgen.
Comment 6 Stefan Gohmann univentionstaff 2012-12-21 09:47:47 CET
QA zu interim-3, da aufgrund von Bug #29105 ggf. univention-session noch entfernt wird.
Comment 7 Moritz Muehlenhoff univentionstaff 2013-01-23 11:59:24 CET
univention-session is no longer used in UCC and has been removed.
Comment 8 Felix Botner univentionstaff 2013-01-24 09:16:29 CET
(In reply to comment #7)
> univention-session is no longer used in UCC and has been removed.

that's right
Comment 9 Moritz Muehlenhoff univentionstaff 2013-03-26 09:14:45 CET
UCC 1.0 has been released: 
http://forum.univention.de/viewtopic.php?f=26&t=2417
http://forum.univention.de/viewtopic.php?f=54&t=2418

If this error occurs again, please use "Clone This Bug".