Skip to content

Comments

Fix leak in SSL_set_tlsext_status_ocsp_resp#28894

Closed
rgacogne wants to merge 1 commit intoopenssl:masterfrom
rgacogne:fix-28888
Closed

Fix leak in SSL_set_tlsext_status_ocsp_resp#28894
rgacogne wants to merge 1 commit intoopenssl:masterfrom
rgacogne:fix-28888

Conversation

@rgacogne
Copy link
Contributor

The changes introduced in b1b4b15 cause the resp parameter to no longer be assigned to the SSL object.
Since it is not freed either, and the caller used to expect that, the memory is now leaked.
This commit frees resp right away. There is an early error return when sk_OCSP_RESPONSE_new_reserve fails where the memory is not freed.
I'm not sure whether it makes sense to free the memory in that case, as the documentation does not mention anything.

Fixes #28888

CLA: trivial

Checklist

@rgacogne
Copy link
Contributor Author

I see some tests are failing, so clearly this is not as straight-forward as it seemed in my own case. I'll look into it.

@t8m t8m added branch: master Applies to master branch triaged: bug The issue/pr is/fixes a bug severity: regression The issue/pr is a regression from previous released version branch: 3.6 Applies to openssl-3.6 labels Oct 14, 2025
@t8m
Copy link
Member

t8m commented Oct 14, 2025

I see some tests are failing, so clearly this is not as straight-forward as it seemed in my own case. I'll look into it.

The tests are failing because the test case was incorrectly changed in b1b4b15#diff-ac041dcce48346a57d70403803133a58fb4ac5764e173d7cbfd6db2c2df5afdcR1943

This free call should be removed.

ssl/s3_lib.c Outdated
Comment on lines 3718 to 3719

OPENSSL_free(parg);
Copy link
Member

Choose a reason for hiding this comment

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

I think this would be a better (more backwards compatible with pre-3.6 versions) fix.

Suggested change
OPENSSL_free(parg);
sc->ext.ocsp.resp = parg;
sc->ext.ocsp.resp_len = larg;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is fine by me, but is it OK to have both sc->ext.ocsp.resp and sc->ext.ocsp.resp_ex set? The current code seems to try hard to avoid ending up in that situation, although it's not clear to me whether resp is still actually used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I successfully tested the change locally.

@t8m t8m added the cla: trivial One of the commits is marked as 'CLA: trivial' label Oct 14, 2025
The changes introduced in b1b4b15
cause the `resp` parameter to no longer be assigned to the `SSL` object.
Since it is not freed either, and the caller used to expect that,
the memory is now leaked.
This commit assigns the value to the `SSL` object. There is an early error return
when `sk_OCSP_RESPONSE_new_reserve` fails where the memory is not freed.
I'm not sure whether it makes sense to free the memory in that case,
as the documentation does not mention anything.

Fixes openssl#28888

CLA: trivial

Signed-off-by: Remi Gacogne <[email protected]>
@Sashan Sashan added the approval: review pending This pull request needs review by a committer label Oct 14, 2025
Copy link
Contributor

@Sashan Sashan left a comment

Choose a reason for hiding this comment

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

I agree with CLA trivial.

thank you for the fix.

@rgacogne rgacogne requested a review from t8m October 16, 2025 07:25
@InfoHunter
Copy link
Member

Ping @t8m for a confirmation

@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 30 days ago

t8m added a commit to t8m/openssl that referenced this pull request Nov 28, 2025
Fixes openssl#28888

Fixes b1b4b15

Instead of transferring the ownership of the single OCSP response
to the SSL object, the multi-stapling PR modified the semantics
of SSL_set_tlsext_status_ocsp_resp() to copying semantics.

This change reverts the behavior to the previous one.

Partially based on fix by Remi Gacogne:
openssl#28894
@t8m
Copy link
Member

t8m commented Nov 28, 2025

I took over this fix in PR #29251

@t8m t8m closed this Nov 28, 2025
@rgacogne rgacogne deleted the fix-28888 branch November 28, 2025 15:51
openssl-machine pushed a commit that referenced this pull request Dec 1, 2025
Fixes #28888

Fixes b1b4b15

Instead of transferring the ownership of the single OCSP response
to the SSL object, the multi-stapling PR modified the semantics
of SSL_set_tlsext_status_ocsp_resp() to copying semantics.

This change reverts the behavior to the previous one.

Partially based on fix by Remi Gacogne:
#28894

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Saša Nedvědický <[email protected]>
(Merged from #29251)
openssl-machine pushed a commit that referenced this pull request Dec 1, 2025
Fixes #28888

Fixes b1b4b15

Instead of transferring the ownership of the single OCSP response
to the SSL object, the multi-stapling PR modified the semantics
of SSL_set_tlsext_status_ocsp_resp() to copying semantics.

This change reverts the behavior to the previous one.

Partially based on fix by Remi Gacogne:
#28894

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Saša Nedvědický <[email protected]>
(Merged from #29251)

(cherry picked from commit 7e50e03)
cxx194832 pushed a commit to cxx194832/openssl that referenced this pull request Dec 12, 2025
Fixes openssl#28888

Fixes b1b4b15

Instead of transferring the ownership of the single OCSP response
to the SSL object, the multi-stapling PR modified the semantics
of SSL_set_tlsext_status_ocsp_resp() to copying semantics.

This change reverts the behavior to the previous one.

Partially based on fix by Remi Gacogne:
openssl#28894

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Saša Nedvědický <[email protected]>
(Merged from openssl#29251)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: review pending This pull request needs review by a committer branch: master Applies to master branch branch: 3.6 Applies to openssl-3.6 cla: trivial One of the commits is marked as 'CLA: trivial' severity: regression The issue/pr is a regression from previous released version triaged: bug The issue/pr is/fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak in SSL_set_tlsext_status_ocsp_resp

5 participants