Repository navigation
new_connection: ignore a PTR host name that does not resolve back - #598
Merged
Merged
Conversation
With tls_checkhost enabled, the client's certificate is matched against the host name returned by a reverse lookup of the client's address. The PTR record is controlled by whoever controls the reverse zone for that address, not by the owner of the name in the certificate, so a client holding a certificate issued for another host could connect from any address whose PTR record names that host. Only use the name if it resolves back to the client's address. Otherwise only an IP address in the certificate can match, the same as when the reverse lookup fails.
millert
reviewed
Nov 15, 2026
millert
left a comment
Collaborator
There was a problem hiding this comment.
Is setting ai_socktype to SOCK_STREAM actually meaningful without a service name being specified? I thought that was only used when specifying a service along with the host name, which is not the case here.
Without a service name the socket type doesn't affect which addresses are returned, it only stops getaddrinfo() from listing each address once per socket type.
Contributor
Author
|
You're right, it doesn't change which addresses come back. Without it glibc just returns each address once per socket type (stream, datagram and raw), so all it did was trim duplicates from the loop. I've dropped it, which also matches resolve_host() in sudoers_cb.c. |
millert
approved these changes
Nov 16, 2026
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.
With
tls_checkpeeron (andtls_checkhostat its default of true),new_connection()reverse-resolves the client's address withgetnameinfo(NI_NAMEREQD)andverify_peer()matches that name against the DNS names in the client certificate. The PTR record belongs to whoever controls the reverse zone for the connecting address, and nothing checks that the name resolves back to it, so a client holding any certificate from the CA for host A can present it from an unrelated address whose PTR record says A. Before bfc344d (1.9.18),validate_hostname()forward-resolved the certificate's names and compared them with the peer address, which a PTR record can't influence.Only keep the reverse-resolved name if
getaddrinfo()on it returns the peer's address. Otherwise log a warning and leaveclosure->nameunset, so only an IP address SAN can match, the same as when the reverse lookup fails. Doing it innew_connection()keeps DNS lookups out of the verify callback. Reproduced on Linux with dnsmasq answering PTR 127.0.0.1 -> trusted.example.com and A trusted.example.com -> 192.0.2.10:sudo_sendlogwith a client certificate whose only SAN isDNS:trusted.example.comis accepted and its event logged before the change, and the handshake fails after it. With the A record pointing at 127.0.0.1 the connection is still accepted.make checkpasses.