Package: bdii
Version: 6.0.3-1
Severity: grave
Tags: security
X-Debbugs-Cc: [email protected]

bdii: local root privilege escalation via symlink following in postinst chown
(CWE-59)

Filed in the BTS per the Debian Security Team's advice (Moritz Mühlenhoff) to
handle this in the open; originally reported to [email protected].

Affected:  6.0.3-1 (trixie = sid). Debian-specific — upstream uses "chown -R",
           which with GNU default -P does not dereference the operand. The
           non-recursive pattern was introduced in 2012 ("Don't use recursive
           chown").
Type:      symlink following in a root-run maintainer script (CWE-59) -> local
           privilege escalation from uid openldap to root.
CVSS 3.1:  AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H = 7.3 (High) [proposed]

Detail
------
debian/bdii.postinst runs, as root on every "configure":

    chown openldap:openldap /var/lib/bdii
    chown openldap:openldap /var/lib/bdii/gip
    chown openldap:openldap /var/lib/bdii/gip/ldif
    chown openldap:openldap /var/lib/bdii/gip/provider
    chown openldap:openldap /var/lib/bdii/gip/plugin

The first line makes the parent owned by openldap. A process running as uid
openldap (Debian's slapd, the bdii slapd, or any bdii provider/plugin all run
as openldap) can replace a child with a symlink; the next chown runs without
-h, dereferences it, and hands openldap ownership of an arbitrary root-owned
target. The sysvinit script (debian/patches/bdii-debian.patch) has the same
pattern.

Reproduction
------------
Reproduced on 6.0.3-1, confirmed on both the host and a throwaway VM booting a
stock Debian kernel (6.12.107+deb13-amd64) with fs.protected_symlinks=1 (the
Debian default): a root:600 file became openldap:600 after planting
/var/lib/bdii/gip -> /root/VICTIM as uid openldap and re-running the real
postinst. strace shows fchownat(AT_FDCWD, "/var/lib/bdii/gip", openldap,
openldap, 0) (flag 0 = follow symlink); the same victim inode changed owner
while gip stayed a symlink; a negative control (no symlink) left the victim
untouched. fs.protected_symlinks does not mitigate it: that sysctl only guards
symlink following during path resolution in world-writable sticky directories,
not a root chown on a path below an openldap-owned directory.

A reproducer script is available (poc.sh) and can be attached on request.

Suggested fix
-------------
Use "chown -h" (or skip symlinked paths), or set ownership via
dpkg-statoverride and never chown a path below an openldap-owned directory; or
restore upstream's "chown -R". Apply the same fix to the sysvinit script.

Thanks,
Ing. Maximiliano Sebastián Quiroga

Reply via email to