Bug 16174 - DNS SOA Serial uint32-to-uint16 Truncation Bypasses Update Ordering
Summary: DNS SOA Serial uint32-to-uint16 Truncation Bypasses Update Ordering
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: DNS server (internal) (show other bugs)
Version: 4.24.3
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Samba QA Contact
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-07-09 04:22 UTC by Douglas Bagnall
Modified: 2026-10-03 10:38 UTC (History)
1 user (show)

See Also:


Attachments
Patch for DNS SOA serial uint16 truncation (1.41 KB, patch)
2026-09-11 17:42 UTC, TristanInSec
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Douglas Bagnall 2026-07-09 04:22:45 UTC
Tristan reports:

DNS SOA Serial uint32-to-uint16 Truncation Bypasses Update Ordering
===================================================================
CVSS 3.1: 6.5 (AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N)
CWE: CWE-681 (Incorrect Conversion between Numeric Types)
Auth: TSIG/GSS-API authenticated DNS client
Version: Samba 4.24.3 and prior, master (2026-06-25)

File: source4/dns_server/dns_update.c, line 510

Root Cause:

The DNS dynamic update handler declares SOA serial variables as uint16_t
instead of uint32_t (per RFC 1035 and Samba's own IDL definition). This
truncation causes the serial comparison to accept updates that should be
rejected. With date-based serials (e.g., 2024010100, common in AD), the
upper 16 bits are silently discarded.

    // dns_update.c:510
    uint16_t n, o;  // WRONG: SOA serial is uint32 per IDL and RFC 1035

    // IDL definition (correct):
    typedef struct { ... uint32 serial; ... } dns_soa_record;

    // Line 518: comparison uses truncated values
    if (n <= o) {
        // reject update - serial not advancing
    }

Data Flow:

  Zone SOA serial = 65537 (0x10001) -> truncated to 1
  -> attacker sends update with serial 2 -> truncated to 2
  -> comparison: 2 > 1 -> update accepted
  -> real comparison should be: 2 <= 65537 -> reject

Impact:

Authenticated DNS clients can bypass serial ordering to inject or
overwrite DNS records. In AD-integrated DNS, zone serials are commonly
above 65535, making this universally exploitable. Breaks the fundamental
SOA serial ordering guarantee.

Lab verified: code trace confirmed uint16_t declaration vs uint32 IDL.
Comment 1 Douglas Bagnall 2026-07-09 04:47:39 UTC
It is a bug, but I am not sure it is a security bug.

In this case:

>  Zone SOA serial = 65537 (0x10001) -> truncated to 1
>  -> attacker sends update with serial 2 -> truncated to 2
>  -> comparison: 2 > 1 -> update accepted
>  -> real comparison should be: 2 <= 65537 -> reject

couldn't the attacker just use serial 65538?



Also relevant is this comment:

					/*
					 * TODO: Implement RFC 1982 comparison
					 * logic for RFC2136
					 */

RFC 1982 is considerably more complicated than `if (n <= 0)`. To quote from an example using an 8-bit serial number:

>   Comparison is more interesting, 1 > 0, 44 > 0, 100 > 0, 100 > 44,
>   200 > 100, 255 > 200, 0 > 255, 100 > 255, 0 > 200, and 44 > 200.

Our mess is nowhere near the correct mess.
Comment 2 Andrew Bartlett 2026-08-08 08:35:20 UTC
I agree, moving to the embargoed non-security.
Comment 3 Douglas Bagnall 2026-08-08 08:52:16 UTC
(In reply to Andrew Bartlett from comment #2)
FWIW, Tristan also agreed via email to security@ on 2026-07-12. 

>  (Bug 16174, DNS SOA serial): You're right -- an authenticated client can just use a higher serial. Code quality bug, not security.
Comment 4 TristanInSec 2026-09-11 17:42:01 UTC
Created attachment 19202 [details]
Patch for DNS SOA serial uint16 truncation
Comment 5 Andrew Bartlett 2026-09-11 22:12:08 UTC
Thanks for adding a patch.

I've not looked at it, but I've opened up the bug so we can just deal with this in public.

Can you please make a GitLab Merge Request per
https://wiki.samba.org/index.php/Contribute#Submitting_Patches_via_GitLab
and send in the copyright Declaration if you haven't already done so?
Comment 6 Samba QA Contact 2026-10-03 10:38:04 UTC
This bug was referenced in samba master:

9ff8eec2d61d5b5cd5e1f780fe53c318eb65dded