Saturday, May 27, 2023

[fix/patch] net/knot - add patch for infinite journal looping on broken zone

Hi,
I've added a patch for knot which fixes infinite loop in journal loading when one of the zones is broken.

This error is witnessed when an update to knot zone changes the SOA record to a serial which is older than the current one and then knot is restarted. This results in knot going into an infinite loop.

Patch was provided by knot developer Daniel Salzman < daniel DOT salzman AT nic DOT cz >.

I'd also like to get the patch backported to 7.3 stable as this error has broken my setup multiple times. Will send patch for stable in separate email.

OK for -current?

Aisha

diff --git a/net/knot/Makefile b/net/knot/Makefile
index e035a08c8a8..0402ef39a53 100644
--- a/net/knot/Makefile
+++ b/net/knot/Makefile
@@ -2,6 +2,7 @@ COMMENT = authoritative DNS server

# update net/py-libknot when updating this
DISTNAME = knot-3.2.6
+REVISION = 0

SHARED_LIBS += dnssec 3.1 # .9.0
SHARED_LIBS += knot 8.0 # .13.0
diff --git a/net/knot/patches/patch-src_knot_journal_journal_read_c b/net/knot/patches/patch-src_knot_journal_journal_read_c
new file mode 100644
index 00000000000..fa1f450525a
--- /dev/null
+++ b/net/knot/patches/patch-src_knot_journal_journal_read_c
@@ -0,0 +1,36 @@
+Stop journal from looping infinitely when reading a broken zone
+
+Index: src/knot/journal/journal_read.c
+--- src/knot/journal/journal_read.c.orig
++++ src/knot/journal/journal_read.c
+@@ -32,6 +32,8 @@ struct journal_read {
+ const knot_dname_t *zone;
+ wire_ctx_t wire;
+ uint32_t next;
++ uint32_t changesets_read;
++ uint32_t changesets_total;
+ };
+
+ int journal_read_get_error(const journal_read_t *ctx, int another_error)
+@@ -56,6 +58,10 @@ static bool go_next_changeset(journal_read_t *ctx, boo
+ ctx->txn.ret = KNOT_ELOOP;
+ return false;
+ }
++ if (++ctx->changesets_read > ctx->changesets_total) {
++ ctx->txn.ret = KNOT_ELOOP;
++ return false;
++ }
+ ctx->next = journal_next_serial(&ctx->txn.cur_val);
+ update_ctx_wire(ctx);
+ return true;
+@@ -77,6 +83,10 @@ int journal_read_begin(zone_journal_t j, bool read_zon
+ newctx->next = serial_from;
+
+ knot_lmdb_begin(j.db, &newctx->txn, false);
++
++ journal_metadata_t md = { 0 };
++ journal_load_metadata(&newctx->txn, newctx->zone, &md);
++ newctx->changesets_total = md.changeset_count + (read_zone ? 1 : 0);
+
+ if (go_next_changeset(newctx, read_zone, j.zone)) {
+ *ctx = newctx;

No comments:

Post a Comment