Skip to content

Fix lock during SslStream renegotiation request - #56470

Merged
aik-jahoda merged 4 commits into
dotnet:mainfrom
aik-jahoda:jajahoda/renegolock
Aug 5, 2021
Merged

aik-jahoda merged 4 commits into
dotnet:mainfrom
aik-jahoda:jajahoda/renegolock

Conversation

@aik-jahoda

Copy link
Copy Markdown
Contributor

When server request renegotiation on client stream with pending data, the server trow exception as expected but lock is not released.

This PR fix this behaviour and extend related test to cover this case.

Close #56345

@aik-jahoda
aik-jahoda requested a review from wfurt July 28, 2021 13:55
@ghost

ghost commented Jul 28, 2021

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/ncl, @vcsjones
See info in area-owners.md if you want to be subscribed.

Issue Details

When server request renegotiation on client stream with pending data, the server trow exception as expected but lock is not released.

This PR fix this behaviour and extend related test to cover this case.

Close #56345

Author: aik-jahoda
Assignees: -
Labels:

area-System.Net.Security

Milestone: -

@aik-jahoda
aik-jahoda requested a review from a team July 28, 2021 13:55

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we allowed to read _decryptedBytesCount when we don't hold the locks?

Rather than moving this earlier, should it instead be moved down into the try?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting it down would be safer. We try to prevent people from using this concurrently with IO so it should not be valid case but since it is easy I think it is ok to do little bit more work e.g. do the increments/decrements.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to the try block

@aik-jahoda
aik-jahoda force-pushed the jajahoda/renegolock branch from 0e899aa to 2f3f500 Compare July 29, 2021 14:53
_nestedWrite = 0;
_isRenego = false;
// We will not release _nestedAuth at this point to prevent another renegotiation attempt.
_nestedAuth = 0;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The renegotiation should be done we don't need postpone clear this lock

}
if (_decryptedBytesCount is not 0)
{
_nestedAuth = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should clear it here. This was purposely left set in the finally so the RenegotiateAsync can be called at most once.

#49346 (comment)

I think especially if we throw the rest would be unpredictable IMHO.

Also if we throw for _nestedRead or _nestedWrite this would still be set. I think that is ok as the intention is not to allow multiple calls but it would be inconsistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I was tempted by wrong change in test.

@wfurt wfurt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aik-jahoda

Copy link
Copy Markdown
Contributor Author

iOSSimulator and tvOSSimulator tests are hanging, however this change is not for those platforms. Merging.

@aik-jahoda
aik-jahoda merged commit 81b6502 into dotnet:main Aug 5, 2021
@aik-jahoda
aik-jahoda deleted the jajahoda/renegolock branch August 5, 2021 08:54
@karelz karelz added this to the 6.0.0 milestone Aug 17, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Regression] NegotiateClientCertificateAsync exceptions do not clear the read or write locks

4 participants