Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore incomplete RRs #136

Merged
merged 3 commits into from
Dec 4, 2023
Merged

Conversation

mattias-p
Copy link
Member

@mattias-p mattias-p commented Mar 16, 2022

Purpose

This PR makes sure that we're not assuming all RRs come with all fields included. Out-of-the-box ldns returns such RRs even though they're incomplete. If we're unlucky we could be accessing such non-existing fields and that could lead to assertion errors or unexpected undef values.

Context

I found this when investigating #110.

Changes

  • Introduces Zonemaster::LDNS::RR::check_rd_count() that validates the rdata field count for a record.
  • Changes Zonemaster::LDNS::Packet::{answer,authority,additional}() to filter out incomplete RRs.
  • The full set of RRs is still available through Zonemaster::LDNS::Packet::{answer,authority,additional}_unfiltered().

And I've included @pnax's fix from #133 for the broken tests.

How to test this PR

Just run make test. New unit test are added to verify that incomplete RRs are filtered out. The old tests verify that complete RRs are not filtered out.

@mattias-p mattias-p changed the title Ignore incomplete rr Ignore incomplete RRs Mar 16, 2022
@mattias-p mattias-p requested review from hannaeko, matsduf, a user and tgreenx March 16, 2022 10:11
@mattias-p mattias-p added this to the v2022.1 milestone Mar 21, 2022
t/rr.t Outdated
# Alg 8 will replace 5. Now (December 2017) both are used.
ok( $rr->algorithm == 5 or $rr->algorithm == 8 );
# Alg 8 has replaced 5. Now (February 2022) only alg 8 is used.
ok( $rr->algorithm == 8 );
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really related to the PR description? I think this should be in a separate PR with a relevant description.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's under the Changes section:

And I've included @pnax's fix for the broken tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Preferably it should be in a separate PR, and "@pnax's fix for the broken tests" is not much of documentation.

t/rr.t Outdated
ok( $rr->keytag == 59747 or $rr->keytag == 59407 );
# .SE KSK should not change very often. 59407 has replaced 59747.
# Now (February 2022) only 59407 is used.
ok( $rr->keytag == 59407 );
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment above. And more changes below.

lib/Zonemaster/LDNS/Packet.pm Outdated Show resolved Hide resolved
@matsduf
Copy link
Contributor

matsduf commented Mar 25, 2022

How is this PR related to #135? They both introduce the new defintion of Zonemaster::LDNS::Packet::answer method.

@ghost
Copy link

ghost commented Apr 19, 2022

How is this PR related to #135? They both introduce the new defintion of Zonemaster::LDNS::Packet::answer method.

They both use the same commit (86d8fef and 86d8fef) so both PR can be built on top of the same root and there won't be any conflict on merge.

ghost
ghost previously approved these changes Apr 19, 2022
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

LGTM.

tgreenx
tgreenx previously approved these changes May 5, 2022
Copy link
Contributor

@tgreenx tgreenx left a comment

Choose a reason for hiding this comment

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

LGTM, a welcome change here as well

@matsduf
Copy link
Contributor

matsduf commented May 6, 2022

Will this PR resolve #110?

matsduf
matsduf previously approved these changes May 6, 2022
@matsduf matsduf modified the milestones: v2022.1, v2022.2 May 11, 2022
@marc-vanderwal marc-vanderwal dismissed stale reviews from matsduf, tgreenx, and ghost via 0ca82ce August 1, 2022 11:25
@marc-vanderwal
Copy link
Contributor

Hi,

I was conducting some additional tests on this pull requests because I was wondering whether it would solve the crashes I witnessed when fuzz testing Zonemaster. One of my runs ended with the following fatal error:

   5.69 CRITICAL  Erreur fatale dans le module Zonemaster::Engine::Test::Nameserver: Can't locate object method "check_rd_count" via package "Zonemaster::LDNS::RR::SIG" at /home/mvw/.perl5/lib/perl5/x86_64-linux-gnu-thread-multi/Zonemaster/LDNS/Packet.pm line 34, <DATA> line 1.

I found the solution to this small issue, and I think it should be added to this pull request in order to avoid a regression when a server returns SIG records.

@mattias-p
Copy link
Member Author

I've rebased this onto current develop. Please re-review and I'll merge it.

SIG resource records were missing methods defined in LDNS.xs because of
a missing use statement in Zonemaster::LDNS::RR.
Copy link
Contributor

@matsduf matsduf left a comment

Choose a reason for hiding this comment

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

If I understand this PR, incomplete RRs will be silently ignored from processing. Since Zonemaster is testing tool I think it would make more sence if the information is signalled to Engine, that can output a message that this has happened, e.g. (ERROR, "MX record with invalid format has been ignored from response of X query for DOMAIN to server SERVER/IP"

If this PR prevents crashes I think it is OK if it is seen as a preliminary work-around, but that should then be documented in the code and an issue being created.

@mattias-p
Copy link
Member Author

mattias-p commented Dec 4, 2023

Correct. Broken RRs are silently dropped when using the API the way Engine does today. This prevents crashes.

While Zonemaster::LDNS does not actively signal that a broken RR has been found, Engine could use the current Zonemaster::LDNS API without too much trouble to find out if any RRs have been dropped and the RRtypes of the dropped RRs. Doing this might put a little extra pressure on the garbage collector so it would be interesting to have a look at the performance impact. If the impact is significant we could provide a more efficient API in Zonemaster::LDNS.

Edit: For context, the dropping mechanism was introduced in #135.

@mattias-p mattias-p merged commit 3b9154f into zonemaster:develop Dec 4, 2023
1 check 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.

4 participants