Skip to content

new_connection: ignore a PTR host name that does not resolve back - #598

Merged
millert merged 2 commits into
sudo-project:mainfrom
iefa-m:logsrvd-checkhost-fcrdns
Nov 16, 2026
Merged

millert merged 2 commits into
sudo-project:mainfrom
iefa-m:logsrvd-checkhost-fcrdns

Conversation

@iefa-m

@iefa-m iefa-m commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

With tls_checkpeer on (and tls_checkhost at its default of true), new_connection() reverse-resolves the client's address with getnameinfo(NI_NAMEREQD) and verify_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 leave closure->name unset, so only an IP address SAN can match, the same as when the reverse lookup fails. Doing it in new_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_sendlog with a client certificate whose only SAN is DNS:trusted.example.com is 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 check passes.

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 millert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@iefa-m

iefa-m commented Nov 16, 2026

Copy link
Copy Markdown
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
millert merged commit d58e85d into sudo-project:main Nov 16, 2026
5 checks passed
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