Commit graph

45002 commits

Author SHA1 Message Date
Ondřej Surý
d4ec8ebee8 fix: usr: Fail DNSKEY validation when supported but invalid DS is found
A regression was introduced when adding the EDE code for unsupported
DNSKEY and DS algorithms.  When the parent has both supported and
unsupported algorithm in the DS record, the validator would treat the
supported DS algorithm as insecure when validating DNSKEY records
instead of BOGUS.  This has not security impact as the rest of the child
zone correctly ends with BOGUS status, but it is incorrect and thus the
regression has been fixed.

Closes #5757

Merge branch '5757-fix-mixed-algorithm-DS-handling' into 'main'

See merge request isc-projects/bind9!11580
2026-02-23 20:57:50 +01:00
Ondřej Surý
46f15f4f9d
Add test for mixed unsupported DS records
Add a system test that has one invalid DS record with supported
algorithm and one unsupported DS record.  Both DNSKEY and A queries must
fail with SERVFAIL.
2026-02-23 19:53:48 +01:00
Ondřej Surý
f983a64152
Fail DNSKEY validation when supported but invalid DS is found
A regression was introduced when adding the EDE code for unsupported
DNSKEY and DS algorithms.  When the parent has both supported and
unsupported algorithm in the DS record, the validator would treat the
supported DS algorithm as insecure when validating DNSKEY records
instead of BOGUS.  This has not security impact as the rest of the child
zone correctly ends with BOGUS status, but it is incorrect and thus the
regression has been fixed.
2026-02-23 11:34:43 +01:00
Matthijs Mekking
2c67f8bbca fix: usr: Clear serve-stale flags when following the CNAME chains
A stale answer could have been served in case of multiple upstream
failures when following the CNAME chains.  This has been fixed.

Closes #5751

Merge branch '5751-clear-staleflags-in-CNAME-chains' into 'main'

See merge request isc-projects/bind9!11558
2026-02-23 07:50:48 +00:00
Ondřej Surý
d46277b398 Clear serve-stale flags when following the CNAME chains
A stale answer or SERVFAIL could have been served in case of multiple
upstream failures when following the CNAME chains. This has been fixed.
2026-02-23 08:07:12 +01:00
Matthijs Mekking
c32de7df95 Test serve-stale with upstream zones and CNAMEs
Three variants of YWH-PGM40640-56: Stale/Wrong DNS Data Served via
CNAME Flag Leak (DNS_DBFIND_STALEOK persistence) are presented in
GitLab issue #5751. All these variants have been converted to system
tests.

Variant 1 forwards source.stale to another server, that provides a
CNAME record, while the resolver is authoritative for target.stale.
The CNAME points to a non-existing name. A stale CNAME record should
result in a stale NXDOMAIN (instead of SERVFAIL).

Variant 2 forwards both source.stale and target.stale to other servers.
This time the CNAME points to an A RRset. If the source.stale server
is not available (and stale-answer-client-timeout is off), the cached
CNAME should be followed and pick up the fresh RRset (instead of the
stale A RRset).

Variant 3 is similar to variant 2, but this time the CNAME points to
a non-existing name again. After flushing the target, BIND should
return a stale NXDOMAIN (instead of SERVFAIL).
2026-02-23 08:07:12 +01:00
Ondřej Surý
6d3252bbe6 new: doc: Provide guidelines for tool-generated content
In the last few years, the capabilities of coding tools have exploded.
As those capabilities have expanded, contributors and maintainers have
more and more questions about how and when to apply those capabilities.

Add new documentation to guide contributors on how to best use BIND 9
development tools, new and old.

In short: Please show your work and make sure your contribution is
easy to review.

This has been adopted from the Linux Kernel guidelines.

Merge branch 'ondrej/clarify-the-use-of-tools' into 'main'

See merge request isc-projects/bind9!11447
2026-02-23 07:23:25 +01:00
Ondřej Surý
3fe2215afb Provide guidelines for tool-generated content
In the last few years, the capabilities of coding tools have exploded.
As those capabilities have expanded, contributors and maintainers have
more and more questions about how and when to apply those capabilities.

Add new documentation to guide contributors on how to best use BIND 9
development tools, new and old.

In short: Please show your work and make sure your contribution is
easy to review.

