Skip to content

dnsext-iterative: DS の問い合わせを親へ送る - #293

Merged
khibino merged 4 commits into
mainfrom
fix-parent-ds
Nov 20, 2026
Merged

khibino merged 4 commits into
mainfrom
fix-parent-ds

Conversation

@kazu-yamamoto

@kazu-yamamoto kazu-yamamoto commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

#292 を直します。問題と再現条件は #292 に書いてあります。

どこがどう間違っていたか

dnsext-iterative/DNS/Iterative/Query/ResolveJust.hs の resolveExactDC。

(mmsg, nss) <- iterative dc anchor $ DNS.superDomains' (delegationZone anchor) n
...
delegationFallbacks dc withDO (logLn Log.DEMO . unwords . ainfo) nss n typ

iterative が降りていく先は n に対する最深の委任、つまり n への委任です。そのサーバ群は子ゾーンのものなので、DS を尋ねる相手として唯一間違っています。DS 以外のすべての型ではこれで正しい動きです。

どう直したか

DS のときだけ、歩く名前の列から末尾を落とします。

    stopAbove ds
        | typ == DS = dropLast ds
        | otherwise = ds
    dropLast [] = []
    dropLast ds = init ds

superDomains' は浅い順で n で終わる列を返すので、末尾を落とせば 1 つ上の委任まで歩きます。example.com. DS なら com. のサーバへ、sub.example.com. DS なら example.com. のサーバへ。iterative に [] を渡すとアンカーが返るので、アンカーゾーン直下の名前も正しく扱えます。

どの層・どのパッケージ

dnsext-iterative の ResolveJust。resolveExactDC には他に 3 つの呼び出し元がありますが、どれも DS を渡しません(Resolve.hs:240 は CNAME、ResolveJust.hs:672 は NS アドレスの解決、Resolve.hs:252 は問い合わせ側の型で、これが修正対象の経路)。

どう確かめたか

シナリオを先に落としてから直しています(888ca312 → 8b3cc960)。dnsext-scenario/test/parent-ds/ は、ルートが example. を DS 付きで委任し、example. が保証しない子を 2 つ委任します。up.example. は答えるサーバを持ち、lame.example. は居ないサーバを指します。修正前は 4 例中 3 例が赤です。

is the one the parent vouched with [x]            predicate failed on: []
does not leave the zone below it unvalidated [x]  expected: True, but got: False
is nothing, provably, where the parent vouched for nobody [v]
is nothing where the delegation leads nowhere [x] expected: NoError, but got: ServFail

cabal build all --enable-tests、dnsext-scenario 74 例、dnsext-iterative 51 例(実インターネット)、fourmolu すべて緑。#294・#295・#302 と重ねた状態でも dnsext-scenario 77 例・dnsext-dnssec 61 例・dnsext-iterative 51 例が緑でした(衝突は dnsext-dnssec.cabal の other-modules 1 行だけ)。

🤖 Generated with Claude Code

@kazu-yamamoto kazu-yamamoto changed the title dnsext-iterative: a DS is asked of the parent, not of the zone itself dnsext-iterative: DS は子ではなく親に聞く Oct 9, 2026
@kazu-yamamoto kazu-yamamoto changed the title dnsext-iterative: DS は子ではなく親に聞く dnsext-dnssec: DS の問い合わせを親へ送る Oct 9, 2026
@kazu-yamamoto kazu-yamamoto changed the title dnsext-dnssec: DS の問い合わせを親へ送る dnsext-iterative: DS の問い合わせを親へ送る Oct 9, 2026
kazu-yamamoto and others added 4 commits November 20, 2026 17:32
A DS belongs to the parent: RFC 4034 Sec 5 has it appear only on the
parental side of a delegation and RFC 4035 Sec 2.4 has it not appear at
the zone's apex, so the zone itself is the one server certain not to
have it.

The scenario's root delegates example. and vouches for it with a DS, and
example. delegates two children and vouches for neither -- one which
answers and one whose server is not there.  Three of the four examples
fail:

  - example. DS gives an empty answer, though the root has a DS for it
    and bowline verified that DS on the way down;
  - having been asked, bowline then serves the rest of example.
    unvalidated, the empty answer having been cached as "no DS";
  - lame.example. DS is SERVFAIL, because the child's servers are asked
    a question only its parent can answer.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
外部テストの代わりに doctest で確認を行なう。次のコミットで resolveExact の doctest に置き換える。
応答の AD ビット、キャッシュ後の検証、応答しない委任先の経路は、その doctest では見ない。

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
example. をスタブゾーンに置き、queryNorec を差し替えて a.example. への委任を返させる。
resolveExact が返す委任のゾーンで、DS だけが親の example. に送られることを見る。
この時点では "a.example." で赤になり、次の修正コミットで緑になる。

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
resolveExactDC walks down to the deepest delegation for the name asked
about and sends the question there.  For a DS that is the delegation to
the name itself, so the question goes to the zone -- the one server
which RFC 4034 Sec 5 and RFC 4035 Sec 2.4 between them guarantee has no
DS at that name, a DS living on the parental side and not at an apex.

So a DS query was answered NODATA by the zone whose DS was being asked
for, however good the DS in its parent was.  bowline fetched and
verified that DS on the way down, threw it away, asked the child, and
handed back the child's empty answer with AD set.  That answer is then
cached as "no DS", and the whole subtree is served unvalidated from then
on: one ordinary question turns a secure zone insecure for every client
of the cache.

Where the delegation is insecure the parent proves there is no DS and
bowline verifies the proof -- and then asked the child anyway, so a
delegation whose servers had stopped answering failed the query
outright, with CD set as well as without.  Lame servers under an
insecure delegation are not rare.

For a DS the walk now stops at the delegation above the name.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Kei Hibino <ex8k.hibino@gmail.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@khibino

khibino commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

外部テストをやめて、doctest 化しています。
本文には書かれていませんが、F6 と F9 の攻撃経路を塞ぐのに相当する修正です。

CI が通ったらマージするつもりです。

@khibino
khibino merged commit 70dbffc into main Nov 20, 2026
17 of 18 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