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

Fix crash in GSSAPI on macOS #71484

Merged
merged 2 commits into from
Jul 1, 2022
Merged

Conversation

filipnavara
Copy link
Member

On macOS the gss_accept_sec_context/gss_init_sec_context APIs release the context handle when error occurs. The code didn't handle it properly and it would result in double-free and hard crash. Update the code to handle this situation properly.

Fixes #71463

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jun 30, 2022
@filipnavara filipnavara requested a review from wfurt June 30, 2022 11:54
@ghost
Copy link

ghost commented Jun 30, 2022

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

Issue Details

On macOS the gss_accept_sec_context/gss_init_sec_context APIs release the context handle when error occurs. The code didn't handle it properly and it would result in double-free and hard crash. Update the code to handle this situation properly.

Fixes #71463

Author: filipnavara
Assignees: -
Labels:

area-System.Net.Security

Milestone: -

… the context handle

when error occurs. The code didn't handle it properly and it would result in double-free
and hard crash. Update the code to handle this situation properly.
@filipnavara filipnavara force-pushed the gss-context-null-macos branch from 721a4a3 to 00b2786 Compare June 30, 2022 11:55
@@ -85,146 +85,6 @@ internal static string QueryContextAuthenticationPackage(SafeDeleteContext secur
}
}

private static bool GssInitSecurityContext(
Copy link
Member Author

@filipnavara filipnavara Jun 30, 2022

Choose a reason for hiding this comment

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

The GssInitSecurityContext and GssAcceptSecurityContext methods are folded into the caller. This made updating the handles substantially easier. I also removed the code that threw GssApiException only to catch it one method above in the stack and convert it to reported status code.

@@ -45,6 +45,7 @@ public SafeDeleteNegoContext(SafeFreeNegoCredentials credential)
: base(credential)
{
Debug.Assert((null != credential), "Null credential in SafeDeleteNegoContext");
_context = new SafeGssContextHandle();
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of trying to handle null values here it's easier to just always have a non-null handle.

Copy link
Member

Choose a reason for hiding this comment

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

I assume we need to always allocate it anyway? #69527 is trying to avoid unnecessary allocations.

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, it would always get allocated right after SafeDeleteNegoContext is created.

@@ -63,7 +65,6 @@ public SafeDeleteNegoContext(SafeFreeNegoCredentials credential, string targetNa

public void SetGssContext(SafeGssContextHandle context)
{
Debug.Assert(context != null && !context.IsInvalid, "Invalid context passed to SafeDeleteNegoContext");
Copy link
Member Author

Choose a reason for hiding this comment

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

We now explicitly allow invalid handles to reset the previous values so the Assert became useless. context == null is already checked by the nullability in the compiler.

@wfurt
Copy link
Member

wfurt commented Jun 30, 2022

I assume this is independent of #71373, right?

@filipnavara
Copy link
Member Author

I assume this is independent of #71373, right?

Yep. Although it may create some merge conflict.

@filipnavara filipnavara marked this pull request as ready for review June 30, 2022 12:32
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

@wfurt wfurt merged commit d9718f5 into dotnet:main Jul 1, 2022
@filipnavara filipnavara deleted the gss-context-null-macos branch July 1, 2022 16:16
@filipnavara filipnavara mentioned this pull request Jul 12, 2022
7 tasks
@karelz karelz added this to the 7.0.0 milestone Jul 19, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Security community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation violation when doing server-side Kerberos authentication on macOS
3 participants