Skip to content

Conversation

fanquake
Copy link
Member

@fanquake fanquake commented Feb 17, 2023

Use FORTIFY_SOURCE=3 when building libevent in depends. I've upstreamed a change to switch libevent from using =2 to =3 as well: libevent/libevent#1418.

Solves half of #27038, by giving us some fortified funcs in bitcoin-cli.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 17, 2023

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK TheCharlatan

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #24123 (build: Pointer Authentication and Branch Target Identification for aarch64 Linux (Guix) by fanquake)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@fanquake
Copy link
Member Author

Changed the approach here, from using libevents own hardening option (might send some fixes upstream), and a patch, to just using FORTIFY_SOURCE directly. That gets as what we want at the moment, without other potential side effects.

@theuni
Copy link
Member

theuni commented Feb 17, 2023

Do you have a before/after count for hardened functions?

@fanquake
Copy link
Member Author

fanquake commented Feb 17, 2023

Do you have a before/after count for hardened functions?

Using GCC 13 and glibc 2.37 (with only this branch):

# master
nm -C src/bitcoind | grep _chk
                 U __fprintf_chk@GLIBC_2.17
                 U __memcpy_chk@GLIBC_2.17
                 U __snprintf_chk@GLIBC_2.17
                 U __stack_chk_fail@GLIBC_2.17
                 U __stack_chk_guard@GLIBC_2.17
                 U __vsnprintf_chk@GLIBC_2.17
objdump -d src/bitcoind | grep "_chk@plt" | wc -l
32

# this branch
nm -C src/bitcoind | grep _chk
                 U __fdelt_chk@GLIBC_2.17
                 U __fprintf_chk@GLIBC_2.17
                 U __memcpy_chk@GLIBC_2.17
                 U __memmove_chk@GLIBC_2.17
                 U __memset_chk@GLIBC_2.17
                 U __snprintf_chk@GLIBC_2.17
                 U __stack_chk_fail@GLIBC_2.17
                 U __stack_chk_guard@GLIBC_2.17
                 U __vsnprintf_chk@GLIBC_2.17
objdump -d src/bitcoind | grep "_chk@plt" | wc -l
54

If I combine with our own use of FORTIFY_SOURCE=3:

nm -C src/bitcoind | grep _chk
                 U __fdelt_chk@GLIBC_2.17
                 U __fprintf_chk@GLIBC_2.17
                 U __memcpy_chk@GLIBC_2.17
                 U __memmove_chk@GLIBC_2.17
                 U __memset_chk@GLIBC_2.17
                 U __snprintf_chk@GLIBC_2.17
                 U __stack_chk_fail@GLIBC_2.17
                 U __stack_chk_guard@GLIBC_2.17
                 U __vsnprintf_chk@GLIBC_2.17
objdump -d src/bitcoind | grep "_chk@plt" | wc -l
81

@hebasto
Copy link
Member

hebasto commented Feb 17, 2023

Changed the approach here, from using libevents own hardening option

The previous 974e44c commit, being combined with the current 778e34e one, should work for older compilers as well, no?

@fanquake
Copy link
Member Author

should work for older compilers as well, no?

I changed the approach because I don't want us to use the gcc-hardening option.

Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 778e34e

@fanquake
Copy link
Member Author

Rebased on top of #27027.

@TheCharlatan
Copy link
Contributor

ACK ff4a73a

@fanquake fanquake requested a review from theuni February 22, 2023 18:12
@fanquake fanquake merged commit e60a58f into bitcoin:master Feb 28, 2023
@fanquake fanquake deleted the harden_libevent branch February 28, 2023 10:31
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 28, 2023
ff4a73a depends: use FORTIFY_SOURCE=3 with libevent (fanquake)

Pull request description:

  Use `FORTIFY_SOURCE=3` when building libevent in depends. I've upstreamed a change to switch libevent from using =2 to =3 as well: libevent/libevent#1418.

  Solves half of bitcoin#27038, by giving us some fortified funcs in `bitcoin-cli`.

ACKs for top commit:
  TheCharlatan:
    ACK ff4a73a

Tree-SHA512: eaf692ec92b288f0cb524c011fc81529f58efa4c43d418a7b3ae7108eba2bccba708a81a28ac6d063267be80ca615637c6e3fccc02497d7367af2eaae0e8d812
@hebasto
Copy link
Member

hebasto commented Mar 31, 2023

This PR introduced a regression when building with depends and disabled hardening:

$ make -C depends HOST=x86_64-w64-mingw32 NO_QT=1 NO_WALLET=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 NO_USDT=1
$ ./configure --disable-hardening CONFIG_SITE=$PWD/depends/x86_64-w64-mingw32/share/config.site
$ make
...
/usr/bin/x86_64-w64-mingw32-ld: /home/hebasto/git/gui/depends/x86_64-w64-mingw32/lib/libevent.a(evutil.o):evutil.c:(.text+0x2975): undefined reference to `__memcpy_chk'
/usr/bin/x86_64-w64-mingw32-ld: /home/hebasto/git/gui/depends/x86_64-w64-mingw32/lib/libevent.a(evutil.o):evutil.c:(.text+0x29d6): undefined reference to `__memcpy_chk'
/usr/bin/x86_64-w64-mingw32-ld: /home/hebasto/git/gui/depends/x86_64-w64-mingw32/lib/libevent.a(evutil.o):evutil.c:(.text+0x3041): undefined reference to `__strcat_chk'
/usr/bin/x86_64-w64-mingw32-ld: /home/hebasto/git/gui/depends/x86_64-w64-mingw32/lib/libevent.a(evutil.o):evutil.c:(.text+0x3052): undefined reference to `__strcat_chk'
/usr/bin/x86_64-w64-mingw32-ld: /home/hebasto/git/gui/depends/x86_64-w64-mingw32/lib/libevent.a(http.o):http.c:(.text+0x6e6): undefined reference to `__memcpy_chk'
...

fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 3, 2023
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Annoyingly, because
of the way we link libssp for Windows builds, they now fail (after bitcoin#27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin#27118 (comment).
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 3, 2023
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Annoyingly, because
of the way we link libssp for Windows builds, they now fail (after bitcoin#27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin#27118 (comment).
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 3, 2023
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Annoyingly, because
of the way we link libssp for Windows builds, they now fail (after bitcoin#27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin#27118 (comment).
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 3, 2023
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Annoyingly, because
of the way we link libssp for Windows builds, they now fail (after bitcoin#27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin#27118 (comment).
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 3, 2023
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Annoyingly, because
of the way we link libssp for Windows builds, they now fail (after bitcoin#27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin#27118 (comment).
fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 3, 2023
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Due to the way
we link libssp for Windows builds, they now fail (after bitcoin#27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin#27118 (comment).

This change would add a depends opiton such that, if someone wants to
build with, for windows, without hardening, they can do so. This may
also be useful when building for debugging.
@fanquake
Copy link
Member Author

fanquake commented Apr 3, 2023

This PR introduced a regression when building with depends and disabled hardening:

Followup for discussion in 27406.

fanquake added a commit to fanquake/bitcoin that referenced this pull request Apr 4, 2023
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Due to the way
we link libssp for Windows builds, they now fail (after bitcoin#27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin#27118 (comment).

This change would add a depends opiton such that, if someone wants to
build with, for windows, without hardening, they can do so. This may
also be useful when building for debugging.
fanquake added a commit to bitcoin-core/gui that referenced this pull request Apr 5, 2023
436df1e depends: add NO_HARDEN option (fanquake)

Pull request description:

  Add an option that when passed, will disable hardening options, and pass `--disable-hardening` through to configure. Due to the way we link `libssp` for Windows builds, they now fail (after #27118), if building with depends, and configuring with `--disable-hardening` (Windows is the odd build out here). See: bitcoin/bitcoin#27118 (comment).

  This change would add a depends option such that, if someone wants to build with depends, for Windows, without hardening, they can do so. This may also be useful when building for debugging.

ACKs for top commit:
  hebasto:
    re-ACK 436df1e

Tree-SHA512: 5a3ef5ec87b10a5ad0a284201988ce94789451735c7c7e20d337f7232955b0b9a0addab1c3b5725755f00d8ce6741aa9c8cb5e3d48d926515b7dde46acdbcaa0
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 5, 2023
436df1e depends: add NO_HARDEN option (fanquake)

Pull request description:

  Add an option that when passed, will disable hardening options, and pass `--disable-hardening` through to configure. Due to the way we link `libssp` for Windows builds, they now fail (after bitcoin#27118), if building with depends, and configuring with `--disable-hardening` (Windows is the odd build out here). See: bitcoin#27118 (comment).

  This change would add a depends option such that, if someone wants to build with depends, for Windows, without hardening, they can do so. This may also be useful when building for debugging.

ACKs for top commit:
  hebasto:
    re-ACK 436df1e

Tree-SHA512: 5a3ef5ec87b10a5ad0a284201988ce94789451735c7c7e20d337f7232955b0b9a0addab1c3b5725755f00d8ce6741aa9c8cb5e3d48d926515b7dde46acdbcaa0
marcosptf pushed a commit to marcosptf/bitcoin-labs that referenced this pull request Apr 9, 2023
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Due to the way
we link libssp for Windows builds, they now fail (after #27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin/bitcoin#27118 (comment).

This change would add a depends opiton such that, if someone wants to
build with, for windows, without hardening, they can do so. This may
also be useful when building for debugging.
willcl-ark pushed a commit to willcl-ark/bitcoin that referenced this pull request Apr 18, 2023
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Due to the way
we link libssp for Windows builds, they now fail (after bitcoin#27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin#27118 (comment).

This change would add a depends opiton such that, if someone wants to
build with, for windows, without hardening, they can do so. This may
also be useful when building for debugging.
RandyMcMillan pushed a commit to RandyMcMillan/bitcoin that referenced this pull request May 27, 2023
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Due to the way
we link libssp for Windows builds, they now fail (after bitcoin#27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin#27118 (comment).

This change would add a depends opiton such that, if someone wants to
build with, for windows, without hardening, they can do so. This may
also be useful when building for debugging.
janus pushed a commit to BitgesellOfficial/bitgesell that referenced this pull request Sep 3, 2023
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Due to the way
we link libssp for Windows builds, they now fail (after #27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin/bitcoin#27118 (comment).

This change would add a depends opiton such that, if someone wants to
build with, for windows, without hardening, they can do so. This may
also be useful when building for debugging.
backpacker69 pushed a commit to peercoin/peercoin that referenced this pull request Mar 5, 2024
Add an option that when passed, will disable hardening options, and
pass `--disable-hardening` through to configure. Due to the way
we link libssp for Windows builds, they now fail (after #27118),
if building with depends, and configuring with --disable-hardening.
See:
bitcoin/bitcoin#27118 (comment).

This change would add a depends opiton such that, if someone wants to
build with, for windows, without hardening, they can do so. This may
also be useful when building for debugging.
@bitcoin bitcoin locked and limited conversation to collaborators Apr 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants