Your message dated Thu, 09 Jun 2016 22:50:36 +0000
with message-id <[email protected]>
and subject line Bug#640158: fixed in vnc4 4.1.1+X4.3.0-38
has caused the Debian Bug report #640158,
regarding vnc4server: 100% CPU hang when run from inetd in nowait mode
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
640158: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=640158
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: vnc4
Version: 4.1.1+X4.3.0-37
Severity: normal
Tags: patch
User: [email protected]
Usertags: origin-ubuntu oneiric ubuntu-patch


I have been experiencing this bug for several years but I finally decided to 
investigate it. I run Xvnc through xinetd and I often find that there are 
left-over Xvnc processes each consuming 100% CPU. They tend to crop up when a 
client disconnects. In particular, scanning ports with nmap produces the 
problem every time.

I've tracked down the problem and implemented a fix. The issue is that Xvnc in 
inetd mode detects whether it is run as "wait" or "nowait" by checking if the 
inetd socket has a valid peer name with getpeername(). If it has a valid peer 
name then it assumes nowait mode, otherwise it assumes wait mode. But this is 
unreliable, because if it is run in nowait mode and a client connects and 
disconnects very quickly then the socket will no longer have a valid peer name 
when Xvnc checks and it will mistakenly use wait mode. The 100% CPU results 
from repeatedly trying to call accept() on the socket in the select loop.

My solution is to instead detect wait vs. nowait via getsockopt(..., 
SOL_SOCKET, SO_ACCEPTCONN, ...), which works reliably in both modes.

*** /tmp/tmpkCQys0
I have sent the attached patch to Ubuntu, but I am sending it to Debian too 
because there is nothing Ubuntu-specific about it.


  * Fix 100% CPU hang when run from inetd in nowait mode if a client connects 
and disconnects quickly (e.g., nmap).


Thanks for considering the patch.


-- System Information:
Debian Release: squeeze/sid
  APT prefers natty-updates
  APT policy: (500, 'natty-updates'), (500, 'natty-security'), (500, 'natty')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.38-10-generic (SMP w/8 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
diff -u vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.h vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.h
--- vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.h
+++ vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.h
@@ -59,8 +59,7 @@
     virtual void shutdown();
 
     static bool enableNagles(int sock, bool enable);
-    static bool isSocket(int sock);
-    static bool isConnected(int sock);
+    static bool isListening(int sock);
     static int getSockPort(int sock);
   private:
     bool closeFd;
diff -u vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.cxx vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.cxx
--- vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.cxx
+++ vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.cxx
@@ -282,18 +282,12 @@
   return true;
 }
 
-bool TcpSocket::isSocket(int sock)
+bool TcpSocket::isListening(int sock)
 {
-  struct sockaddr_in info;
-  VNC_SOCKLEN_T info_size = sizeof(info);
-  return getsockname(sock, (struct sockaddr *)&info, &info_size) >= 0;
-}
-
-bool TcpSocket::isConnected(int sock)
-{
-  struct sockaddr_in info;
-  VNC_SOCKLEN_T info_size = sizeof(info);
-  return getpeername(sock, (struct sockaddr *)&info, &info_size) >= 0;
+  int listening = 0;
+  VNC_SOCKLEN_T listening_size = sizeof(listening);
+  return getsockopt(sock, SOL_SOCKET, SO_ACCEPTCONN, &listening,
+                    &listening_size) >= 0 && listening;
 }
 
 int TcpSocket::getSockPort(int sock)
