Skip to content

toolchain: fortify-headers: Update to version 2.3.3 and add _FORTIFY_SOURCE=3 - #20313

Merged
openwrt-bot merged 2 commits into
openwrt:mainfrom
hauke:fortify-headers
Oct 25, 2025
Merged

openwrt-bot merged 2 commits into
openwrt:mainfrom
hauke:fortify-headers

Conversation

@hauke

@hauke hauke commented Oct 5, 2025 •

Copy link
Copy Markdown
Member
  • toolchain: fortify-headers: Update to version 2.3.3

    Update to recent fortify-headers version. This version also supports
    _FORTIFY_SOURCE=3.

    Changes: jvoisin/fortify-headers@1.1...2.3.3

    A patch similar to the removed one was applied upstream:
    jvoisin/fortify-headers@b40f6d8

  • build: Add _FORTIFY_SOURCE=3 support

    Add support for _FORTIFY_SOURCE level 3.

    This is supported with glibc and with musl libc.

I build this on armsr/armv8 and x86/64 target with _FORTIFY_SOURCE=1 and _FORTIFY_SOURCE=3 with musl and booted the images in qemu successfully.

@github-actions github-actions Bot added build/scripts/tools pull request/issues for build, scripts and tools related changes toolchain pull request/issue with toolchain related changes labels Oct 5, 2025
@Ansuel

Ansuel commented Oct 9, 2025

Copy link
Copy Markdown
Member

@hauke benefits of fortify source 3?

@hauke

hauke commented Oct 23, 2025

Copy link
Copy Markdown
Member Author

RedHat has a good block for such topics.

Here is an article about _FORTIFY_SOURCE=3:
https://developers.redhat.com/articles/2022/09/17/gccs-new-fortification-level

It activates some more more expensive ways to determine the size of an object to make functions fail when they do an buffer overflow.

@hauke

hauke commented Oct 25, 2025

Copy link
Copy Markdown
Member Author

I compared OpenWrt compiled with the old fortify sources and the new one.
I used OpenWrt with standard configuration and musl libc for aarch64 and mips32.

I decompiled some binaries and compared them with some binary diff tools. There are smaller changes, strcpy arguments are now better checked for example, but the changes are not significant.

hauke added 2 commits October 26, 2025 01:41
Update to recent fortify-headers version. This version also supports
_FORTIFY_SOURCE=3.

Changes: jvoisin/fortify-headers@1.1...2.3.3

A patch similar to the removed one was applied upstream:
jvoisin/fortify-headers@b40f6d8

The root file system is getting a bit bigger.
Without this commit:
5250380 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4919997 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz
With this commit:
5263407 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4930011 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
Add support for _FORTIFY_SOURCE level 3.

This is supported with glibc and with musl libc.

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
@openwrt-bot
openwrt-bot merged commit 93f8662 into openwrt:main Oct 25, 2025
@yangfl

yangfl commented Oct 26, 2025

Copy link
Copy Markdown
Contributor

openwrt/packages#27708

@hnyman

hnyman commented Oct 26, 2025

Copy link
Copy Markdown
Contributor

One observation:
There may be trouble for packages that for some reason specify a really old C version. That is because the new headers include some C++ style comments after the endif directives, which was not yet allowed in C90.

I have an out-of-tree version of fribdi (that also exists in video feed), and that failed with the new fortify-headers. (The package will likely fail also in buildbot in the next round, as the version in Makefile is the same)

As C++ style of comments are not allowed, they are not recognized as comments, and all endif's with them throw later errors.

[28/60] Compiling C object lib/libfribidi.so.0.4.0.p/fribidi.c.o
FAILED: [code=1] lib/libfribidi.so.0.4.0.p/fribidi.c.o 
aarch64-openwrt-linux-musl-gcc -Ilib/libfribidi.so.0.4.0.p  ... -g -ansi -Os -pipe ...

In file included from /OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/stdlib.h:27,
                 from ../lib/common.h:55,
                 from ../lib/fribidi.c:30:
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/fortify-headers.h:24:1: error: C++ style comments are not allowed in ISO C90
   24 | // https://clang.llvm.org/docs/LanguageExtensions.html#has-builtin
      | ^
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/fortify-headers.h:24:1: note: (this will be reported only once per input file)
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/stdlib.h:174:8: warning: extra tokens at end of #endif directive [-Wendif-labels]
  174 | #endif // clang
      |        ^
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/stdlib.h:180:8: warning: extra tokens at end of #endif directive [-Wendif-labels]

I patched my local copy to avoid declaring that old C90 via "-ansi". (Upstream has already done that in their git, but has not yet done a new release.)

@hnyman

hnyman commented Oct 26, 2025

Copy link
Copy Markdown
Contributor

@hauke

elfutils throws two different errors:

