ldnsutils emits wrong sha256 hashes

Bug #1966237 reported by Christian Ehrhardt 
16
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ldns (Ubuntu)
Fix Released
High
Christian Ehrhardt 
Impish
Won't Fix
Medium
Christian Ehrhardt 
Jammy
Fix Released
High
Christian Ehrhardt 

Bug Description

[Impact]

 * When ldns is compiled with gcc11 without a fix for
   strict-aliasing it will silently emit wrong sha256 hashes

 * This affected Jammy where it was build with GCC11 already
   and a fix was uploaded there.

 * If rebuilt as-is today in Impish it would expose that bad
   behavior. But the build of today is still from hirsute with GCC10.
   Therefore we want to avoid this from ever becoming a problem,
   but at the same time have no reason to push an update all
   the way through.
   The intention is to get this into impish-proposed and stay there
   in case any later fix/security-update comes by it will not
   trigger this problem.

[Test Plan]

$ cat > root.key << EOF
. 86400 IN DNSKEY 257 3 8 AwEAAaz/tAm8yTn4Mfeh5eyI96WSVexTBAvkMgJzkKTOiW1vkIbzxeF3+/4RgWOq7HrxRixHlFlExOLAJr5emLvN7SWXgnLh4+B5xQlNVz8Og8kvArMtNROxVQuCaSnIDdD5LKyWbRd2n9WGe2R8PzgCmr3EgVLrjyBxWezF0jLHwVN8efS3rCj/EWgvIWgb9tarpVUDK/b58Da+sqqls3eNbuv7pr+eoZG+SrDK6nWeL3c6H5Apxz7LjVc1uTIdsIXxuOLYA4/ilBmSVIzuDWfdRUfhHdY6+cn8HFRm+2hM8AnXGXws9555KrUB5qihylGa8subX2Nn6UwNR1AkUTV74bU= ;{id = 20326 (ksk), size = 2048b} ;;state=2 [ VALID ]
EOF

$ ldns-key2ds -n -2 root.key
. 86400 IN DS 20326 8 2

wrong result:
0ae721f59a19244008217c3d2a646183acef2f17cf4c30929a3f29d09311c05e
correct result:
e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d

Note: To avoid confusion - once more to be clear - the ldns in impish as of today is ok as it was built with older GCC, to see the bad-behavior you'd need to rebuild it as-is.

[Where problems could occur]

 * If there is another - not yet discovered - issue with GCC11 it would
   pick this one up; But it would do so as well without this fix and
   with it we prevent at least one issue.

 * If there was someone building ldns from package source relying on
   strict-aliasing for anything this will now be disabled - but
   intentionally, so IMHO ok.

[Other Info]

 * As I mentioned above, this is not meant to migrate to -release,
   we want it in -proposed to avoid a latter issue.

---- original bug report ----

Hi,
originally this started by a finding of an FTFBS issue of dns-root-data [1] as reported in the most recent archive rebuild [2]

But comparing those I've found that it is actually ldns that is broken, as it seems most likely by openssl3.0 changes.

Separating this from dns-root-data, you can:

$ cat > root.key << EOF
. 86400 IN DNSKEY 257 3 8 AwEAAaz/tAm8yTn4Mfeh5eyI96WSVexTBAvkMgJzkKTOiW1vkIbzxeF3+/4RgWOq7HrxRixHlFlExOLAJr5emLvN7SWXgnLh4+B5xQlNVz8Og8kvArMtNROxVQuCaSnIDdD5LKyWbRd2n9WGe2R8PzgCmr3EgVLrjyBxWezF0jLHwVN8efS3rCj/EWgvIWgb9tarpVUDK/b58Da+sqqls3eNbuv7pr+eoZG+SrDK6nWeL3c6H5Apxz7LjVc1uTIdsIXxuOLYA4/ilBmSVIzuDWfdRUfhHdY6+cn8HFRm+2hM8AnXGXws9555KrUB5qihylGa8subX2Nn6UwNR1AkUTV74bU= ;{id = 20326 (ksk), size = 2048b} ;;state=2 [ VALID ]
EOF

$ ldns-key2ds -n -2 root.key
. 86400 IN DS 20326 8 2 0ae721f59a19244008217c3d2a646183acef2f17cf4c30929a3f29d09311c05e

The problem here is that this is the wrong hash.
The very same file used to emit:
. 86400 IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d

And on Impish it still does:
 ldnsutils | 1.7.1-2build1 | impish/universe | amd64, arm64, armhf, ppc64el, riscv64, s390x
 ldnsutils | 1.7.1-2ubuntu3 | jammy/universe | amd64, arm64, armhf, ppc64el, riscv64, s390x

The difference between the two builds related to this seem to be the openssl3.0 changes.

I say it is sha256 explicitly as that is what "-2" selects.
If I run with any of the other hashes jammy/impish still agree which tells me that the rest of the process is still good.
       -1 Use SHA1 as the hash function.
       -2 Use SHA256 as the hash function
       -4 Use SHA384 as the hash function

root@j:~# /usr/bin/ldns-key2ds -n -1 root.key
. 86400 IN DS 20326 8 1 ae1ea5b974d4c858b740bd03e3ced7ebfcbd1724
root@j:~# /usr/bin/ldns-key2ds -n -4 root.key
. 86400 IN DS 20326 8 4 538f47ba9bb88908e1dc335d6dfd51ca66b4d824192e6e6e210ae8cc18ece46a0f62b9f0d2f88dfc87d4bb8b8aed21cb

root@i:~# /usr/bin/ldns-key2ds -n -1 root.key
. 86400 IN DS 20326 8 1 ae1ea5b974d4c858b740bd03e3ced7ebfcbd1724
root@i:~# /usr/bin/ldns-key2ds -n -4 root.key
. 86400 IN DS 20326 8 4 538f47ba9bb88908e1dc335d6dfd51ca66b4d824192e6e6e210ae8cc18ece46a0f62b9f0d2f88dfc87d4bb8b8aed21cb

The build compares this to a root-anchors.xml from http://data.iana.org/root-anchors/root-anchors.xml which also refers to "E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D" so I'm pretty sure our new build of ldns is the bad one here.

[1]: https://people.canonical.com/~ginggs/ftbfs-report/test-rebuild-20220317-jammy-jammy.html#ubuntu-server-team
[2]: https://launchpadlibrarian.net/591984954/buildlog_ubuntu-jammy-amd64.dns-root-data_2021011101_BUILDING.txt.gz

Related branches

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Subscribed Simon who added the openssl3 delta, he might have more context from having worked on so many of these changes.

tags: added: server-todo
Changed in ldns (Ubuntu):
importance: Undecided → High
Simon Chopin (schopin)
tags: added: transition-openssl3-jj
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Most likely change:
"2020-08-24 Use EVP_sha256 instead of HMAC_Update (for openssl-3.0.0)"

From
https://github.com/NLnetLabs/ldns/commit/12ab6f7a408cd99e9b43b7db86724c2ee66bc36e

That is the latest ssl3 toleration they have upstream (merged in 1.8.0, no updates in 1.8.1), but it seems something in there is wrong.

I'll try from git 1.8.1 and our version tomorrow and start looking for a fix from there.

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Build instructions:

git clean -xdf
git checkout .
git submodule update --init
libtoolize -ci
autoreconf -fi
./configure --disable-rpath --with-examples --with-drill --enable-ed25519 --disable-ldns-config --build=x86_64-linux-gnu --prefix=/usr --includedir=/usr/include --mandir=/usr/share/man --infodir=/usr/share/info --sysconfdir=/etc --localstatedir=/var --disable-option-checking --disable-silent-rules --libdir=/usr//lib/x86_64-linux-gnu --runstatedir=/run --disable-maintainer-mode --disable-dependency-tracking
make
./examples/ldns-key2ds -n -2 ~/root.key

Various builds later (git = from git as above; pkg = re-build the pkg as-is):

git 1.7.1@i - bad result
git 1.7.1@j - ftbfs openssl
pkg 1.7.1@i - bad result
pkg 1.7.1@j - bad result
git 1.8.1@j - good result

Insight:
- 1.7.1 in Impish (e.g. on rebuild) is affected by the same issue
  - old in-archive builld is from hirsute 19 Nov 2020
- Something in 1.8.1 makes this right in jammy
- openssl3 breakage blocks most free bisecting

git 1.8.1@i - good result
git 1.8.0@j - good result

