https://bugs.openldap.org/show_bug.cgi?id=10611
Issue ID: 10611 Summary: slappasswd with sha2 can generate wrong hashes Product: OpenLDAP Version: 2.6.14 Hardware: All OS: All Status: UNCONFIRMED Keywords: needs_review Severity: normal Priority: --- Component: contrib Assignee: bugs@openldap.org Reporter: ondra@mistotebe.net Target Milestone: ---
Depending on compiler version and build flags, SHA256 and SSHA256 can generate the wrong hash. e.g. hashing password `test`: - local build (./servers/slapd/slapd -Tp -o module-load=./contrib/slapd-modules/passwd/sha2/pw-sha2.la -h '{SHA256}' -s test): `{SHA256}AFQU1hg1xqCsA68tVBURFs7dJbJ25QC/Ancq/MQQXKM=` - independent (echo -n 'test' | openssl dgst -sha256 -binary | base64): `n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=`
The issue appears to be pointer aliasing violation that the compiler optimises through. Other implementations already carry a fix, so we can apply that.
None of the known packages (Symas, LTB, Debian) that I tested were affected, they emit the correct hash but this appears to have been quietly patched around by setting `OPT=-fno-strict-aliasing` without a report I can see here[0]
[0]. https://salsa.debian.org/openldap-team/openldap/-/blob/master/debian/rules?r...
https://bugs.openldap.org/show_bug.cgi?id=10611
--- Comment #1 from Howard Chu hyc@openldap.org --- This has been known for a while, but nobody reported it upstream to us?
https://bugs.launchpad.net/ubuntu/+source/openldap/+bug/2000817
https://bugs.openldap.org/show_bug.cgi?id=10611
--- Comment #2 from Geert Hendrickx geert@hendrickx.be --- Also in https://github.com/Zimbra/packages/pull/234
https://bugs.openldap.org/show_bug.cgi?id=10611
--- Comment #3 from Howard Chu hyc@openldap.org --- For reference, on Ubuntu 24
viola:~/OD/r26/contrib/slapd-modules/passwd/sha2> clang --version Ubuntu clang version 18.1.3 (1ubuntu1) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin viola:~/OD/r26/contrib/slapd-modules/passwd/sha2> gcc --version gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Using clang works, using gcc doesn't work unless -fno-strict-aliasing is used.
https://bugs.openldap.org/show_bug.cgi?id=10611
Howard Chu hyc@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |IN_PROGRESS Ever confirmed|0 |1
--- Comment #4 from Howard Chu hyc@openldap.org --- I couldn't find any specific part of the code that was tripping things up. So I grabbed an updated copy of sha2.c from the portable-openssh repo and massaged it to minimize the differences with our tree so it could build.
https://git.openldap.org/openldap/openldap/-/merge_requests/934
Works with and without various optimization flags, so it should be good to go.
https://bugs.openldap.org/show_bug.cgi?id=10611
Quanah Gibson-Mount quanah@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords|needs_review | Target Milestone|--- |2.6.16 Assignee|bugs@openldap.org |hyc@openldap.org
https://bugs.openldap.org/show_bug.cgi?id=10611
Quanah Gibson-Mount quanah@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|IN_PROGRESS |RESOLVED Resolution|--- |TEST
--- Comment #5 from Quanah Gibson-Mount quanah@openldap.org --- head:
3eddef6c by Howard Chu at 2026-10-05T23:21:08+00:00
ITS#10611 contrib pw-sha2: fix build dependency
bff5105c by Howard Chu at 2026-10-05T23:21:08+00:00
ITS#10611 contrib pw-sha2: fix pointer aliasing
Use newer endian-specific macros from OpenBSD to avoid casting from char * to larger words. Macros lifted from 10479cc2a4acd6faaf643eb305233b49d70c31c1 in https://github.com/openssh/openssh-portable and further improved.
RE26:
3da1c174 by Howard Chu at 2026-10-09T23:50:37+00:00
ITS#10611 contrib pw-sha2: fix build dependency
b02e12f6 by Howard Chu at 2026-10-09T23:50:41+00:00
ITS#10611 contrib pw-sha2: fix pointer aliasing
Use newer endian-specific macros from OpenBSD to avoid casting from char * to larger words. Macros lifted from 10479cc2a4acd6faaf643eb305233b49d70c31c1 in https://github.com/openssh/openssh-portable and further improved.
RE27:
1595ce0d by Howard Chu at 2026-10-09T23:48:48+00:00
ITS#10611 contrib pw-sha2: fix build dependency
2a85ecae by Howard Chu at 2026-10-09T23:48:53+00:00
ITS#10611 contrib pw-sha2: fix pointer aliasing
Use newer endian-specific macros from OpenBSD to avoid casting from char * to larger words. Macros lifted from 10479cc2a4acd6faaf643eb305233b49d70c31c1 in https://github.com/openssh/openssh-portable and further improved.