Skip to content

Fix native memory leak on OCSP_Response - #96561

Merged
rzikm merged 1 commit into
dotnet:mainfrom
rzikm:ocsp-leak
Jan 6, 2024
Merged

Fix native memory leak on OCSP_Response#96561
rzikm merged 1 commit into
dotnet:mainfrom
rzikm:ocsp-leak

Conversation

@rzikm

@rzikm rzikm commented Jan 5, 2024

Copy link
Copy Markdown
Member

Fixes #96616.

This PR makes sure we parse OCSP_Response only once per certificate. This fixes a leak when CryptoNative_SslGetPeerCertificate is called multiple times to retrieve the same certificate, as previously the already parsed OCSP_RESPONSE in X509 instance would be simply overwritten without freeing it.

We did not hit this before because the implementation generally retrieves the peer's certificate only once, but during renegotiation, we may ask for it multiple times.

@ghost ghost added the area-System.Security label Jan 5, 2024
@rzikm
rzikm requested a review from bartonjs January 5, 2024 16:18
@ghost ghost assigned rzikm Jan 5, 2024
@ghost

ghost commented Jan 5, 2024

Copy link
Copy Markdown

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

Issue Details

This PR makes sure we parse OCSP_Response only once per certificate. This fixes a leak when CryptoNative_SslGetPeerCertificate is called multiple times to retrieve the same certificate, as previously the already parsed OCSP_RESPONSE in X509 instance would be simply overwritten without freeing it.

We did not hit this before because the implementation generally retrieves the peer's certificate only once, but during renegotiation, we may ask for it multiple times.

Author: rzikm
Assignees: -
Labels:

area-System.Security

Milestone: -

@ghost

ghost commented Jan 5, 2024

Copy link
Copy Markdown

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

Issue Details

This PR makes sure we parse OCSP_Response only once per certificate. This fixes a leak when CryptoNative_SslGetPeerCertificate is called multiple times to retrieve the same certificate, as previously the already parsed OCSP_RESPONSE in X509 instance would be simply overwritten without freeing it.

We did not hit this before because the implementation generally retrieves the peer's certificate only once, but during renegotiation, we may ask for it multiple times.

Author: rzikm
Assignees: rzikm
Labels:

area-System.Net.Security, area-System.Security

Milestone: -

@rzikm
rzikm requested a review from wfurt January 5, 2024 16:24
Comment thread src/native/libs/System.Security.Cryptography.Native/pal_ssl.c

@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

@rzikm

rzikm commented Jan 6, 2024

Copy link
Copy Markdown
Member Author

All CI failures are Known Build Errors.

@rzikm
rzikm merged commit 3e8f588 into dotnet:main Jan 6, 2024
@rzikm

rzikm commented Jan 6, 2024

Copy link
Copy Markdown
Member Author

/backport to release/8.0-staging

@rzikm

rzikm commented Jan 6, 2024

Copy link
Copy Markdown
Member Author

/backport to release/7.0-staging

@github-actions

github-actions Bot commented Jan 6, 2024

Copy link
Copy Markdown
Contributor

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/7431377625

@github-actions

github-actions Bot commented Jan 6, 2024

Copy link
Copy Markdown
Contributor

Started backporting to release/7.0-staging: https://github.com/dotnet/runtime/actions/runs/7431377941

@Leonardo-Ferreira

Copy link
Copy Markdown

Any ideas of when will this be available at the docker images?

@wfurt

wfurt commented Jan 9, 2024

Copy link
Copy Markdown
Member

February if we get it approved in next few days. Likely month later otherwise as part of regular servicing cadence.

@github-actions github-actions Bot locked and limited conversation to collaborators Feb 9, 2024
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.

Native memory leak on TLS client reading OCSP staple.

6 participants