Uploaded image for project: 'MINA SSHD'
  1. MINA SSHD
  2. SSHD-902

Local port forwarding: EOF is not handled properly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 2.1.0
    • 2.1.0
    • None
    • OS: both Windows 10 and Red Hat Enterprise Linux Server release 7.4 (Maipo) Linux 4.1.12-124.19.2.el7uek.x86_64 x86_64
      JDK: 1.8.0_201
      SSHD: 2.1.0

    Description

      Set remote port to a real listening port but is not for DB connection. Start a local port forwarding. Try getting a connection through the established SSH tunnel. This operation is expected to be finished with some error, but it hangs.

      Reproduce steps:

      1. prepare a Linux server and find a listening port, such as 2049, which is not of DB listener.
      2. get attached demo code: ApacheServerApacheClientTest.java and AbstractServerCloseTestSupport.java. They are modified from the ones in mina-sshd-2.1.0\sshd-core\src\test\java\org\apache\sshd\common\forward. Please replace the corresponding ones.
      3. download ojdbc8.jar from https://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html? and add it to classpath.
      4. set up a local port forwarding tunnel by Putty or other tools. Set the forwarded local port to 37777, remote server/port to the server/port in step 1.
      5. run  ApacheServerApacheClientTest.java. It finishes with error like java.io.IOException: Got minus one from a read call. This is expected behavior.
      6. change org.apache.sshd.common.forward.AbstractServerCloseTestSupport#testLocalPortForwardOneBuffer: uncomment line "int serverPort = startLocalPF();" and comment line "int serverPort = 37777;"
      7. change org.apache.sshd.common.forward.ApacheServerApacheClientTest#createClient, set username, host and password to the ones in step 1.
      8. run  ApacheServerApacheClientTest.java again and it hangs.

      By capturing loopback packets, it can be found the interactions are same, but SSHD make different process from what Putty does. In attached snapshot, the "nfs" is of port 2049.

      Did a bit digging up, and it seems that EOF is not handled properly. Here is a call stack:

      handleEof:873, AbstractChannel (org.apache.sshd.common.channel)

      channelEof:498, AbstractConnectionService (org.apache.sshd.common.session.helpers)

      process:357, AbstractConnectionService (org.apache.sshd.common.session.helpers)

      doHandleMessage:626, AbstractSession (org.apache.sshd.common.session.helpers)

      handleMessage:559, AbstractSession (org.apache.sshd.common.session.helpers)

      decode:1542, AbstractSession (org.apache.sshd.common.session.helpers)

      messageReceived:520, AbstractSession (org.apache.sshd.common.session.helpers)

      messageReceived:63, AbstractSessionIoHandler (org.apache.sshd.common.session.helpers)

      handleReadCycleCompletion:339, Nio2Session (org.apache.sshd.common.io.nio2)

      onCompleted:318, Nio2Session$1 (org.apache.sshd.common.io.nio2)

      onCompleted:315, Nio2Session$1 (org.apache.sshd.common.io.nio2)

      lambda$completed$0:38, Nio2CompletionHandler (org.apache.sshd.common.io.nio2)

      run:-1, 391147216 (org.apache.sshd.common.io.nio2.Nio2CompletionHandler$$Lambda$73)

      doPrivileged:-1, AccessController (java.security)

      completed:37, Nio2CompletionHandler (org.apache.sshd.common.io.nio2)

      invokeUnchecked:126, Invoker (sun.nio.ch)

      run:218, Invoker$2 (sun.nio.ch)

      run:112, AsynchronousChannelGroupImpl$1 (sun.nio.ch)

      runWorker:1149, ThreadPoolExecutor (java.util.concurrent)

      run:624, ThreadPoolExecutor$Worker (java.util.concurrent)

      run:748, Thread (java.lang)

      Attachments

        1. AbstractServerCloseTestSupport.java
          12 kB
          Yumin Sang
        2. ApacheServerApacheClientTest.java
          5 kB
          Yumin Sang
        3. fixBasedOn2.1.0.zip
          15 kB
          Yumin Sang
        4. packets.PNG
          641 kB
          Yumin Sang

        Issue Links

          Activity

            People

              lgoldstein Lyor Goldstein
              ysang Yumin Sang
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m