Skip to content

Prevent race on SSL CTX - #488

Closed
bilias wants to merge 1 commit into
NLnetLabs:masterfrom
bilias:tls_race
Closed

Prevent race on SSL CTX#488
bilias wants to merge 1 commit into
NLnetLabs:masterfrom
bilias:tls_race

Conversation

@bilias

@bilias bilias commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

xfrd_tcp_open() currently loads the client certificate and private key into the global SSL_CTX (set->ssl_ctx) which is shared across all pipelines.

This causes a race condition when multiple zones have different tls-auth definitions with different client certificates. Concurrent calls to xfrd_tcp_open() can overwrite each other's certificate/key in the shared context, causing a pipeline to authenticate with the wrong identity or fail SSL_check_private_key() due to a cert/key mismatch.

Fix this by loading the private key/certificate directly into the per-pipeline SSL object (tp->ssl)

I've kept SSL_CTX_set_default_passwd_cb and SSL_CTX_set_default_passwd_cb_userdata on the global CTX for now since LibreSSL that I use does not have SSL_set_default_passwd_cb and SSL_set_default_passwd_cb_userdata. So we still have a race condition there that should be documented (use same password for all encrypted keys!)

Ideally this should be solved by loading tls-auth early on startup before dropping privileges (see #363) and before chroot while keeping a different SSL_CTX per tls-auth.

@bilias

bilias commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

New PR (#490)

@bilias bilias closed this Jun 6, 2026
bilias added a commit to bilias/nsd that referenced this pull request Jun 6, 2026
cert-bundle and tls-auth certs can be outside of chroot and loaded
before priv drop. Can be owned by root only.

Client SSL CTX moved out of xfrd_tcp_set struct into tls_auth_options
struct. CTXs for tls-auth are created before chroot. tp pipeline uses
that to create the SSL connections.

This also fixes a race on SSL CTX.
Details: NLnetLabs#488
bilias added a commit to bilias/nsd that referenced this pull request Jun 6, 2026
cert-bundle and tls-auth certs can be outside of chroot and loaded
before priv drop. Can be owned by root only.

Client SSL CTX moved out of xfrd_tcp_set struct into tls_auth_options
struct. CTXs for tls-auth are created before chroot. tp pipeline uses
that to create the SSL connections.

This also fixes a race on SSL CTX.
Details: NLnetLabs#488
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.

1 participant