Bug 281685 - ASAN intercepting SHA256 and MD5 causes issues with OpenSSL's EVP
Summary: ASAN intercepting SHA256 and MD5 causes issues with OpenSSL's EVP
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-09-24 14:30 UTC by Theo Buehler
Modified: 2024-11-09 16:56 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Theo Buehler 2024-09-24 14:30:02 UTC
libmd has a few Init/Update/Final implementations of the same name as OpenSSL but with incompatible signature. For FreeBSD this is at least SHA2 and MD5. This causes issues when using ASAN, in particular in combination with EVP.

See https://github.com/libressl/portable/issues/1098 and https://github.com/openssl/openssl/issues/25456 for an example.

I suspect defining `SANITIZER_INTERCEPT_*` for these needs to be reconsidered.
Comment 1 Theo Buehler 2024-09-27 07:41:11 UTC
I reported this to LLVM upstream to make the NetBSD developers who added this aware.

https://github.com/llvm/llvm-project/issues/110215
Comment 2 Mark Johnston freebsd_committer freebsd_triage 2024-10-04 17:04:41 UTC
Looks like this has been addressed upstream by simply removing the interceptors: https://github.com/llvm/llvm-project/issues/110215
Comment 3 Rafael Grether 2024-11-06 21:29:25 UTC
I think we can close this, since LLVM will be released w/ this patch for upcoming FreeBSD 14.2?
Comment 4 Mark Johnston freebsd_committer freebsd_triage 2024-11-07 14:07:02 UTC
(In reply to Rafael Grether from comment #3)
As far as I can see, this patch isn't in 14.2 (though it is in stable/14).  It's not in stable/13 either.  It seems low-risk enough that we could include it in 14.2, but it's getting a bit late in the release cycle.  Dimitry, do you have an opinion on what to do here?
Comment 5 commit-hook freebsd_committer freebsd_triage 2024-11-07 16:15:17 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4f1754bccef155c0fd24547ab3c872bd0f182224

commit 4f1754bccef155c0fd24547ab3c872bd0f182224
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-11-07 16:12:12 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-11-07 16:13:43 +0000

    Merge commit d0b9c2c56476 from llvm git (by David CARLIER):

      [compiler-rt] Remove SHA2 interceptions for NetBSD/FreeBSD. (#110246)

      To Fix #110215

      Interceptors introduced with 18a7ebda99044473fdbce6376993714ff54e6690

    This fixes undesirable runtime failures when using -fsanitize=-address
    in combination with -lcrypto.

    Direct commit to stable/14, because main already got this change as part
    of the llvm-19 import.

    Reported by:    Theo Buehler <tb@openbsd.org>
    PR:             281685

 .../sanitizer_common_interceptors.inc              | 180 ---------------------
 .../sanitizer_platform_interceptors.h              |   2 -
 2 files changed, 182 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2024-11-07 16:15:19 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=56d38dda6b909031995bac73d166efa1b6cccb26

commit 56d38dda6b909031995bac73d166efa1b6cccb26
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-11-07 16:12:50 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-11-07 16:12:50 +0000

    Merge commit d0b9c2c56476 from llvm git (by David CARLIER):

      [compiler-rt] Remove SHA2 interceptions for NetBSD/FreeBSD. (#110246)

      To Fix #110215

      Interceptors introduced with 18a7ebda99044473fdbce6376993714ff54e6690

    This fixes undesirable runtime failures when using -fsanitize=-address
    in combination with -lcrypto.

    Direct commit to stable/13, because main already got this change as part
    of the llvm-19 import.

    Reported by:    Theo Buehler <tb@openbsd.org>
    PR:             281685

 .../sanitizer_common_interceptors.inc              | 180 ---------------------
 .../sanitizer_platform_interceptors.h              |   2 -
 2 files changed, 182 deletions(-)
Comment 7 Dimitry Andric freebsd_committer freebsd_triage 2024-11-07 16:16:55 UTC
(In reply to Mark Johnston from comment #4)
No, it wasn't in stable/14 yet. I have committed that now, and if you like I can mail re@ again for another eleventh-hour fix. :)
Comment 8 Mark Johnston freebsd_committer freebsd_triage 2024-11-07 20:49:59 UTC
(In reply to Dimitry Andric from comment #7)
Oops, thanks for merging.  I suspect that this is low-risk enough to consider for 14.2.  cc'ing releng.  I'll do some testing using the bug report from libressl.
Comment 9 Theo Buehler 2024-11-07 22:46:53 UTC
(In reply to Mark Johnston from comment #8)
Thanks for fixing this in various branches.

FWIW, I have been running a test box with 14.1-stable with a variant of this patch applied for about a month and have done a few simple tests like building test programs of a few related bug reports with -fsanitize=address. I also built and ran tests for several LibreSSL versions and all things work as expected. This is only light testing, but I encourage you to land this if at all possible. I think it can only improve things.

The bug has very confusing side effects, is quite annoying and it breaks tons of serious usage of ASAN with OpenSSL in play.
Comment 10 commit-hook freebsd_committer freebsd_triage 2024-11-09 16:52:23 UTC
A commit in branch releng/14.2 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=57921ae825dcf690b06b63db2e38613ee32d1b8e

commit 57921ae825dcf690b06b63db2e38613ee32d1b8e
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-11-07 16:12:12 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-11-09 16:49:52 +0000

    Merge commit d0b9c2c56476 from llvm git (by David CARLIER):

      [compiler-rt] Remove SHA2 interceptions for NetBSD/FreeBSD. (#110246)

      To Fix #110215

      Interceptors introduced with 18a7ebda99044473fdbce6376993714ff54e6690

    This fixes undesirable runtime failures when using -fsanitize=-address
    in combination with -lcrypto.

    Direct commit to stable/14, because main already got this change as part
    of the llvm-19 import.

    Approved by:    re (cperciva)
    Reported by:    Theo Buehler <tb@openbsd.org>
    PR:             281685

    (cherry picked from commit 4f1754bccef155c0fd24547ab3c872bd0f182224)

 .../sanitizer_common_interceptors.inc              | 180 ---------------------
 .../sanitizer_platform_interceptors.h              |   2 -
 2 files changed, 182 deletions(-)
Comment 11 Mark Johnston freebsd_committer freebsd_triage 2024-11-09 16:56:31 UTC
The patch will be in 14.2-RELEASE.  Thank you for the report.