This has been adopted from the Linux Kernel guidelines.
2026-02-23 07:23:10 +01:00
Ondřej Surý
bc0b26439b chg: doc: Add examples to the dig man page
Add a set of short examples at the end of the dig manual page to help new or infrequent users figure out the most basic ways to use dig.

Merge branch 'examples' into 'main'

See merge request isc-projects/bind9!11577
2026-02-22 17:20:50 +01:00
Julia Evans
8972ed9424 Add examples to the dig man page
The goal here is to help new or infrequent users figure out the most
basic ways to use dig.

Notes on the choice of examples:

* I wrote examples that users can copy and paste exactly as is, without
  having to come up with an appropriate IP address or domain name to use.
  The one exception is the `dig -x` example which uses an IP from the
  example range.
* `dig +noall +answer` here is because learning about `+noall +answer`
  was lifechanging for me when I learned about it, I've heard from
  others that they find it helpful too, and it's pretty hard to infer
  from the man page as is that it might be useful
* I thought about adding `+trace` but left it out because 5 examples was
  already starting to feel like a lot.
2026-02-22 11:03:10 -05:00
Ondřej Surý
92d3c7d011 fix: nil: Cleanup setting netmgr ports from isc_managers_create()
This is now duplicate as the default ports are already set in
isc_netmgr_create().

Merge branch 'ondrej/mr11569-followup-cleanup' into 'main'

See merge request isc-projects/bind9!11576
2026-02-20 17:25:04 +01:00
Ondřej Surý
10270f6b42
Cleanup setting netmgr ports from isc_managers_create()
This is now duplicate as the default ports are already set in
isc_netmgr_create().
2026-02-20 16:37:44 +01:00
Štěpán Balážik
6907c4f349 chg: ci: Rework linting of Python code
With the Python version bumped to 3.10 and the dependency situation cleared with !11415 it is now time to run linters and formatters on more parts of the Python code that was previously skipped or ignored.

Switch configuration of the various Python-adjacent tools to `pyproject.toml` to ensure that the same configuration is used in CI and locally.

See the individual commits for details on settings changed and linters added. 

Tweaks to type checking and enabling more `ruff` lints will come in a subsequent MRs.

Prerequisites:
- bind9-qa!160.
- images!442

Merge branch 'stepan/python-tooling' into 'main'

See merge request isc-projects/bind9!11499
2026-02-20 14:59:10 +00:00
Štěpán Balážik
8b0a8dbd8e Add ruff job to CI
Run the linter on Python code changes in CI.
2026-02-20 15:17:32 +01:00
Štěpán Balážik
ced002c4ab Replace deprecated typing imports
More specific modules (like collections.abc) can now be used.

Generated with: ruff check --extend-select UP035 --fix
2026-02-20 15:17:32 +01:00
Štěpán Balážik
d3186c7038 Clean up imports of dnspython modules
Add a pylint plugin that enforces:
  - There is no bare `import dns` statement.
  - All `dns.<module>` used are explicitly imported.
  - There are no unused `dns.<module>` imports.

Fix all the imports to conform with this check.
2026-02-20 15:17:32 +01:00
Štěpán Balážik
1d5924c82f Replace Optional["T"] with "T | None"
In Python 3.10 strings don't support the | operator, so ruff doesn't
attempt to fix these. Quote the entire type specification to avoid the
typing.Optional import.

Alternatives I considered:
- leaving it as is (only use of Optional in the code base)
- using `from future import __annotations__` (replacing one import with
  another one)