diff -u vnc4-4.1.1+xorg4.3.0/unix/xc/programs/Xserver/vnc/vncExtInit.cc vnc4-4.1.1+xorg4.3.0/unix/xc/programs/Xserver/vnc/vncExtInit.cc
--- vnc4-4.1.1+xorg4.3.0/unix/xc/programs/Xserver/vnc/vncExtInit.cc
+++ vnc4-4.1.1+xorg4.3.0/unix/xc/programs/Xserver/vnc/vncExtInit.cc
@@ -160,8 +160,7 @@
         network::TcpListener* listener = 0;
         network::TcpListener* httpListener = 0;
         if (scr == 0 && vncInetdSock != -1) {
-          if (network::TcpSocket::isSocket(vncInetdSock) &&
-              !network::TcpSocket::isConnected(vncInetdSock))
+          if (network::TcpSocket::isListening(vncInetdSock))
           {
             listener = new network::TcpListener(0, 0, vncInetdSock, true);
             vlog.info("inetd wait");
diff -u vnc4-4.1.1+xorg4.3.0/debian/changelog vnc4-4.1.1+xorg4.3.0/debian/changelog
only in patch2:
unchanged:
--- vnc4-4.1.1+xorg4.3.0.orig/debian/patches/fix-100-percent-cpu-hang-in-inetd-mode.patch
+++ vnc4-4.1.1+xorg4.3.0/debian/patches/fix-100-percent-cpu-hang-in-inetd-mode.patch
@@ -0,0 +1,53 @@
+diff -ur vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.cxx vnc4-4.1.1+xorg4.3.0.new/common/network/TcpSocket.cxx
+--- vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.cxx	2011-09-02 13:30:44.000000000 -0700
++++ vnc4-4.1.1+xorg4.3.0.new/common/network/TcpSocket.cxx	2011-09-01 18:17:07.074243662 -0700
+@@ -282,18 +282,12 @@
+   return true;
+ }
+ 
+-bool TcpSocket::isSocket(int sock)
++bool TcpSocket::isListening(int sock)
+ {
+-  struct sockaddr_in info;
+-  VNC_SOCKLEN_T info_size = sizeof(info);
+-  return getsockname(sock, (struct sockaddr *)&info, &info_size) >= 0;
+-}
+-
+-bool TcpSocket::isConnected(int sock)
+-{
+-  struct sockaddr_in info;
+-  VNC_SOCKLEN_T info_size = sizeof(info);
+-  return getpeername(sock, (struct sockaddr *)&info, &info_size) >= 0;
++  int listening = 0;
++  VNC_SOCKLEN_T listening_size = sizeof(listening);
++  return getsockopt(sock, SOL_SOCKET, SO_ACCEPTCONN, &listening,
++                    &listening_size) >= 0 && listening;
+ }
+ 
+ int TcpSocket::getSockPort(int sock)
+diff -ur vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.h vnc4-4.1.1+xorg4.3.0.new/common/network/TcpSocket.h
+--- vnc4-4.1.1+xorg4.3.0/common/network/TcpSocket.h	2011-09-02 13:30:44.000000000 -0700
++++ vnc4-4.1.1+xorg4.3.0.new/common/network/TcpSocket.h	2011-09-01 18:17:25.524243654 -0700
+@@ -59,8 +59,7 @@
+     virtual void shutdown();
+ 
+     static bool enableNagles(int sock, bool enable);
+-    static bool isSocket(int sock);
+-    static bool isConnected(int sock);
++    static bool isListening(int sock);
+     static int getSockPort(int sock);
+   private:
+     bool closeFd;
+diff -ur vnc4-4.1.1+xorg4.3.0/unix/xc/programs/Xserver/vnc/vncExtInit.cc vnc4-4.1.1+xorg4.3.0.new/unix/xc/programs/Xserver/vnc/vncExtInit.cc
+--- vnc4-4.1.1+xorg4.3.0/unix/xc/programs/Xserver/vnc/vncExtInit.cc	2011-09-02 13:30:44.000000000 -0700
++++ vnc4-4.1.1+xorg4.3.0.new/unix/xc/programs/Xserver/vnc/vncExtInit.cc	2011-09-01 18:15:50.874243690 -0700
+@@ -160,8 +160,7 @@
+         network::TcpListener* listener = 0;
+         network::TcpListener* httpListener = 0;
+         if (scr == 0 && vncInetdSock != -1) {
+-          if (network::TcpSocket::isSocket(vncInetdSock) &&
+-              !network::TcpSocket::isConnected(vncInetdSock))
++          if (network::TcpSocket::isListening(vncInetdSock))
+           {
+             listener = new network::TcpListener(0, 0, vncInetdSock, true);
+             vlog.info("inetd wait");

--- End Message ---
--- Begin Message ---
Source: vnc4
Source-Version: 4.1.1+X4.3.0-38

We believe that the bug you reported is fixed in the latest version of
vnc4, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to [email protected],
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Ola Lundqvist <[email protected]> (supplier of updated vnc4 package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing [email protected])


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Thu, 09 Jun 2016 22:46:59 +0200
Source: vnc4
Binary: vnc4server xvnc4viewer
Architecture: source amd64
Version: 4.1.1+X4.3.0-38
Distribution: unstable
Urgency: low
Maintainer: Ola Lundqvist <[email protected]>
Changed-By: Ola Lundqvist <[email protected]>
Description:
 vnc4server - Virtual network computing server software
 xvnc4viewer - Virtual network computing client software for X
Closes: 421815 471996 492015 568707 610852 640158 656862 767957 780804
Changes:
 vnc4 (4.1.1+X4.3.0-38) unstable; urgency=low
 .
   * Updated to debhelper compatibility 9.
   * Applied a patch from Timo Juhani Lindfors <[email protected]>
     that solves a segfault problem. Closes: #492015.
   * Applied a patch from Scott Bigham <[email protected]> to allow
     the -via option. Closes: #568707.
   * Applied a patch from Moritz Muehlenhoff <[email protected]> to enable
     harden build flags. Closes: #656862.
   * Applied a patch from Tristan Schmelcher
     <[email protected]> to avoid a 100% CPU problem.
     Closes: #640158.
   * Changed the default generated init script. Closes: #471996.
   * Applied a patch to solve a segfault problem. Closes: #421815.
   * Applied a patch to make it build on hurd-i386. Closes: #610852.
   * Applied a patch to make it build on ppc64el. Closes: #767957.
   * Applied a patch to make it build on mips64el. Closes: #780804.
Checksums-Sha1:
 1652c4e2ebeeca14dced23d9179a79a249f6bfe1 1795 vnc4_4.1.1+X4.3.0-38.dsc
 8416eb9433713cffeb5469c9d7c62ac289d5d191 77056 vnc4_4.1.1+X4.3.0-38.diff.gz
 35e2ef95b393fc30a3148c43c47c624318961a4d 1593876 
vnc4server_4.1.1+X4.3.0-38_amd64.deb
 bc1912f9ecf9a1e7b4495fa6adb1f75d98d0fc65 124962 
xvnc4viewer_4.1.1+X4.3.0-38_amd64.deb
Checksums-Sha256:
 2ec804a584c8dfe6ee0b6403c065a89f30d5fc23bc1f960c2f478c769dc16e71 1795 
vnc4_4.1.1+X4.3.0-38.dsc
 fdb1e84ad60a8232b577dcedebfbd25434caa62237569c0086b080464602a79e 77056 
vnc4_4.1.1+X4.3.0-38.diff.gz
 fd44173ebc30e35b97eb92acf62c06f365114f320112a12cd6a5e91ee45c543e 1593876 
vnc4server_4.1.1+X4.3.0-38_amd64.deb
 013cbb255b0b291db68fd9403e3777614ef49cf884da3d0785fc6d686054898c 124962 
xvnc4viewer_4.1.1+X4.3.0-38_amd64.deb
Files:
 e5a63dd6acd352c95dab53f3e0634ad9 1795 x11 optional vnc4_4.1.1+X4.3.0-38.dsc
 6946d175a84f7dc1697dd0a5235113cf 77056 x11 optional 
vnc4_4.1.1+X4.3.0-38.diff.gz
 2af3ffdca304dcfd699263adc614a699 1593876 x11 optional 
vnc4server_4.1.1+X4.3.0-38_amd64.deb
 0a988f7e1b0696ba4d4737b991881cef 124962 net optional 
xvnc4viewer_4.1.1+X4.3.0-38_amd64.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCAAGBQJXWd/yAAoJEF6Q3PqUJodvf+8P/jvvL9KUfFZIYdWHFZpiGi5R
gE/VvcxFok1a7yQQ5nHaU4LCgfjUUo8Dqztm2irCh27VWQugorySVzsgluIz9Rqy
NnOr0/GX+W5gZlO+FpG2lYTkZC1ewhMAgOEfj3pd8FqFN4JoKzRrP+XLgGdhmewW
4rHJlibRbZcurzm5bxNkt+Byy2K0gTkG8HNf/0ajXsEBpvxElKlRKe8ay5c56dka
qcb5pwT/w5K/D5npldFagMcItDjoaGvmHgugn/M/dKfHTUwf5S3NRO/L0XT9ABbA
AloIdpQstua9OI7H3DtRSBQv6L2xo9kEVqOZsDjwwCRLp0MEQyHb5DWgAWUY4gcQ
4aa2exR2VmSJ5KskZKAZ0vBlI9w2dzWSnACTJy/jinPSQ9smplQ1xWdA5S82M8qj
lJ+1zWWfH32HS8cEqk5txZ4WAEc+lBE0visgNmNxdGMXqLykoYKkJv0Rr6sS81Xi
LC+l+oI76/BmNzR6DkP9dURxkSs2SxNkbCI8kj6n+c45nSlVvGTEyAT2Ewz9eCuE
Ak4f1v0BVlw/c+HyYP5YWBoh+TFuBd/s5qyEFqZOD1KhfURorqxx6BwJOl4XBlL8
FOjVCQtb2ibkuvdt+F4qep/78SI5Qo87tMoXIWwfyPVQGrjuZmREzpZgWCF+rId0
dNmwKDliVgVfsXeK5w5u
=LTUN
-----END PGP SIGNATURE-----

--- End Message ---

Reply via email to