Skip to content

Commit

Permalink
Fix hardened-binaries test for .NET 9
Browse files Browse the repository at this point in the history
With .NET 9, the NativeAOT feature results in the inclusion of a few .o
(object) files in the SDK. The `file` reports those as:

    /usr/lib64/dotnet/.../libbootstrapper.o: ELF 64-bit LSB...

Which means the test then tries to check if it was linked with BIND_NOW
and GNU_RELRO. That doesn't make any sense, because this isn't a shared
library or an executable that the linker has run over.

Fix that by skipping testing any `.o` files.
  • Loading branch information
omajid committed Jul 4, 2024
1 parent cfbcd7c commit 487a333
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions hardened-binaries/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
set -euo pipefail
IFS=$'\n\t'

set -x

root=$(dirname "$(readlink -f "$(command -v dotnet)")")
echo ".NET Core base directory: $root"

# TODO handle more architectures can just x86-64

file_list=$(find "$root/" -type f -exec file {} \; | grep -E 'ELF [[:digit:]][[:digit:]]-bit [LM]SB' | cut -d: -f 1 | sort -u)
file_list=$(find "$root/" -type f -not -iname '*.o' -exec file {} \; \
| grep -E 'ELF [[:digit:]][[:digit:]]-bit [LM]SB' \
| cut -d: -f 1 \
| sort -u)
mapfile -t binaries <<< "$file_list"
for binary in "${binaries[@]}"; do
echo "$binary"
Expand Down

0 comments on commit 487a333

Please sign in to comment.