Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fix a race condition in SslStreamBase::AsyncHandshakeCallback#41

Open
paulvirag wants to merge1 commit intoopenssl-net:master
base:master
Choose a base branch
Loading
frompaulvirag:master

Conversation

paulvirag
Copy link

@paulviragpaulvirag commentedNov 9, 2016
edited
Loading

AsyncHandshakeCallback currently assumes that an SSL_ERROR_WANT_READ result from ProcessHandshake means it's our turn to write data from the write_bio. This isn't always the case - sometimes there's more data for us to read from the network, and if we blindly try to do a write operation we can end up entering InternalBeginWrite with write_bio.BytesPending == 0 (which will cause the original AuthenticateAsClient caller thread to hang inside of EndAuthenticateAsClient/EndRead indefinitely).

Instead this callback should check write_bio.BytesPending > 0 and initiate either a read or a write depending on which makes sense. I've attached a test that will verify this by presenting a server certificate which is larger than 16384 bytes (the size of the network buffer). This will force the server to split the handshake message into multiple writes, and if the client isn't prepared to perform multiple network reads in sequence then it will deadlock.

The following sample code will also provide a quick proof of concept, since slashdot's certificate is enormous (tried on a couple machines, YMMV 😄)

TcpClient tcp = new TcpClient();tcp.Connect("slashdot.org", 443);OpenSSL.SSL.SslStream ssl = new OpenSSL.SSL.SslStream(tcp.GetStream());ssl.AuthenticateAsClient("localhost");Console.WriteLine("Done");Console.ReadLine();

without patch: will hang inside AuthenticateAsClient
with patch: will complete as expected

@flaub
Copy link

LGTM

@GreyAutomaton
Copy link

This fix worked for the same kind of hanging condition with a server I was working with. I haven't encountered any side effects.

@paulvirag
Copy link
Author

I suspect this is what bikashjoshi was seeing with#2 as well. His workaround was to place Thread.Sleep(100) at the start of AsyncHandshakeCallback, which I assume was giving the network a tiny bit of extra time to catch up and reassemble handshake messages that were split into multiple writes by the server's TCP stack.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@paulvirag@flaub@GreyAutomaton

[8]ページ先頭

©2009-2025 Movatter.jp