Repository navigation
pqc: initialize the PQC subsystem eagerly in the postmaster - #1
Merged
Merged
Conversation
pqc_preflight_check(), called from the postmaster at startup, logs
"PQC subsystem initialized (liboqs available: %s)" using pqc_is_available(),
which reflects the static pqc_initialized flag. That flag is only set by
pqc_init() (which calls OQS_init()), and pqc_init() was invoked lazily —
only from the KEM/SIG paths in pqc_kem.c / pqc_sig.c on first use.
As a result the preflight check ran before any lazy init and logged
"liboqs available: no" on a build where liboqs was linked and fully
functional (e.g. pqc_sig_keygen('ML-DSA-65') returns a valid keypair).
The flag is also process-local, so with no init in the postmaster every
backend re-initialized liboqs independently on first PQC use rather than
inheriting an initialized state across fork().
Initialize the subsystem once, eagerly, in the preflight check so the
logged status is accurate and forked backends inherit the initialized
state. pqc_init() is idempotent, so this is safe.
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.
Problem
On a build with liboqs linked and fully functional, the postmaster still logs at startup:
This is a false negative. liboqs is present and works — for example
SELECT pqc_sig_keygen('ML-DSA-65')returns a valid keypair, andldd .../bin/postgresshowsliboqs.so.Root cause
pqc_preflight_check()(called from the postmaster) logs the status viapqc_is_available(), which returns the staticpqc_initializedflag. That flag is set only bypqc_init()(which callsOQS_init()), andpqc_init()was invoked lazily — only from the KEM/SIG paths inpqc_kem.c/pqc_sig.con first use.So at startup the preflight check reads the flag before anything triggers the lazy init, and logs
no. Because the flag is process-local and the postmaster never initializes it, each backend also re-initializes liboqs independently on first PQC use, rather than inheriting an initialized state acrossfork().Fix
Initialize the subsystem once, eagerly, in
pqc_preflight_check()before logging the status.pqc_init()is idempotent, so this is safe, and forked backends inherit the initialized state.One line of behavior change:
Verification
Built FortressQL (PostgreSQL 17,
-Dpqc=enabled -Dssl=openssl) against liboqs 0.16.0 on OpenSSL 3.5. Before the fix the postmaster loggedliboqs available: no; after it logs:Note: this relies on the standard fork-based backend model (children inherit the initialized state). An
EXEC_BACKENDbuild would still initialize per backend on first use via the existing lazy path, which is unchanged.