Skip to content

Fix invalid access of Target in SafeCredentialReference - #36875

Merged
aik-jahoda merged 20 commits into
dotnet:masterfrom
aik-jahoda:jajahoda/SafeCredentialReferencefix
Dec 17, 2020
Merged

aik-jahoda merged 20 commits into
dotnet:masterfrom
aik-jahoda:jajahoda/SafeCredentialReferencefix

Conversation

@aik-jahoda

@aik-jahoda aik-jahoda commented May 22, 2020 •

Copy link
Copy Markdown
Contributor

The SafeCredentialReference derive from CriticalHandleMinusOneIsInvalid however it didn't owerride IsInvalid nor IsClosed and the behaviour of those method are not reflecting the real Target state.

I removed this inheritance so the problemathics methods are no longer valid and it pointed into problematic usage of SafeCredentialReference which is fixed now.

Fixes #34337

@ghost

ghost commented May 22, 2020

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/ncl
Notify danmosemsft if you want to be subscribed.

@aik-jahoda
aik-jahoda requested review from stephentoub and wfurt May 22, 2020 11:55
@wfurt

wfurt commented May 22, 2020

Copy link
Copy Markdown
Member

you may need to rebase or merge from upstream @aik-jahoda

@aik-jahoda
aik-jahoda force-pushed the jajahoda/SafeCredentialReferencefix branch from 9779b99 to a660da1 Compare May 26, 2020 15:36
@aik-jahoda

Copy link
Copy Markdown
Contributor Author

@wfurt, thanks for the notice. All tests are passing now.

Comment thread src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs Outdated
Comment thread src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs Outdated
Comment thread src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs Outdated
Comment thread src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs Outdated
Comment thread src/libraries/Common/src/System/Net/Security/Unix/SafeFreeCredentials.cs Outdated
Comment thread src/libraries/Common/src/System/Net/Security/Unix/SafeFreeCredentials.cs Outdated
Comment thread src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs Outdated
Comment thread src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs Outdated
Comment thread src/libraries/Common/src/System/Net/Security/SSPIHandleCache.cs Outdated
Comment thread src/libraries/Common/src/System/Net/Security/SafeCredentialReference.cs Outdated
Comment thread src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs Outdated
Comment thread src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs Outdated
aik-jahoda and others added 2 commits June 5, 2020 18:08
Co-authored-by: Stephen Toub <stoub@microsoft.com>
@aik-jahoda
aik-jahoda requested a review from stephentoub June 9, 2020 19:55
@aik-jahoda
aik-jahoda requested a review from stephentoub June 16, 2020 13:37
Comment thread src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs Outdated
creds = cached.Target;
cached.Dispose();

if (creds != null && !creds.IsClosed && !creds.IsInvalid && (cached = SafeCredentialReference.CreateReference(creds)) != null)

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.

How would creds be null here? If there's actually a concern that cached.Target might change from non-null to null concurrently, you can move the creds = cached.Target line to above the previous if block, and then use that creds in the above if check... then it definitely won't be null here.

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.

Also, doesn't CreateReference already check for IsClosed and IsInvalid and return null if either is true? Why do we need to duplicate those checks here?

@stephentoub

Copy link
Copy Markdown
Member

@aik-jahoda, are you still working on this?

@aik-jahoda

Copy link
Copy Markdown
Contributor Author

@stephentoub not actively now. However this is on our test failure list and I expect it will be prioritised soon.

@aik-jahoda
aik-jahoda marked this pull request as draft December 3, 2020 16:26
@aik-jahoda

Copy link
Copy Markdown
Contributor Author

I continue on this PR to resolve the handles issue.

@aik-jahoda
aik-jahoda force-pushed the jajahoda/SafeCredentialReferencefix branch from 970d63f to 46631be Compare December 15, 2020 13:53
@aik-jahoda
aik-jahoda marked this pull request as ready for review December 16, 2020 09:11
@aik-jahoda

Copy link
Copy Markdown
Contributor Author

I run the test in loop for several days with any failure. It is ready to merge and we will observe possible failures in our weekly CI report.

@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
aik-jahoda merged commit a987ef6 into dotnet:master Dec 17, 2020
@aik-jahoda
aik-jahoda deleted the jajahoda/SafeCredentialReferencefix branch December 17, 2020 17:13
@ghost ghost locked as resolved and limited conversation to collaborators Jan 16, 2021
@karelz karelz added this to the 6.0.0 milestone Jan 26, 2021
@ViktorHofer

Copy link
Copy Markdown
Member

@aik-jahoda is the result.txt file that was checked into this PR necessary?

@wfurt

wfurt commented Sep 10, 2021

Copy link
Copy Markdown
Member

no, it is not. we miss it in the review IMHO as GitHub would not show binary (utf-16) diff @ViktorHofer

@ViktorHofer

Copy link
Copy Markdown
Member

@aik-jahoda can you please send a PR to remove the file from main?

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.

ClientAndServer_OneOrBothUseDefaultOk failing in CI

6 participants