2026-02-20 15:17:32 +01:00
Štěpán Balážik
fe38515ad0 Replace Optional[T] with T | None
Generated with: ruff check --extend-select UP045 --fix && black .
2026-02-20 15:17:32 +01:00
Štěpán Balážik
cdb7428431 Remove the rest of Union usages by hand
These require some manual changes.
2026-02-20 15:17:32 +01:00
Štěpán Balážik
ce9c9a1a9c Replace Union[S, T] with S | T
Generated with: ruff check --extend-select UP007 --fix && black .
2026-02-20 15:17:32 +01:00
Štěpán Balážik
790745da18 Built-in types are now subscriptable
Generated with: ruff check --extend-select UP006 --fix
2026-02-20 15:17:32 +01:00
Štěpán Balážik
08f5e5ebd1 Remove superfluous 'pylint: disable' directives
Some of these have been fixed already, fix the rest.
2026-02-20 15:17:32 +01:00
Štěpán Balážik
b00f16f026 Remove unused imports
Generated with: ruff check --extend-select F401 --fix
2026-02-20 15:17:32 +01:00
Štěpán Balážik
7178c97e5c Set pytestmark explicitly in rollover* and nsec3* tests
Importing pytestmark confuses static analysis tools as they flag it as
unused.
2026-02-20 15:17:32 +01:00
Štěpán Balážik
ef21b77912 Make default_algorithm accessible through a fixture and method
Importing pytest fixture trips up static analysis tools, so move
default_algorithm to conftest.py and use it instead of os.environ
accesses in various system tests.

For use outside test function, use Algorithm.default().
2026-02-20 15:17:32 +01:00
Štěpán Balážik
2b9c5ccd77 Define __all__ in __init__.py files
Fix ruff's F401 unused-import errors in these files.

Also sort them with: ruff check --extend-select RUF022 --fix.
2026-02-20 15:17:32 +01:00
Štěpán Balážik
ffd5b6ac26 Automatically sort imports in Python code
Generated with: ruff check --extend-select I --fix (with the changes to
pyproject.toml applied).
2026-02-20 15:17:32 +01:00
Štěpán Balážik
0fb7403ef4 Lint code in doc directory
Adjust ignore lists of linters to check more code.
2026-02-20 15:17:32 +01:00
Štěpán Balážik
57ecaee95d Fix vulture warnings and tweak ignore lists
Run vulture on the whole repository, fix most errors in previously
unchecked code, adjust ignore lists.
2026-02-20 15:17:32 +01:00
Štěpán Balážik
19076c0d4d Fix 'Too many return statements' pylint error
Refactor `Key.match_properties` into multiple functions.
2026-02-20 15:17:32 +01:00
Štěpán Balážik
50ed74197c Fix pylint's 'invalid-name' errors
Where possible comply with the naming rules. Add exceptions for the
function names used in KASP tests.
2026-02-20 15:17:32 +01:00
Štěpán Balážik
a3d0f43d21 Move utility Python scripts to the bind9-qa repo
I would have touched them anyway in this MR so let's bite the bullet
and move them there.
2026-02-20 15:17:31 +01:00
Štěpán Balážik
482c1cc72f Clone the bind9-qa repo to the project root in CI jobs
Cloning to a stable location allows clearer handling of paths when
calling scripts from CI jobs.

`unit:gcc:tarball` and `system:gcc:tarball` do `cd bind-*` in
`before_script` which lead to the `bind9-qa` directory ending up in
a different place in exactly these two jobs and that made reasoning
about paths in `.system_test_common` and `.unit_test_common` tricky.
2026-02-20 15:17:31 +01:00
Štěpán Balážik
115e64ea9e Reintroduce pylint checks that are not being violated
We might reintroduce them later if they become obnoxious.
2026-02-20 15:17:31 +01:00
Štěpán Balážik
c47b076494 Set dist=loadscope for pytest in pytest.ini
Previously there was some handling of old pytest-xdist versions which is
no longer needed.
2026-02-20 15:17:31 +01:00
Štěpán Balážik
a384283497 Fix the rest of 'Formatting a regular string which could be an f-string'
Some fixes have to be done manually.
2026-02-20 15:17:31 +01:00
Štěpán Balážik
df0be6b4bd Fix some 'Formatting a regular string which could be an f-string' errors
Generated with:
ruff check --select UP031,UP032 --fix --unsafe-fixes && black .
2026-02-20 15:17:31 +01:00
Štěpán Balážik
b7000ba9b0 Add a small config for the ruff tool
It will be used for automated refactors of Python code.
2026-02-20 15:17:31 +01:00
Štěpán Balážik
601fc1f1cf Centralize Python tooling configuration in pyproject.toml
This allows easy running of the tools from the project root both in CI
and locally.
2026-02-20 15:17:31 +01:00
Štěpán Balážik
4253d7298c Fix 'Import should be placed at the top of the module'
In preparation for running pylint on more Python code.
2026-02-20 15:17:31 +01:00
Štěpán Balážik
38a47d9f7c Fix 'Using open without explicitly specifying an encoding'
In preparation for running pylint on more code.
2026-02-20 15:17:31 +01:00
Štěpán Balážik
d0079b5722 Use relative imports and __init__.py in the statschannel test
This is in preparation for automatic import sorting.
2026-02-20 15:17:31 +01:00
Štěpán Balážik
4684c9c091 Issue errors on re.compile only when isctest is imported
This is in preparation of running pylint on more parts of the codebase.
2026-02-20 15:17:31 +01:00
Štěpán Balážik
407df9599c Run custom servers as Python modules
Use `python -m` for running the custom servers.

