Skip to content
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

Ensure free buffer space when reading TLS messages #83480

Merged
merged 3 commits into from
Mar 17, 2023

Conversation

rzikm
Copy link
Member

@rzikm rzikm commented Mar 15, 2023

Fixes #83455.

@ghost
Copy link

ghost commented Mar 15, 2023

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

Issue Details

Fixes #83455.

Author: rzikm
Assignees: -
Labels:

area-System.Net.Security

Milestone: -

@rzikm rzikm requested a review from wfurt March 15, 2023 22:10
// there should be space left to read into
Debug.Assert(_buffer.AvailableLength > 0, "_buffer.AvailableBytes > 0");
// make sure we have space to read into
_buffer.EnsureAvailableSpace(Math.Min(frameSize, _buffer.Capacity) - _buffer.EncryptedLength);
Copy link
Member

Choose a reason for hiding this comment

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

Is there risk of growing too much if framers are keep coming. I know this is not normal case but as far as I understand the old code, we would make space for a frame, maybe more if needed.
We had EnsureAvailableSpace on line 246 so I'm wondering why that was not sufficient.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, there is, I should've waited with the fix till the morning :D

We had EnsureAvailableSpace on line 246 so I'm wondering why that was not sufficient.

Not sure which one you are talking about, the closes one is in 214 and 287 and both are outside of the while loop which is receiving TLS frames

@wfurt
Copy link
Member

wfurt commented Mar 15, 2023

I assume test would be difficult?

@rzikm
Copy link
Member Author

rzikm commented Mar 16, 2023

I assume test would be difficult?

yes, the exact condition for this regression is that there are just enough leftover bytes at the end of the buffer that we don't know the size of the next frame (when debugging it was 3 or 4 bytes). With more bytes, the frame size would be known and the check on 720 would fix that.

I am not even sure we can make a test for this, since we can't control the size of TLS frames in handshake in order to hit the condition above.

The initial size is not enough to cover later TLS frames
@rzikm
Copy link
Member Author

rzikm commented Mar 16, 2023

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

LGTM.

@rzikm rzikm merged commit 673afec into dotnet:main Mar 17, 2023
@rzikm
Copy link
Member Author

rzikm commented Mar 17, 2023

/backport to release/7.0

@github-actions
Copy link
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/4445535094

@karelz karelz added this to the 8.0.0 milestone Mar 22, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 21, 2023
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.

SslStream fails to authenticate in .NET 7.0 but works in .NET 6.0
3 participants