error: this use of "defined" may not be portable [-Werror=expansion-to-defined]
error: 'nonnull' argument '__s' compared to NULL [-Werror=nonnull-compare]

make[3]: Entering directory '/OpenWrt/aarch64/build_dir/target-aarch64_cortex-a53_musl/elfutils-0.192'
make --no-print-directory all-recursive
Making all in config
make[5]: Nothing to be done for 'all'.
Making all in lib
aarch64-openwrt-linux-musl-gcc -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/usr/share/locale"' -I. -I..  -iquote . -I. -I../lib -I.. -I./../libelf -I/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/usr/include -I/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include -I/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify    -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes -Wtrampolines -Wlogical-op -Wduplicated-cond -Wnull-dereference -Wimplicit-fallthrough=5 -Wuse-after-free=3 -Werror -Wunused -Wextra -Wstack-usage=262144   -fPIC -Os -pipe -mcpu=cortex-a53 -g3 -fno-caller-saves -fno-plt -fhonour-copts -fmacro-prefix-map=/OpenWrt/aarch64/build_dir/target-aarch64_cortex-a53_musl/elfutils-0.192=elfutils-0.192 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro   -D_GNU_SOURCE -Wno-unused-result -Wno-format-nonliteral -Wno-error=use-after-free  -c -o xasprintf.o xasprintf.c
In file included from /OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/stdio.h:26,
                 from xasprintf.c:34:
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/fortify-headers.h:26:30: error: this use of "defined" may not be portable [-Werror=expansion-to-defined]
   26 | #define __fh_has_builtin(x) (__has_builtin(x) || defined(x))
      |                              ^~~~~~~~~~~~~
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/fortify-headers.h:28:7: note: in expansion of macro '__fh_has_builtin'
   28 | #if ! __fh_has_builtin(__builtin_trap)
      |       ^~~~~~~~~~~~~~~~
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/fortify-headers.h:26:30: error: this use of "defined" may not be portable [-Werror=expansion-to-defined]
   26 | #define __fh_has_builtin(x) (__has_builtin(x) || defined(x))
      |                              ^~~~~~~~~~~~~
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/fortify-headers.h:73:29: note: in expansion of macro '__fh_has_builtin'
   73 | #if _FORTIFY_SOURCE  > 2 && __fh_has_builtin (__builtin_dynamic_object_size)
      |                             ^~~~~~~~~~~~~~~~
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/fortify-headers.h:26:30: error: this use of "defined" may not be portable [-Werror=expansion-to-defined]
   26 | #define __fh_has_builtin(x) (__has_builtin(x) || defined(x))
      |                              ^~~~~~~~~~~~~
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/fortify-headers.h:158:5: note: in expansion of macro '__fh_has_builtin'
  158 | #if __fh_has_builtin (__builtin_mul_overflow_p)
      |     ^~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[5]: *** [Makefile:511: xasprintf.o] Error 1
make[4]: *** [Makefile:551: all-recursive] Error 1
make[3]: *** [Makefile:467: all] Error 2
make[3]: Leaving directory '/OpenWrt/aarch64/build_dir/target-aarch64_cortex-a53_musl/elfutils-0.192'
make[2]: *** [Makefile:123: /OpenWrt/aarch64/build_dir/target-aarch64_cortex-a53_musl/elfutils-0.192/.built] Error 2
In file included from xstrndup.c:34:
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/string.h: In function 'mempcpy':
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/string.h:340:13: error: 'nonnull' argument '__d' compared to NULL [-Werror=nonnull-compare]
  340 |         if (!__d || !__s)
      |             ^~~~
/OpenWrt/aarch64/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify/string.h:340:21: error: 'nonnull' argument '__s' compared to NULL [-Werror=nonnull-compare]
  340 |         if (!__d || !__s)
      |                     ^~~~
cc1: all warnings being treated as errors
make[5]: *** [Makefile:511: xstrndup.o] Error 1

This makes it to compile, but I am not sure if that is the right long-term solution:

--- a/package/libs/elfutils/Makefile
+++ b/package/libs/elfutils/Makefile
@@ -87,6 +87,8 @@ TARGET_CFLAGS += \
        -D_GNU_SOURCE \
        -Wno-unused-result \
        -Wno-format-nonliteral \
+       -Wno-error=expansion-to-defined \
+       -Wno-error=nonnull-compare \
        -Wno-error=use-after-free
 
 define Build/InstallDev

simsasss pushed a commit to simsasss/openwrt that referenced this pull request Oct 26, 2025
Update to recent fortify-headers version. This version also supports
_FORTIFY_SOURCE=3.

Changes: jvoisin/fortify-headers@1.1...2.3.3

A patch similar to the removed one was applied upstream:
jvoisin/fortify-headers@b40f6d8

