build: pass hardening flags to secp256k1 #36534

pull fametrano wants to merge 1 commits into bitcoin:master from fametrano:build-secp256k1-hardening changing 2 files +61 −20
  1. fametrano commented at 7:04 AM on October 15, 2026: contributor

    The secp256k1 subtree is built without our hardening flags: they are on core_interface, which the subtree does not use, so unless the compiler enables them by default its objects miss FORTIFY, the stack protector, stack clash protection and control flow protection. On aarch64 Ubuntu 26.04 with GCC 15, the three secp256k1 objects are the only ones in the build tree without the control flow property, so master's bitcoind has no AArch64 feature note.

    This PR moves the flags back to a hardening_interface library, which core_interface links (reverting 77e553ab6a), and cmake/secp256k1.cmake passes the subtree those its C compiler accepts. The same build then shows AArch64 feature: BTI, PAC, GCS on bitcoind. The depends libraries still lack -fcf-protection (#30677, #30685).

  2. DrahtBot added the label Build system on Oct 15, 2026
  3. DrahtBot commented at 7:05 AM on October 15, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. maflcko added the label DrahtBot Guix build requested on Oct 15, 2026
  5. DrahtBot commented at 1:49 AM on October 25, 2026: contributor

    <!--9cd9c72976c961c55c7acef8f6ba82cd-->

    Guix builds (on x86_64) [untrusted test-only build, possibly unsafe, not for production use]

    File commit 3eca89820e1fb152ebf0315e3924fc374cb35958<br>(master) commit 5d512d01eb1cbfd66bfee2a617619872a5103fed<br>(pull/36534/merge)
    *-aarch64-linux-gnu-debug.tar.gz 3d99f1b5dfe7139d... d32a1b7a380dfeec...
    *-aarch64-linux-gnu.tar.gz e119310c231af339... be5015fb57bf02e3...
    *-arm-linux-gnueabihf-debug.tar.gz b3611994b1ccc3fc... e7551e2af7575a05...
    *-arm-linux-gnueabihf.tar.gz 099c30d039fd1ccf... 5a3aee80cd81064b...
    *-arm64-apple-darwin-codesigning.tar.gz e24595ece52716a3... cd3e83a8e4fe8a0c...
    *-arm64-apple-darwin-unsigned.tar.gz 886662eba9cd08ba... fcbff104c5f8e548...
    *-arm64-apple-darwin-unsigned.zip 29e1c0908552b826... 2eaf32ff566a0676...
    *-powerpc64-linux-gnu-debug.tar.gz 8bf7cd9b1d94139a... f2843cff10cfee24...
    *-powerpc64-linux-gnu.tar.gz 05b93aac6c5c3220... 3dfe17710f8a9b33...
    *-riscv64-linux-gnu-debug.tar.gz b4d2eda8888b02fd... 3a527cf3df9690eb...
    *-riscv64-linux-gnu.tar.gz 48efc464a63eea29... 6e4a267e64064680...
    *-win64-codesigning.tar.gz e3027e6bc4ead530... ac239ffb35c099ec...
    *-win64-debug.zip 3fec05694843befa... 7066e35cb9c3868c...
    *-win64-setup-unsigned.exe 6377610c2a3f66c2... ecf4502ef6ea5004...
    *-win64-unsigned.zip f0015cc1ae1f7e90... ef1f3b27d5992b40...
    *-x86_64-apple-darwin-codesigning.tar.gz ef4f9a7592fa1658... 49e1982fdbe0899b...
    *-x86_64-apple-darwin-unsigned.tar.gz 913cfdabdeea381f... 3005e5682f72aefd...
    *-x86_64-apple-darwin-unsigned.zip 6c0fe3baad354830... c45f3a484dbdd2e8...
    *-x86_64-linux-gnu-debug.tar.gz 09c21fb85429895c... a13f2b07948fd349...
    *-x86_64-linux-gnu.tar.gz d7ca7386bd38bf30... 4153960fdea5f6b7...
    *.tar.gz 824fb8782d74d318... e2b5060c2f5c24f3...
    SHA256SUMS.part 37d921b59621a29a... cecaf142faedb223...
    guix_build.log 7a3293747836a472... d3ac1cecf9aaf3fc...
    guix_build.log.diff 909ccd87681a4eae...
  6. DrahtBot removed the label DrahtBot Guix build requested on Oct 25, 2026
  7. hebasto commented at 2:07 PM on October 27, 2026: member

    I think that Ralph's feedback should be addressed.

  8. fametrano force-pushed on Nov 1, 2026
  9. fametrano commented at 6:50 PM on November 1, 2026: contributor

    @hebasto, Ralph's finding is addressed in 08bd06ccd4: cmake/secp256k1.cmake now checks each hardening flag with the C compiler, together with those accepted before it, and passes secp256k1 only those it accepts.

    I tested it with a C compiler wrapper that rejects -fstack-protector-all: master builds, 09509dde1d fails to build secp256k1, and 08bd06ccd4 drops the flag at configure time and builds. The wrapper, the commands and their output: https://gist.github.com/fametrano/6c0ed42765b0fc0a0d7cc9d3ae4fceb3/0f0ddc7b9b05391659c3ed92b8a74893b263a377

    I filter rather than stop configuration, so a toolchain that builds on master keeps building. secp256k1 then lacks only the flags its C compiler rejects, as Core's own targets lack those the C++ compiler rejects.

  10. build: pass hardening flags to secp256k1
    The hardening flags are added to core_interface, which the secp256k1
    subtree does not use: cmake/secp256k1.cmake passes it only the
    sanitizer and APPEND_* flags. Its objects are therefore built without
    _FORTIFY_SOURCE, -fstack-protector-all, -fstack-clash-protection,
    -fcf-protection and -mbranch-protection, unless the compiler enables
    them by default.
    
    This also drops the control flow property from the binaries. The
    linker marks an executable as BTI/PAC (aarch64) or IBT/SHSTK (x86_64)
    enabled only when every object it links has the property. On aarch64
    Ubuntu 26.04 with GCC 15, bitcoind built from master has no AArch64
    feature property, and the secp256k1 objects are the only objects in
    the build tree without it.
    
    Move the hardening flags to a hardening_interface library, which
    core_interface links, and pass its compile and link options to the
    subtree in the same way as sanitize_interface. This brings back the
    hardening_interface that was folded into core_interface in 77e553ab6a,
    now that the flags have a second user.
    
    The hardening flags are checked with the C++ compiler, and the subtree
    is built with the C compiler. Check them again with the C compiler and
    pass on only those it accepts, so that a C compiler rejecting one of
    them cannot break the subtree's build. Each flag is checked together
    with those accepted before it, because -D_FORTIFY_SOURCE=3 alone fails
    with -Werror where CFLAGS already define _FORTIFY_SOURCE, and dropping
    it while keeping -U_FORTIFY_SOURCE would build secp256k1 without
    FORTIFY at all.
    c1f588dfb2
  11. fametrano force-pushed on Nov 11, 2026
  12. fametrano commented at 12:40 AM on November 11, 2026: contributor

    On an Apple M5 with Apple clang, the hardening flags cost secp256k1 little: against master, the bench_bitcoin VerifyScript benchmarks are within 0.5% and the ConnectBlock ones about 1% slower, as medians of 20 back-to-back pairs per benchmark. Two benchmarks that run no secp256k1 code stay within 0.5%. Schnorr signing is within 1%; SignTransactionECDSA varied too much between runs to give a number. On this platform the flags added are -fstack-protector-all, _FORTIFY_SOURCE=3 and BTI. Scripts and raw numbers: https://gist.github.com/fametrano/cc48d5fa5cca8b0bd2c8b4b1499d688c/28c42316be0515a44db526a14866fb615a566ba7


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-16 00:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me