This allows the use of relative imports in the server modules and in
turn linting the modules.
2026-02-20 15:17:31 +01:00
Ondřej Surý
b3d13387f6 chg: usr: Optimize the TCP source port selection on Linux
Enable a socket option on the outgoing TCP sockets to allow faster selection of the source <address,port> tuple for different destination <address,port> tuples when nearing over 70-80% of the source port utilization.

Merge branch 'improve-selection-of-outgoing-TCP-port' into 'main'

See merge request isc-projects/bind9!11569
2026-02-20 14:07:13 +01:00
Ondřej Surý
295139f8ca
Rename isc_net_getudpportrange() to isc_net_getportrange()
This better reflects the true nature of the function as we are reading
the ephemeral port range which is not related to UDP at all.
2026-02-20 14:06:23 +01:00
Ondřej Surý
04c81b55d2
Implement IP_LOCAL_PORT_RANGE socket option for Linux
For Linux >= 6.8:

Since 2023, Linux has introduced a change to the IP_LOCAL_PORT_RANGE
socket option that eliminates the need for the random window
shifting (implemented as a fallback in the next commit).

By setting IP_LOCAL_PORT_RANGE option, we tell the kernel to use better
approach to the source port selection.

For Linux << 6.8:

This implement selecting port by random shifting range leveraging the
IP_LOCAL_PORT_RANGE socket option.  The network manager is initialized
with the ephemeral port range (on startup and on reconfig) and then for
every outgoing TCP connection, we define a custom port range (1000
ports) and then randomly shift the custom range within the system range.

This helps the kernel to reduce the search space to the custom window
between <random_offset, random_offset + 1000>.

Reference:
https://blog.cloudflare.com/linux-transport-protocol-port-selection-performance/#kernel
2026-02-20 14:06:23 +01:00
Ondřej Surý
2c48fcaeed
Improve the source port selection on Linux
Since 2015, Linux has introduced a new socket option to overcome TCP
limitations: When an application needs to force a source IP on an active
TCP socket it has to use bind(IP, port=x).  As most applications do not
want to deal with already used ports, x is often set to 0, meaning the
kernel is in charge to find an available port.  But kernel does not know
yet if this socket is going to be a listener or be connected. This
IP_BIND_ADDRESS_NO_PORT socket option ask the kernel to ignore the 0
port provided by application in bind(IP, port=0) and only remember the
given IP address. The port will be automatically chosen at connect()
time, in a way that allows sharing a source port as long as the 4-tuples
are unique.

Enable IP_BIND_ADDRESS_NO_PORT on the outgoing TCP sockets to overcome
this TCP limitation.
2026-02-20 14:06:23 +01:00
Ondřej Surý
c3ec414d88
Remove return value from isc_net_getudpportrange()
The function was already marked as never failing, always returning
ISC_R_SUCCESS, so there was a lot of dead code around checking whether
the result would be ISC_R_SUCCESS.  This has been cleaned up.
2026-02-20 14:06:23 +01:00
Ondřej Surý
254d41f733 fix: usr: Fix read UAF in BIND9 dns_client_resolve() via DNAME Response
An attacker controlling a malicious DNS server returns a DNAME record,
and the we stores a pointer to resp->foundname, frees the response
structure, then uses the dangling pointer in dns_name_fullcompare()
possibly causing invalid match.  Only the `delv`is affected.  This has
been fixed.

Closes #5728

Merge branch '5728-heap-uaf-in-bind9-dns_client_resolve-via-dname-response' into 'main'

See merge request isc-projects/bind9!11570
2026-02-20 12:51:41 +01:00