Created attachment 19225 [details] patch from Chase Bevan-Thomas Chase Bevan-Thomas writes: I'm reporting a reliable, remotely triggerable crash in the AD DC DNS management RPC service (MS-DNSP), reachable by an authenticated user with write access to a DNS zone (DnsAdmins, delegated permissions, or an authenticated-user-update zone -- not Domain Admin). A suggested patch is inline at the end, and a standalone AddressSanitizer proof of concept is attached. I'm happy to work to whatever disclosure timeline you prefer. SUMMARY dns_to_dnsp_convert() in source4/rpc_server/dnsserver/dnsdata.c converts a client-supplied DNS_RPC_RECORD (MS-DNSP wire format) into the stored dnsp_DnssrvRpcRecord format. Its switch(dns->wType) handles only a subset of the record types the request NDR union (DNS_RPC_RECORD_DATA) accepts; any accepted-but-unhandled type falls through to a default case that does a raw memcpy between two incompatible union types: default: memcpy(&dnsp->data, &dns->data, sizeof(union dnsRecordData)); DEBUG(0, ("dnsserver: Found Unhandled DNS record type=%d", dns->wType)); For wType == DNS_TYPE_HINFO this reinterprets a DNS_RPC_NAME {uint8 len; char *str} as a dnsp_hinfo {char *cpu; char *os} (dnsp_string is a plain const char* in C). After the memcpy, cpu is built from the {len, padding} bytes and is never a valid pointer. When the record is serialised for storage, ndr_push_dnsp_string(cpu) calls strlen(cpu) on that invalid pointer and crashes the process. The crash is deterministic and independent of heap contents. ROOT CAUSE The two unions are the same size (56 bytes on x86-64, both dominated by their SOA arm), so the memcpy is in bounds -- this is a type confusion, not an out-of-bounds read. DNS_RPC_NAME (dnsserver.idl) { uint8_t len; const char *str; } // len@0, str@8 dnsp_hinfo (dnsp.idl) { const char *cpu; const char *os; } // cpu@0, os@8 (dnsp_string is const char* in C -- see ndr_push_dnsp_string() in librpc/ndr/ndr_dnsp.c, which takes const char* and calls strlen().) Copying the HINFO DNS_RPC_NAME over dnsp_hinfo yields: cpu = bytes 0-7 of DNS_RPC_NAME = {len, padding} -> invalid pointer os = bytes 8-15 of DNS_RPC_NAME = str -> the real string pointer The stored side expects two strings for HINFO (CPU + OS) but the RPC side supplies only one name, so the fields are off by one pointer slot and cpu receives the {len, padding} word. On store, dnsserver_db_do_add_rec() serialises the record (ndr_push_struct_blob with ndr_push_dnsp_DnssrvRpcRecord), reaching ndr_push_dnsp_string(cpu) -> strlen(cpu) -> SIGSEGV. Because cpu is {len, padding}, it is a tiny value, stale-padding garbage, or NULL for an empty name -- never a valid address -- so the crash is reliable. The other accepted-but-unhandled types (MD, MF, MB, MG, MR, DNAME) map to the stored [default] DATA_BLOB arm and fail the subsequent NDR push gracefully, so HINFO is the one that crashes. REACHABILITY DnssrvUpdateRecord (add path) -> dnsserver_update_record() -> dnsserver_db_add_record() dns_to_dnsp_convert() [HINFO -> default memcpy] dnsserver_update_soa() [ldb_modify, ACL-checked] -> dnsserver_db_do_add_rec() ndr_push_struct_blob() [CRASH: strlen on cpu] The service opens LDB as the calling user (dcesrv_samdb_connect_as_user()), so writes are authorization-checked at the LDB layer. Reaching the crash requires passing dnsserver_update_soa(), whose ldb_modify() needs write access to the target zone -- i.e. DnsAdmins, delegated zone permissions, or a zone that permits authenticated-user updates. It does not require Domain Admin. The handler performs no additional privilege check before the conversion/serialisation. IMPACT Reliable crash of the process handling the dnsserver RPC on an AD DC -> denial of service against a default-enabled component. Authenticated; requires DNS-zone write access, not DC admin. No confidentiality/integrity impact -- the strlen faults (a wild read of an invalid pointer) before any data is written or returned. Suggested CVSS 3.1: AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H (~6.5), potentially higher depending on the deployment's RPC process model. PROOF OF CONCEPT The attached poc_dnsserver_hinfo.c reproduces the exact struct layouts and the default-case memcpy, then performs the same strlen() the store path performs. Built with -fsanitize=address it reports a SEGV in strlen <- ndr_push_dnsp_string, with cpu = 0x4141414141414105 (from {len=5, padding}) and os = 0x502000000010 (the real string pointer). The len==0 variant faults on NULL, confirming independence from padding and name length. A live trigger is an authenticated MS-DNSP DnssrvUpdateRecord adding an HINFO record (wType = 0x000D) with any valid name to a writable zone; a short Samba python-bindings script using samba.dcerpc.dnsserver is attached as well (trigger_dnsserver_hinfo.py). SUGGESTED PATCH The default raw union memcpy is unsafe for any type whose RPC and stored arms differ. None of the affected types have a working conversion today (HINFO crashes; the DNS_RPC_NAME-to-DATA_BLOB types already fail the push), so rejecting them loses no working functionality. This also matches the sibling function dns_rr_to_dnsp() in source4/dns_server/dns_update.c, which already ZERO_STRUCTPs the record and returns DNS_ERR(NOT_IMPLEMENTED) for unhandled types. --- a/source4/rpc_server/dnsserver/dnsdata.c +++ b/source4/rpc_server/dnsserver/dnsdata.c @@ -652,8 +652,17 @@ WERROR dns_to_dnsp_convert(TALLOC_CTX *mem_ctx, struct DNS_RPC_RECORD *dns, break; default: - memcpy(&dnsp->data, &dns->data, sizeof(union dnsRecordData)); - DEBUG(0, ("dnsserver: Found Unhandled DNS record type=%d", dns->wType)); + /* + * The request union (DNS_RPC_RECORD_DATA) accepts several + * types (MD, MF, MB, MG, MR, HINFO, DNAME) that have no + * matching conversion above. The stored union (dnsRecordData) + * uses different arms for these, so a raw memcpy here + * reinterprets memory across incompatible union types -- a + * type confusion that yields an invalid pointer and crashes + * on store (ndr_push_dnsp_string() -> strlen()) for HINFO. + * Reject unsupported types rather than corrupt the record. + */ + DBG_ERR("dnsserver: refusing unsupported DNS record type=%u\n", + dns->wType); + return WERR_NOT_SUPPORTED; } *out_dnsp = dnsp; Thanks for your time and for maintaining Samba.
Following 51ace4d00106920cfae560d3d4489c5daefdeb79 and 64e637802fc58f0215160449fbdd7686150d10d2 we don't deal with HINFO over dns, so we probably shouldn't over dcerpc.
The claim is that a user with semi-administrative privileges can crash the RPC server. The RPC server will eventually restart, so I think we should un-embargo this per https://wiki.samba.org/index.php/Samba_Security_Process 4b.) Even for a CVSSv3.1 of more than 5.0 we do not do a security release where the impact is: * Only a Denial of Service (not a use after free) and the automated internal process restart will allow other clients to reconnect eventually. For clarity, the shared LDAP or KDC process in the AD DC will restart, so a simple NULL de-reference crash there would not trigger a release. However a similar issue in the main smbd listener preventing new connections being established may require a release. This will allow us to get this fix out to our users and help keep the confidential process for more serious issues.
[Bulk message on a number of bugs being made public at once] The embargo is being removed from this bug. That is not to say that the issue is not a real bug, but some things are better dealt with in public, where the normal process is both more available to external contributors and much, much more efficient. If you have a patch for this issue, please do contribute it via our normal GitLab process: https://wiki.samba.org/index.php/Contribute#Submitting_Patches_via_GitLab All patches to Samba must follow our copyright policy: https://www.samba.org/samba/devel/copyright-policy.html Thanks to all who report issues to Samba, we value your patience as we, along with the rest of the Open Source and Free Software communities, work though the reported issues.