Skip to content

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
iiviel:fix/oqs-sig-dupctx-double-free
Open

fix: deep-copy signature field in oqs_sig_dupctx() to prevent double-free#766
iiviel wants to merge 1 commit intoopen-quantum-safe:mainfrom
iiviel:fix/oqs-sig-dupctx-double-free

Conversation

@iiviel
Copy link
Copy Markdown

@iiviel iiviel commented Apr 10, 2026

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.

@RodriM11
Copy link
Copy Markdown
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>
@iiviel iiviel force-pushed the fix/oqs-sig-dupctx-double-free branch from d4eabfd to e7cca7a Compare April 11, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants