-
Notifications
You must be signed in to change notification settings - Fork 154
session BUGFIX do not close SSH socket twice #559
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
Conversation
michalvasko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add the opt_sock member into the session instead of keeping the socket in the libssh session and getting it using ssh_get_fd()?
|
Thanks for letting us know about this, the change went unnoticed. But, based on the docs the socket now needs to be closed explicitly. So they are not being closed twice but they are not closed at all, which is probably why it did not cause any problems. |
michalvasko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think it now works correctly for libssh >= 0.10.0, I do remember changing this a long time ago, but 0.10.0 is 3 year old. The issue you describe is present for older libssh versions when the socket is really closed twice.
|
For session server (src/session_server.c): ssh_get_fd() returns the session socket FD which may be owned by libssh or by the application (passed through options). However, since all sockets are currently created by us, the fix can be: If you agree, I can update the patch to use this second solution. |
|
Okay, that seems better. Just please leave empty lines before the comments and make sure |
Update nc_accept_ssh_session() documentation to highlight that the socket is closed if is not set to the SSH session. Signed-off-by: Ilyes Ben Hamouda <[email protected]>
Since libssh 0.10, ssh_disconnect() only closes the socket only if it is not passed via options. For session server, the SSH socket is not passed to libssh via options. It is then closed twice in nc_session_free_transport(): once by libssh in ssh_disconnect() and again by us. This leads to undefined behaviour in multi-threaded programs. Currently, we can not distinguish between a socket passed via options and a socket owned by libssh for cleanup. There is no API in libssh that can retrieve the socket FD passed via options. Ensure to pass all sockets via options and handle ssh_disconnect() behavior before libssh 0.10 (libnetconf2 requires libssh >= 0.9.5) to prevent double close. Fixes: 70e9062 ("session BUGFIX close SSH socket") Signed-off-by: Ilyes Ben Hamouda <[email protected]>
d5b1a2b to
ba6df0b
Compare
Currently, SSH socket is closed twice when created by libssh, causing undefined behavior in multithreaded programs (e.g. netopeer2-server).
ssh_disconnect() used to close the SSH socket. However, this behavior changed with libssh 0.10: the socket is no longer closed when passed through options.
Let's only close SSH socket when created by us after disconnecting from the session, if libssh >= 0.10 (libnetconf2 requires libssh >= 0.9.5).