The root file system is getting a bit bigger.
Without this commit:
5250380 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4919997 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz
With this commit:
5263407 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4930011 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
simsasss pushed a commit to simsasss/openwrt that referenced this pull request Oct 26, 2025
Add support for _FORTIFY_SOURCE level 3.

This is supported with glibc and with musl libc.

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
@hauke
hauke deleted the fortify-headers branch October 26, 2025 23:53
@kuanyili

Copy link
Copy Markdown
Contributor

Targets like bcm27xx and lantiq also failed to build some required packages after this PR.

https://buildbot.openwrt.org/images/#/waterfall

testuser7 pushed a commit to testuser7/openwrt that referenced this pull request Oct 28, 2025
Update to recent fortify-headers version. This version also supports
_FORTIFY_SOURCE=3.

Changes: jvoisin/fortify-headers@1.1...2.3.3

A patch similar to the removed one was applied upstream:
jvoisin/fortify-headers@b40f6d8

The root file system is getting a bit bigger.
Without this commit:
5250380 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4919997 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz
With this commit:
5263407 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4930011 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
testuser7 pushed a commit to testuser7/openwrt that referenced this pull request Oct 28, 2025
Update to recent fortify-headers version. This version also supports
_FORTIFY_SOURCE=3.

Changes: jvoisin/fortify-headers@1.1...2.3.3

A patch similar to the removed one was applied upstream:
jvoisin/fortify-headers@b40f6d8

The root file system is getting a bit bigger.
Without this commit:
5250380 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4919997 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz
With this commit:
5263407 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4930011 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
@hauke

hauke commented Oct 28, 2025

Copy link
Copy Markdown
Member Author

I reverted the the fortify-headers update again, see ab221cf fbe2ad6 and 677c5c3.

The old version works fine for us, but the updates have too many problems.

testuser7 pushed a commit to testuser7/openwrt that referenced this pull request Oct 28, 2025
Add support for _FORTIFY_SOURCE level 3.

This is supported with glibc and with musl libc.

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
testuser7 pushed a commit to testuser7/openwrt that referenced this pull request Oct 28, 2025
Add support for _FORTIFY_SOURCE level 3.

This is supported with glibc and with musl libc.

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
Vladdrako pushed a commit to Vladdrako/openwrt that referenced this pull request Nov 3, 2025
Update to recent fortify-headers version. This version also supports
_FORTIFY_SOURCE=3.

Changes: jvoisin/fortify-headers@1.1...2.3.3

A patch similar to the removed one was applied upstream:
jvoisin/fortify-headers@b40f6d8

The root file system is getting a bit bigger.
Without this commit:
5250380 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4919997 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz
With this commit:
5263407 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4930011 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
Vladdrako pushed a commit to Vladdrako/openwrt that referenced this pull request Nov 3, 2025
Add support for _FORTIFY_SOURCE level 3.

This is supported with glibc and with musl libc.

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
LuisMitaHL pushed a commit to LuisMitaHL/LooperWrt that referenced this pull request Sep 21, 2026
Update to recent fortify-headers version. This version also supports
_FORTIFY_SOURCE=3.

Changes: jvoisin/fortify-headers@1.1...2.3.3

A patch similar to the removed one was applied upstream:
jvoisin/fortify-headers@b40f6d8

The root file system is getting a bit bigger.
Without this commit:
5250380 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4919997 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz
With this commit:
5263407 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4930011 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
LuisMitaHL pushed a commit to LuisMitaHL/LooperWrt that referenced this pull request Sep 21, 2026
Add support for _FORTIFY_SOURCE level 3.

This is supported with glibc and with musl libc.

Link: openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
Quarx2k pushed a commit to Quarx2k/OpenWRT-BE7000 that referenced this pull request Sep 22, 2026
Update to recent fortify-headers version. This version also supports
_FORTIFY_SOURCE=3.

Changes: jvoisin/fortify-headers@1.1...2.3.3

A patch similar to the removed one was applied upstream:
jvoisin/fortify-headers@b40f6d8

The root file system is getting a bit bigger.
Without this commit:
5250380 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4919997 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz
With this commit:
5263407 bin/targets/armsr/armv8/openwrt-armsr-armv8-generic-rootfs.tar.gz
4930011 bin/targets/malta/be/openwrt-malta-be-default-rootfs.tar.gz

Link: openwrt/openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
Quarx2k pushed a commit to Quarx2k/OpenWRT-BE7000 that referenced this pull request Sep 22, 2026
Add support for _FORTIFY_SOURCE level 3.

This is supported with glibc and with musl libc.

Link: openwrt/openwrt#20313
Signed-off-by: Hauke Mehrtens <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build/scripts/tools pull request/issues for build, scripts and tools related changes toolchain pull request/issue with toolchain related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants