Browse Source

Fix: deadlock

Rod Hynes 7 years ago
parent
commit
6c0bd5a9bc
1 changed files with 9 additions and 7 deletions
  1. 9 7
      psiphon/server/tunnelServer.go

+ 9 - 7
psiphon/server/tunnelServer.go

@@ -2505,13 +2505,6 @@ func (sshClient *sshClient) isPortForwardPermitted(
 	remoteIP net.IP,
 	port int) bool {
 
-	sshClient.Lock()
-	defer sshClient.Unlock()
-
-	if !sshClient.handshakeState.completed {
-		return false
-	}
-
 	// Disallow connection to loopback. This is a failsafe. The server
 	// should be run on a host with correctly configured firewall rules.
 	if remoteIP.IsLoopback() {
@@ -2533,6 +2526,15 @@ func (sshClient *sshClient) isPortForwardPermitted(
 		}
 	}
 
+	// Don't lock before calling logBlocklistHits.
+	sshClient.Lock()
+	defer sshClient.Unlock()
+
+	// Client must complete handshake before port forwards are permitted.
+	if !sshClient.handshakeState.completed {
+		return false
+	}
+
 	// Traffic rules checks.
 
 	var allowPorts []int