Insight:
- whatever is in 1.8.x fixes impish as well
- 1.8.0 is already good
- we might be able to bisect on Impish (no openssl3 block there)

Bisect new tag:1.8.0 <-> old tag:release-1.7.1

Identified:
- https://github.com/NLnetLabs/ldns/issues/131
- https://github.com/NLnetLabs/ldns/commit/4d2057f0b5220487882be1b19c302833b84cffe3

git 1.7.1@i + cherry pick - good result
git 1.8.1@j - revert fix - bad result

Insight:
- it is actually a gcc-11 issue of ldns
- fix can be backported and fixes the issue
- fixed in 1.8.0 and later

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

And @SSL3-patches, I beg your pardon - it was GCC11 after all :-)

tags: removed: transition-openssl3-jj
Changed in ldns (Ubuntu Jammy):
status: New → Confirmed
status: Confirmed → In Progress
Changed in ldns (Ubuntu Impish):
status: New → Confirmed
importance: Undecided → Medium
Changed in ldns (Ubuntu Jammy):
assignee: nobody → Christian Ehrhardt  (paelzer)
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Uploaded to Jammy, once in we can re-check dns-root-data and if all is fine we can consider if/how/when to SRU this.

description: updated
Changed in ldns (Ubuntu Impish):
status: Confirmed → In Progress
assignee: nobody → Christian Ehrhardt  (paelzer)
description: updated
tags: added: block-proposed
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

We do only want to hold it back in impish, jammy we want to complete.
Updating the tag.

tags: added: block-proposed-impish
removed: block-proposed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ldns - 1.7.1-2ubuntu4

---------------
ldns (1.7.1-2ubuntu4) jammy; urgency=medium

  * d/p/lp-1966237-Fix-131-Compile-with-fno-strict-aliasing.patch: fix
    wrong results in sha256 (LP: #1966237)

 -- Christian Ehrhardt <email address hidden> Fri, 25 Mar 2022 10:10:41 +0100

Changed in ldns (Ubuntu Jammy):
status: In Progress → Fix Released
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Uploaded the impish variant for SRU consideration

Revision history for this message
Robie Basak (racb) wrote :

Since this is a fragile bug in the sense that the wrong build time option will silently result in a built binary that has wrong behaviour, _and_ the Test Plan is straightforward and (I think?) doesn't need an Internet connection or anything like that, then have you considered a dep8 test to make it less fragile? That would help to ensure that the bug remains fixed, including in the staged SRU case where the manual verification is expected to take place only once long before any other change, and there may be other changes in the meantime that we can't predict right now.

Ideally that'd go into an upstream test suite too.

I finished my SRU review and this is an SRU +1 regardless though, for the upload currently in Impish unapproved. I'm happy to accept immediately if you prefer. But I'll wait for your answer.

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

There actually is an autopkgtest exercising this already, as part of dns-root-data - this is how it was found. The problem is that this test isn't fired when ldns itself is updated :-/

I'd not want to block the SRU on this Robie.
But I'd be ok to file a request upstream to please add it to their build time tests - that will help down the road.

Revision history for this message
Robie Basak (racb) wrote :

Ah OK. Great!

Changed in ldns (Ubuntu Impish):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-impish
Revision history for this message
Robie Basak (racb) wrote : Please test proposed package

Hello Christian, or anyone else affected,

Accepted ldns into impish-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/ldns/1.7.1-2ubuntu0.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-impish to verification-done-impish. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-impish. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Request to add the test to the upstream build time test filed here:
https://github.com/NLnetLabs/ldns/issues/169

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Upgraded and tested from impish proposed

root@i:~# dpkg -l ldnsutils
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-================-============-=================================
ii ldnsutils 1.7.1-2ubuntu0.1 amd64 ldns library for DNS programming
root@i:~# /usr/bin/ldns-key2ds -n -2 root.key
. 86400 IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d

This is all good now, marking it verified (but it will stay there due to block proposed as intended)

tags: added: verification-done verification-done-impish
removed: verification-needed verification-needed-impish
tags: removed: server-todo
Revision history for this message
Steve Langasek (vorlon) wrote :

impish has gone EOL without any further updates to ldns, therefore I am removing this package from -proposed and closing this bug wontfix as part of the EOL process.

Changed in ldns (Ubuntu Impish):
status: Fix Committed → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.