Skip to content

systemd-resolved's local DNS stub incorrectly returs NOTIMP on DO/CD queries #17218

Closed

Description

@letoams

systemd-246.4-2.fc33.x86_64

When sending a query with the DO and CD flags set, the DNS reply is NOTIMP

paul@thinkpad:~/$ dig +dnssec nohats.ca @127.0.0.53 +cd

; <<>> DiG 9.11.22-RedHat-9.11.22-1.fc33 <<>> +dnssec nohats.ca @127.0.0.53 +cd
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOTIMP, id: 6474
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

It is wrong to return NOTIMP. This will just direct the DNS client to try another nameserver from /etc/resolv.conf, or give up if there are no more others. NOTIMP must only be returned for not implemented OPCODEs.

When you don't support a certain flag, you are supposed to ignore it. So when +do +cd is set, you return the answer without do /cd bit in the OPT record. And obviously without the ad bit. If not understanding the flag means something did not get returned, so be it. That is fine. If it means you have nothing to return, you send NODATA or NXDOMAIN. Sending NOTIMP violates the DNS specification.

Activity

  1. poettering commented on Oct 1, 2020

    @poettering
    Member

    Hmm, RFC1035 is not that clear about what NOTIMP means, just says "The name server does not support the requested kind of query". Which is pretty vague, there's no direct reference to the opcode field mentioned a bit further up. Is there a later RFC that clarifies that?

    I mean, we can certainly change what we return if we don#t support something, but I am not sure how much this would do good... DNSSEC clients can barely rely on DNS servers to return useful data on success, but as long as there's an error returned at all it's already excellent compared to much of the DNS servers I tested against.

    Note that the dns stub in resolved actually does return some DNSSEC metadata on DO/non-CD requests: we include the amount of info some well-known clients actually use. Specifically glibc's nss-dns looks for the AD flag, so we set that, but don't bother with more data (since the fewest deployed clients actually do DNSSEC checking client side). Yes, we are not implementing DNSSEC towards the client beyond some basics, it was not supposed to so far.

    (Also note that we take the liberty to set AD for some data from local trusted sources, for example for records we synthesize from /etc/hosts, as that's a source under control of the local admin, which we generally trust the most, i.e. more than than the public internet DNS. I figure to some DNSSEC purists this migh be revolting...)

  2. changed the title [-]systemd-resolved incorrectly returning NOTIMP[/-] [+]systemd-resolved's local DNS stub incorrectly returs NOTIMP on DO/CD queries[/+] on Oct 1, 2020
  3. pemensik commented on Oct 1, 2020

    @pemensik
    Contributor

    Hmm, RFC1035 is not that clear about what NOTIMP means, just says "The name server does not support the requested kind of query". Which is pretty vague, there's no direct reference to the opcode field mentioned a bit further up. Is there a later RFC that clarifies that?

    Requested kind of query means OPCODE in RFC 1035. It does not mean queried type (QTYPE) or rrset in question section. As a forwarder, it should forward and cache even for records it does not know nothing about. It does not have to understand all records requested. For example, I don't think it is correct to block explicit dig -t rrsig queries with FORMERR. FORMERR should be used to wrong formatted query. Uknown OPCODE. Something that did not exist when implemented.

    Note that the dns stub in resolved actually does return some DNSSEC metadata on DO/non-CD requests: we include the amount of info some well-known clients actually use. Specifically glibc's nss-dns looks for the AD flag, so we set that, but don't bother with more data (since the fewest deployed clients actually do DNSSEC checking client side). Yes, we are not implementing DNSSEC towards the client beyond some basics, it was not supposed to so far. If there are options you don't understand, just ignore them as if they were missing. Clients will handle optional extensions missing in reply.

    This approach is forward incompatible. You used only bits you know are used now by clients. If you act as forwarder, you should cache and forward original response. If systemd supports DNSSEC (it does!), it should just remove DNSSEC related bits from reply, if original client did not set DO flag. That is rrsig, nsec, nsec3 would not be delivered to client, but stored in cache. DNS evolves and your version should be able work well even after 5 or 10 years, especially if supported in RHEL.
    For example, bind 9.8 from RHEL 6 can still validate the most of signatures, unless they use unsupported algorithms.

    Dnsmasq for example stores original reply message and only adjusts query id on reply. It workaround inability to strip DNSSEC records to client. Instead, it makes queries with DO bit set bypass the cache and always forwards. That way, it can cache non-dnssec enabled replies and not collide with DO enabled query for cached entry without DO. I think this is incorrect approach. Solid DNS implementations always use DO on outgoing queries, just filter DNSSEC rrsets on reply to dnssec unaware client. If reply from remote party is missing DO flag, it does not support DNSSEC. You cannot support it unless you choose alternative server.

    # cache non-DO
    dig @127.0.0.53 fedoraproject.org
    # retry with DO, must contain also RRSIG
    dig +dnssec @127.0.0.53 fedoraproject.org
    

    (Also note that we take the liberty to set AD for some data from local trusted sources, for example for records we synthesize from /etc/hosts, as that's a source under control of the local admin, which we generally trust the most, i.e. more than than the public internet DNS. I figure to some DNSSEC purists this migh be revolting...)

    You are misusing AD flag for something else. AA flag from RFC 1035 should be set for any authoritative records instead. Because they are just authoritative, but otherwise unverified. Check dig localhost against any DNS server and flags. Means it can be trusted, because you are authoritative for them. AD bit does not make sense without validation. Do you know what clients use that flag and what for?

  4. letoams commented on Oct 5, 2020

    @letoams
    Author

    Hmm, RFC1035 is not that clear about what NOTIMP means, just says "The name server does not support the requested kind of query". Which is pretty vague, there's no direct reference to the opcode field mentioned a bit further up. Is there a later RFC that clarifies that?

    RFC 1035 predates DNSSEC. There have been updates on this, eg RFC 3225 explains when to reply with the DO bit.

    RFC 8906 clarifies when to use FORMERR vs NOTIMP - It suggests you may return FORMERR.

    RFC 9806 Section 8.1.3.1. Testing CD=1 Queries, clarifies the behaviour to ignore if DNSSEC is not supported and copy if it is.

    That is, neither FORMERR or NOTIMP should be returned when receiving the +CD bit.

    Technically, the problem now is what "DNSSEC support" means for systemd-resolved. With its current behaviour of returning cached answers without DNSSEC data in response to +DO queries, it cannot claim DNSSEC support. By doing so, it will will appear to DNSSEC capable clients of being malicious or compromised.

    It would be best if the incoming CD bit is ignored and not copied to the reply, and to return a non-DNSSEC answer without DO and CD bits set. That makes it clear to DNSSEC capable clients that this server cannot be used for DNSSEC queries and in theory it can try another server listed in resolv.conf.

  5. pemensik commented on Oct 5, 2020

    @pemensik
    Contributor

    This request seems to match much older issue #4621, which is still unresolved.

  6. poettering commented on Oct 9, 2020

    @poettering
    Member

    Requested kind of query means OPCODE in RFC 1035. It does not mean queried type (QTYPE) or rrset in question section.

    The text in the RFC is pretty vague, not sure where you get your understanding from. I doubt it's that clear cut. Is there a clarification RFC for what you are claiming?

  7. letoams commented on Oct 9, 2020

    @letoams
    Author

    My comment above shared pointers to clarifications about old DNS RFCs including RFC 1035. Did you not find the clarifications you were looking for in these subsequent documents? We agree that RFC 1035 is "pretty vague" and "not clear cut". But I thought that the RFCs cited above that update RFC 1035 were clear?

    For example: RFC 8906 Section 3.1.2 clarifies:

    3.1.2. Unknown/Unsupported Type Queries

    Some servers fail to respond to unknown or unsupported types. If a
    server receives a query for a type that it doesn't recognise, or
    doesn't implement, it is expected to return the appropriate response
    as if it did recognise the type but does not have any data for that
    type, i.e., either NOERROR or NXDOMAIN. The exceptions to this are
    queries for Meta-RR types, which may return NOTIMP.

    and section 3.1.4:

    3.1.4. Unknown DNS Opcodes

    The use of previously undefined opcodes is to be expected. Since the
    DNS was first defined, two new opcodes have been added, UPDATE and
    NOTIFY.

    NOTIMP is the expected rcode to an unknown or unimplemented opcode.

    I think these clarifications should be interpreted to mean that receiving qname/qtype queries that are known, with DO bit that are either "not supported or not configured", should not return NOTIMP, but should return the query data without DO/AD bit set.

    RFC 9806 further clarifies the use of the CD bit in that it should be ignored in the query if not supported or configured. It does not state that NOTIMP is a valid response (and RFC 8906 states why returning NOTIMP is generally bad and should only be done for unknown OPCODEs)

    If you have questions about the clarifications offered in RFC 8906 and 9806, please let me know.

  8. pemensik commented on Oct 9, 2020

    @pemensik
    Contributor

    Requested kind of query means OPCODE in RFC 1035. It does not mean queried type (QTYPE) or rrset in question section.

    The text in the RFC is pretty vague, not sure where you get your understanding from. I doubt it's that clear cut. Is there a clarification RFC for what you are claiming?

    https://tools.ietf.org/html/rfc1035#section-4.1.1

    OPCODE A four bit field that specifies kind of query in this
    message. This value is set by the originator of a query
    and copied into the response.
    ...
    RCODE Response code - this 4 bit field is set as part of
    responses. The values have the following
    interpretation:

               0               No error condition
    
               1               Format error - The name server was
                               unable to interpret the query.
    
               2               Server failure - The name server was
                               unable to process this query due to a
                               problem with the name server.
    
               3               Name Error - Meaningful only for
                               responses from an authoritative name
                               server, this code signifies that the
                               domain name referenced in the query does
                               not exist.
    
               4               Not Implemented - The name server does
                               not support the requested *kind of query*.
    
               5               Refused - The name server refuses to
                               perform the specified operation for
                               policy reasons.  For example, a name
                               server may not wish to provide the
                               information to the particular requester,
                               or a name server may not wish to perform
                               a particular operation (e.g., zone
    

    If you are ever unsure, how it should behave, multiple implementors and operators of DNS services would help you at DNS-OARC mailing list

  9. loganaden commented on Oct 19, 2020

    @loganaden

    (Also note that we take the liberty to set AD for some data from local trusted sources, for example for records we synthesize from /etc/hosts, as that's a source under control of the local admin, which we generally trust the most, i.e. more than than the public internet DNS. I figure to some DNSSEC purists this migh be revolting...)

    Is there a way to disable this behaviour as an operator ?

  10. 24 remaining items

  11. poettering commented on Feb 17, 2021

    @poettering
    Member

    Fixed by 30ee707 and 775ae35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions