fix: deep-copy signature field in oqs_sig_dupctx() to prevent double-free#766
Open
iiviel wants to merge 1 commit intoopen-quantum-safe:mainfrom
Open
fix: deep-copy signature field in oqs_sig_dupctx() to prevent double-free#766iiviel wants to merge 1 commit intoopen-quantum-safe:mainfrom
iiviel wants to merge 1 commit intoopen-quantum-safe:mainfrom
Conversation
Member
|
Thanks for the PR @iiviel ! For the commits to pass the workflow, all of them need to be signed off (-s option when doing the commit). Would you mind fixing that so that the checks can advance? I apologize for the inconvenience. |
…free (GHSA-2gh6-p878-65cq) oqs_sig_dupctx() performs a shallow struct copy (*dstctx = *srcctx) but never deep-copies the heap-allocated `signature` field (added under the OPENSSL_VERSION_PREREQ(3,4) guard). Both srcctx and dstctx share the same pointer, and oqs_sig_freectx() frees it unconditionally, causing a double-free when both contexts are freed. Fix: 1. NULL out dstctx->signature and dstctx->siglen immediately after the shallow copy, alongside the existing NULLing of sig, md, mdctx. This prevents the error path (goto err → oqs_sig_freectx) from freeing srcctx's allocation. 2. Add an OPENSSL_memdup deep-copy of srcctx->signature before the return, with goto err on allocation failure. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Eva Crystal <0xiviel@gmail.com>
d4eabfd to
e7cca7a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes GHSA-2gh6-p878-65cq. The signature field introduced in OpenSSL >= 3.4 was not deep-copied in oqs_sig_dupctx() after the shallow struct copy, causing a double-free when both contexts are freed. Fix: NULL out dstctx->signature after shallow copy, then deep-copy via OPENSSL_memdup before return. Verified ASAN-clean.