Skip to content

Windows 7 x64 - sshd Unknown Error #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GT500org opened this issue Nov 24, 2016 · 6 comments
Closed

Windows 7 x64 - sshd Unknown Error #414

GT500org opened this issue Nov 24, 2016 · 6 comments

Comments

@GT500org
Copy link

I just tried to install version 0.0.3.0 on a Windows 7 x64 system, and when I start the sshd service I can't connect and the log simply fills with lines like the following (as in hundreds of thousands of them, very quickly):

11604 05:43:32 862 error: accept: Unknown error
11604 05:43:32 862 error: accept: Unknown error
11604 05:43:32 862 error: accept: Unknown error

If I stop the sshd service, and execute sshd.exe on the command line like sshd.exe -d then I get a repeated error in the Command Prompt that says the following:

accept: Unknown error
debug1: acceptEx - AcceptEx() ERROR:22, io:00000000003011F0
debug1: accept - ERROR: async io completed with error: -9978, io:00000000003011F0

There is nothing else listening to this port, and I have tried adding AddressFamily inet to sshd_config with no luck. There is no software firewall installed, security software is shut down while testing this, port 22 is forwarded in the router, and I'm at a loss for anything else I could try.

@manojampalam
Copy link
Contributor

As per https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx, this should be
WSAEINVAL10022
Invalid argument.
Some invalid argument was supplied (for example, specifying an invalid level to the setsockopt function). In some instances, it also refers to the current state of the socket—for instance, calling accept on a socket that is not listening.

Can you attach DEBUG3 logs from sshd? See https://github.com/PowerShell/Win32-OpenSSH/wiki/Troubleshooting%20Steps

@ywmail
Copy link

ywmail commented Dec 26, 2016

workaround: change the sshd windows login user to local user may fix this.

@Sp1l
Copy link

Sp1l commented Dec 30, 2016

Getting this same error on Windows 10 Enterprise x64 with OpenSSH-Win64

DEBUG3 output:

7636 13:35:37 977 debug2: signal() sig:2, handler:0000000000000001
7636 13:35:37 977 debug1: socket:428, io:00000194614F1E40, fd:3 
7636 13:35:37 977 debug3: w32_fcntl fd:3
7636 13:35:37 977 debug2: fd 3 setting O_NONBLOCK
7636 13:35:37 977 debug3: w32_fcntl fd:3
7636 13:35:37 977 debug3: w32_fcntl fd:3
7636 13:35:37 977 debug3: w32_setsockopt fd:3
7636 13:35:37 977 debug3: sock_set_v6only: set socket 3 IPV6_V6ONLY
7636 13:35:37 977 debug3: w32_setsockopt fd:3
7636 13:35:37 977 debug1: Bind to port 22 on ::.
7636 13:35:37 977 debug3: w32_bind fd:3
7636 13:35:37 977 debug3: w32_listen fd:3
7636 13:35:37 977 Server listening on :: port 22.
7636 13:35:37 977 debug1: socket:532, io:00000194614F1EF0, fd:4 
7636 13:35:37 977 debug3: w32_fcntl fd:4
7636 13:35:37 977 debug2: fd 4 setting O_NONBLOCK
7636 13:35:37 977 debug3: w32_fcntl fd:4
7636 13:35:37 977 debug3: w32_fcntl fd:4
7636 13:35:37 977 debug3: w32_setsockopt fd:4
7636 13:35:37 977 debug1: Bind to port 22 on 0.0.0.0.
7636 13:35:37 977 debug3: w32_bind fd:4
7636 13:35:37 977 debug3: w32_listen fd:4
7636 13:35:37 977 Server listening on 0.0.0.0 port 22.
7636 13:35:37 977 debug2: signal() sig:6, handler:00007FF799C9D7E0
7636 13:35:37 977 debug2: signal() sig:3, handler:00007FF799C9C470
7636 13:35:37 977 debug2: signal() sig:8, handler:00007FF799C9D8D0
7636 13:35:37 977 debug2: signal() sig:7, handler:00007FF799C9D8D0
7636 13:35:37 977 debug3: w32_select fd:3
7636 13:35:37 977 debug3: w32_select fd:4
7636 13:35:37 977 debug3: Total in fds:2
7636 13:35:37 977 debug2: on_select - io:00000194614F1E40 type:1 rd:1
7636 13:35:37 977 debug3: acceptEx - io:00000194614F1E40
7636 13:35:37 977 debug1: acceptEx - AcceptEx() ERROR:22, io:00000194614F1E40
7636 13:35:37 977 debug2: on_select - io:00000194614F1EF0 type:1 rd:1
7636 13:35:37 977 debug3: acceptEx - io:00000194614F1EF0
7636 13:35:37 977 debug3: wait() on 0 events and 0 children
7636 13:35:37 977 debug3: select - returning 1
7636 13:35:37 977 debug3: w32_accept fd:3
7636 13:35:37 977 debug3: accept - io:00000194614F1E40
7636 13:35:37 977 debug1: accept - ERROR: async io completed with error: -9978, io:00000194614F1E40
7636 13:35:37 977 error: accept: Unknown error
7636 13:35:37 977 debug3: w32_select fd:3
7636 13:35:37 977 debug3: w32_select fd:4
7636 13:35:37 977 debug3: Total in fds:2
7636 13:35:37 977 debug2: on_select - io:00000194614F1E40 type:1 rd:1
7636 13:35:37 977 debug3: acceptEx - io:00000194614F1E40
7636 13:35:37 977 debug1: acceptEx - AcceptEx() ERROR:22, io:00000194614F1E40
7636 13:35:37 977 debug2: on_select - io:00000194614F1EF0 type:1 rd:1
7636 13:35:37 977 debug3: wait() on 0 events and 0 children
7636 13:35:37 977 debug3: select - returning 1
7636 13:35:37 977 debug3: w32_accept fd:3
7636 13:35:37 977 debug3: accept - io:00000194614F1E40
7636 13:35:37 977 debug1: accept - ERROR: async io completed with error: -9978, io:00000194614F1E40
7636 13:35:37 977 error: accept: Unknown error

