s4:dsdb:acl: Fix NULL dereference of sAMAccountName in validated writes (BUG 16248)
https://bugzilla.samba.org/show_bug.cgi?id=16248
acl_check_spn() and acl_check_dns_host_name() validate a new
servicePrincipalName / dNSHostName against the account's sAMAccountName,
which they fetch with dsdb_msg_get_single_value(). That helper returns
LDB_SUCCESS with a NULL value when
- a modify request deletes
sAMAccountName, or replaces it with no value, or - an add request (with
AttributeAuthorizationOnLDAPAddset indSHeuristics) has nosAMAccountName.
Neither caller checks for NULL, so the LDAP server process crashes. The crash
sites are acl_validate_spn_value() (via acl_check_spn()) and
acl_check_dns_host_name(). The acl module runs before samldb and
objectclass_attrs, which would otherwise reject removing the mandatory
attribute. Elements of a modify are checked in client order, so the
validated-write element can be placed before the unauthorised sAMAccountName
element.
Only Validated Write (not Write Property) is needed. The default SD of the
computer class grants that to PRINCIPAL SELF and CREATOR OWNER, so any computer
account can crash an LDAP worker with one modify of its own object. Both sites
came with the CVE-2022-32743 work in Samba 4.17: the dNSHostName check was
introduced without a NULL check in b95431ab, and the SPN check started
taking sAMAccountName from the request in e1c52ac0.
The fix keeps the stored sAMAccountName apart from the value after the
request, and handles the two NULL cases differently:
- The request removes an existing
sAMAccountName(modify): returnLDB_SUCCESSand let the later checks reject the illegal request. They do: the access check on thesAMAccountNameelement in the acl module (LDB_ERR_INSUFFICIENT_ACCESS_RIGHTSfor callers that may not write it),samldb(LDB_ERR_UNWILLING_TO_PERFORM, as Windows returns), or, for a replace followed by a delete in the same request,objectclass_attrs(LDB_ERR_UNWILLING_TO_PERFORM). - There never was a
sAMAccountName(an add without one): reject withLDB_ERR_CONSTRAINT_VIOLATION, the code these validations already return on failure. Returning success here would not be caught later:samldbgenerates a randomsAMAccountNamefor the add, and the account would be created with adNSHostName/ SPN that was never validated.
An existing object always has a sAMAccountName here: both validated-write
rights apply only to computer and (group) managed service accounts
(appliesTo), which must have one. Requests that carry a sAMAccountName are
unaffected, as are callers with Write Property, who skip validation.
Commits:
s4:dsdb:acl: Fix NULL dereference of sAMAccountName in SPN validations4:dsdb:acl: Fix NULL dereference of sAMAccountName in dNSHostName checks4:dsdb:tests: Add tests for validated writes without sAMAccountName: 17 tests inacl.py:- 9 modify tests that delete or empty
sAMAccountName: explicit SW grant and PRINCIPAL SELF getLDB_ERR_INSUFFICIENT_ACCESS_RIGHTS; CREATOR OWNER (also with thesAMAccountNameelement first, and with replace then delete) getsLDB_ERR_UNWILLING_TO_PERFORM. Each checks the account is unchanged. - 2 add tests without
sAMAccountName:LDB_ERR_CONSTRAINT_VIOLATION, and the account is not created. - 6 positive controls: the same validated writes by the creator, the
computer itself and on add with a matching
sAMAccountNamestill succeed.
- 9 modify tests that delete or empty
The tests come after the fixes rather than as a knownfail: before the fix, on the
prefork schema_dc env, the crashes take down all four LDAP workers, and
unrelated tests that follow (test_modify_u1..u7,
test_modify_spn_matching_dns_host_name_*) then error while the workers back off.
Tested with make test TESTS=samba4.ldap.acl.python (fl2000dc, fl2003dc,
fl2008dc, fl2008r2dc, schema_dc):
| without the fix | this MR | unconditional LDB_SUCCESS |
|
|---|---|---|---|
9 modify tests removing sAMAccountName |
LDAP worker crash | pass | pass |
2 add tests without sAMAccountName |
LDAP worker crash | pass | fail: account created |
| 6 positive controls | pass | pass | pass |
Checklist
- Commits have
BUG:andSigned-off-by: - Tests added
- CI pipeline passes