[PATCH] fortify: further improve Clang style fortify
Andrej Shadura
andrew.shadura@collabora.co.uk
Thu Mar 27 14:48:08 GMT 2025
On 27/03/2025 15:35, Adrian Ratiu wrote:
> glibc >= v2.41 significatly improved clang fortify support,
> so I've rebased the ChromeOS toolchain test suite [1] on
> top of the upstream implementation and semantics.
>
> Doing this I noticed some missing upstream diagnostics, so
> I've added them to get Clang builds on par with GCC.
>
> In addition to the missing ones I also noticed some mismatch
> bugs between __glibc_objsize0 vs __glibc_objsize calls done
> via various macros like:
> __fortify_clang_warning_only_if_bos0_lt2 versus
> __fortify_clang_warning_only_if_bos_lt2
>
> The general rule is that the function argument declaration
> must match its uses to ensure check consistency between the
> __glibc_objsize0 and __glibc_objsize calls.
>
> For example if the arg is defined like
> __fortify_clang_overload_arg (...)
> then a form like the following must be used:
> __fortify_clang_warning_only_if_bos_lt2(...)
>
> If the arg is defined like
> __fortify_clang_overload_arg0 (...)
> then a form like the following must be used:
> __fortify_clang_warning_only_if_bos0_lt2(...)
>
> This rule ensures consistent use of __glibc_objsize0 vs
> __glibc_objsize calls in checks.
>
> While a diagnostic message might be correctly printed
> with the above type of mismatch, LLVM/Clang will not be
> able to signal and terminate a process despite for eg a
> buffer overflow being detected (it will happily continue).
despite e.g. having detected a buffer overflow, and the process will
happily continue.
>
> So the end result of this type of bug fix is that processes
> will get terimated by proper signals when fortify diagnostics
terminated
> get triggered.
>
> Based on a patch by George Burges with contributions from
> Andrej Shadura. [2]
> Link: https://chromium.googlesource.com/chromiumos/platform2/+/refs/heads/main/cros-toolchain/fortify-tests/clang-fortify-tests.cpp [1]
> Link: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/refs/heads/staging-infra-release-R135-16209.B/sys-libs/glibc/files/local/glibc-2.39/0005-glibc-add-clang-style-FORTIFY.patch [2]
> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Thanks!
Acked-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
--
--
Cheers,
Andrej
More information about the Libc-alpha
mailing list