Bug 16214 - [SECURITY] LDAP bitwise matching rules disclose protected attribute values
Summary: [SECURITY] LDAP bitwise matching rules disclose protected attribute values
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: AD: LDB/DSDB/SAMDB (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Samba QA Contact
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-08-07 00:35 UTC by Douglas Bagnall
Modified: 2026-11-06 18:50 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Douglas Bagnall 2026-08-07 00:35:53 UTC
Gregory Smiley reports:

Active Directory exposes two bitwise extended matching rules to LDAP
clients:

    LDAP_MATCHING_RULE_BIT_AND   1.2.840.113556.1.4.803
    LDAP_MATCHING_RULE_BIT_OR    1.2.840.113556.1.4.804

Both are evaluated against the stored attribute value without consulting
the per-attribute read authorization that the rest of the search path
enforces. Because the caller chooses the bitmask, probing one bit at a
time turns the filter into a value oracle: the entry comes back if and
only if that bit is set in a value the caller is not allowed to read.

Root cause
==========

The fix for CVE-2023-0614 moved suppression of unreadable values out of
the parse-tree walk in `acl_read.c` and into the ldb matcher, then
exempted extended matches from it. The exemption is at
`lib/ldb/common/ldb_match.c:623`:

    /*
     * Suppress matches on confidential attributes (handled
     * manually in extended matches as these can do custom things
     * like read other parts of the DB or other attributes).
     */
    if (tree->operation != LDB_OP_EXTENDED) {
            if (ldb_must_suppress_match(msg, tree)) {
                    return LDB_SUCCESS;
            }
    }

The comment states the contract: extended matches handle it manually.
Four registered rules honor it. Samba's own two, in
`lib/ldb-samba/ldb_matching_rules.c`, call
`ldb_msg_element_is_inaccessible()` at lines 386 and 510.
`ldb_comparator_trans` re-searches through the authorized path.
`ldb_comparator_false` is constant.

`ldb_match_bitmask()` does not. It is defined at `ldb_match.c:469` and
registered as the callback for both bitwise rules at lines 753 and 767:

    el = ldb_msg_find_element(msg, attribute_to_match);
    if (el == NULL) {
            *matched = false;
            return LDB_SUCCESS;
    }

    for (i=0;i<el->num_values;i++) {
            ...
            ret = ldb_comparator_bitmask(oid, v, value_to_match, matched);

`ldb_msg_element_is_inaccessible()` is never called on that element. The
value `acl_read.c` already marked inaccessible is compared as though it
were readable. The function does not lack access to the check:
`ldb_match.c` calls it at line 591, inside `ldb_must_suppress_match()`,
the very function the exemption skips.

The two rules that omit the check are the two an AD client can actually
reach.

Why this is a regression, not an old bug
----------------------------------------

Before the CVE-2023-0614 fix, suppression was performed by a parse-tree
walk in `acl_read.c` whose `parse_tree_get_attr()` handled
`LDB_OP_EXTENDED` explicitly, so bitwise filters were covered. The fix
replaced that walk with the backend redact callback plus this exemption.
The protection that existed for these two rules before the fix does not
exist after it.

Proof of concept
================

The full run is in `transcript.txt`, produced by
`repro/reproduce-bitwise-read-bypass.sh` on a container built and torn
down for that run. Reproducing this, below, rebuilds the target.

Target: a stock `samba-tool domain provision`. No setting is weakened
anywhere. The only administrative actions add directory content or add
restrictions.

Attacker: a separate container holding one ordinary domain user's
password. `alice` has `primaryGroupID` 513, empty `memberOf`, no
`adminCount`. She cannot read `Administrator`'s `unicodePwd`, cannot
write the domain object and cannot add herself to Domain Admins.
Anonymous bind yields `operationsError`. No administrative credential,
no DC host access, no key material, no victim DN and no victim value:
every target is discovered over LDAP from that account.

Baseline, recorded before any payload
-------------------------------------

For each protected attribute, every documented way of asking is
correctly refused. The ordinary read returns nothing, and `(attr=*)`,
`(attr>=0)`, `(attr<=max)`, `(attr=*1*)` and `(attr~=1)` all return zero
entries. The CVE-2023-0614 fix is working on this build for the filter
forms it covers.

The bypass
----------

    (msKds-CreateTime:1.2.840.113556.1.4.804:=<1<<i>)   for i in 0..63

One entry is returned if and only if bit `i` is set. OR the answers
together and the value is exact. On the recorded run:

`msKds-CreateTime`
      Protected by: stock schema `fCONFIDENTIAL`
      Recovered: 134302875298794080
      Actual: 134302875298794080

`msKds-UseStartTime`
      Protected by: stock schema `fCONFIDENTIAL`
      Recovered: 134302512298794080
      Actual: 134302512298794080

`msKds-Version`
      Protected by: stock schema `fCONFIDENTIAL`
      Recovered: 1
      Actual: 1

`unixUserPassword`
      Protected by: deny-Read-Property ACE
      Recovered: 902138476510
      Actual: 902138476510

`employeeID`
      Protected by: deny-Read-Property ACE
      Recovered: 4711220034
      Actual: 4711220034

`employeeNumber`
      Protected by: deny-Read-Property ACE
      Recovered: 305419896
      Actual: 305419896

The GKDI Master Root Key object holding the first three is created by
the provision itself, so this requires no administrative action at all.

Three controls run on the same connection, in the same script:

  * `BIT_AND` with the recovered value returns 1 entry, so the value is
    confirmed, not assumed.
  * `BIT_AND` with the recovered value plus an unset bit returns 0
    entries.
  * Plain equality with the correct recovered value still returns 0
    entries.

That last control is the important one. Redaction is live on the very
same query, against the very same attribute, in the same session. Only
the bitwise rule leaks.

Total cost of recovery: 1196 LDAP queries, 0.9 seconds of wall clock.

The defect is server side
-------------------------

The same recovery was repeated with OpenLDAP's `ldapsearch` over LDAPS,
a completely different client stack. Plain read returned 0, `(attr=*)`
returned 0, equality with the true value returned 0, `BIT_AND` with the
true value returned 1, and `BIT_AND` with a wrong value returned 0. The
behavior is a property of the server.

Domain-wide harvesting
----------------------

A single query enumerates objects by an attribute the caller may not
read:

    (userAccountControl:1.2.840.113556.1.4.803:=4194304)

returns the accounts with `DONT_REQUIRE_PREAUTH` set, including accounts
whose attributes are read-denied to the caller. In the recorded run this
identified a service account that the documented equality form and a
`sAMAccountName` lookup both failed to reveal to the same user. The same
technique located `TRUSTED_FOR_DELEGATION` and `PASSWD_NOTREQD`
accounts.

Existence oracle for values recovery cannot reach
-------------------------------------------------

Where the value cannot be parsed, the probe still distinguishes present
from absent, returning `invalidAttributeSyntax` when the attribute is
present and `success` when it is absent. This was demonstrated cleanly
for `unixUserPassword`: a user holding a real non-numeric `{CRYPT}` hash
answered PRESENT and a user with no value answered absent, while both
returned 0 to `(attr=*)`. The same probe reported `unicodePwd` and
`supplementalCredentials` as present.

Limits
======

These boundaries change what a defender should do, so they are part of
the finding.

Severity
========

The vector above is the one the Samba team assigned to CVE-2023-0614,
whose incomplete fix this is. The attacker position, the protection
defeated and the information disclosed are the same; only the filter
form differs. It is offered on that basis, not as an independent
judgment, and if the team reads the disclosure as narrower than
CVE-2023-0614's, the number should move with it.

`S:C` follows that precedent: the values recovered are keys and
identifiers whose use lies outside the directory's own security
authority.

Suggested remediation
=====================

The minimal change, matching what `dsdb_match_for_expunge()` already
does, in `ldb_match_bitmask()` after `ldb_msg_find_element()`:

    if (ldb_msg_element_is_inaccessible(el)) {
            *matched = false;
            return LDB_SUCCESS;
    }

The exemption at `ldb_match.c:623` also makes correct behavior the
responsibility of every current and future extended matching rule, and
one of the four got it wrong. Running the suppression check for
`LDB_OP_EXTENDED` as well, and letting individual rules opt out where
they genuinely need to read other parts of the database, makes the safe
path the default.

A regression test in `confidential_attr.py` covering both bitwise OIDs
would catch a recurrence.

Interim mitigation for operators
================================

There is no configuration that disables the bitwise matching rules, and
no smb.conf setting changes the behavior. `ldap server require strong
auth` is irrelevant here: the attacker authenticates normally.

Until a patch is applied the exposure can be reduced, not removed:

  * Treat any value ever stored in a numeric confidential attribute on
    an affected DC as disclosed to every authenticated principal, and
    rotate it where rotation is possible.
  * Values that are not purely numeric cannot be recovered by this path,
    so a non-numeric encoding limits disclosure to existence only. That
    mitigates the consequence, not the defect.
  * LDAP query auditing shows a characteristic pattern: many searches
    against one base DN differing only in a power-of-two filter value.
    This detects the attack; it does not prevent it.
Comment 1 Andrew Bartlett 2026-10-26 02:23:06 UTC
I get a CVSSv3 of AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:N/A:N (4.3) as only integers can be disclosed, so confidentiality impact is limited.  We don't do the full security process for an issue under a score of 5.  

The referenced CVE-2023-0614 is worse because it allowed prefix matches, which would allow a binary search to fully obtain a secret 'binary string' value.

I'm moving this to our non-embargo non-security tracking bug so that, once the embargo is lifted, it can be addressed in the normal way and fixes obtained by our users. 

If we are able to get a CVE (say in a batch) then I don't object to it being assigned, we don't recommend that AD be used to store confidential information, and this is not an unrestricted confidentially impact, but it is also not just trivial.
Comment 2 Andrew Bartlett 2026-11-01 06:11:05 UTC
[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.
Comment 3 Andrew Bartlett 2026-11-01 06:30:08 UTC
Samba has for a long time strongly discouraged the storage of confidential data in AD's LDAP tree:  

In CVE-2023-0614 we said:

It is not expected that all similar attacks have been prevented, and
it is likely still possible to determine if an object or attribute on
an object is present, but not to obtain the contents.

This issue needs to be fixed, however it is not worthy of the full Samba security process, so we encourage a fix to be submitted via the public process.