Before starting the service I emptied the log, this is from the start to the first repetitive accept: Unknown error.

@manojampalam
Copy link
Contributor

Can you dump output of ipconfig /all ?

@lzhoucs
Copy link

lzhoucs commented Jan 30, 2017

I had the same issue with v 0.0.7.0, and this workaround: #244 (comment) works for me.

@manojampalam
Copy link
Contributor

dup #606

itnic added a commit to itnic/Win32-OpenSSH that referenced this issue Dec 2, 2017
Issue 787

There is a bug in the Microsoft POSIX compatibility layer used to
translate POSIX socket API to Windows socket API. The bug concerns the
emulated function accept() (socketio_accept() in the file socketio.c),
which may return an invalid socket and may lock the program in an
infinite loop.

A race is happening between the Windows kernel signaling a socket
issue to the POSIX compatibility layer. If a connection to the ssh
service is dropped before being fully handled by the POSIX
compatibility layer, that layer may reach a state where the Windows
kernel is aware of the dropped connection and update all the socket
states of the Windows socket API. However, the POSIX compatibility
layer is in the middle of the accept() function task and fails without
updating the local state of the emulated POSIX socket.

When the emulated accept() exits, the current socket state is not
updated and the emulated select() call would carry on detecting
activity (previously already detected) on the socket, triggering the
same exact error in the accept() call, running then in an infinite
loop.

This may not happen all the time: if the Windows kernel signals the
error before the compatibility POSIX layer has setup its accept()
state and returned successfully, other calls such as send() and recv()
will update the state of the socket and will handle the issue.

However, on a loaded machine where the synchronization between the
Windows socket API and the compatibility POSIX layer may be slower,
the emulated accept() call may finish before being notified by the
Windows kernel of a client disconnection. This may be triggered with
nmap, which makes two TCP connections in a row quickly: one to detect
an opened port, and a second to retrieve the ssh banner.

The fix proposed is to update the emulated accept() function to modify
the internal state of the compatibility POSIX layer as a regular POSIX
kernel would do. I personally had this issue and this patch fixed it.

Please note that we have identified other situations where it could
potentially happen (in particular the socketio_setsockopt() call). But
we haven't investigated this issue more deeply. Other issues such as
PowerShell#414 or PowerShell#606 may be related.
@itnic itnic mentioned this issue Dec 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants