Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix duplicate entries #238

Merged
merged 1 commit into from
Apr 27, 2024
Merged

fix: fix duplicate entries #238

merged 1 commit into from
Apr 27, 2024

Conversation

slimm609
Copy link
Owner

  • fix duplicate entries in fortifed count
  • check binary to validate that it relies on glibc before comparing against glibc

@slimm609 slimm609 force-pushed the fix_duplicate_entries branch 3 times, most recently from 1277756 to 1942028 Compare April 26, 2024 01:19
@teoberi
Copy link
Contributor

teoberi commented Apr 26, 2024

The solution chosen to test the libc dependency:
ldd "${1}" 2> /dev/null | grep 'libc\.so' | cut -d' ' -f3
differs a bit from the one I thought of, that is was:
${readelf} -d "${1}" 2> /dev/null | grep 'NEEDED' | grep 'libc\.so'
or (maybe)
${readelf} -d "${1}" 2> /dev/null | grep 'NEEDED' | grep 'libc\.so' | awk '{print $5}

Source:
https://www.baeldung.com/linux/show-shared-libraries-executables

3. Using the ldd Command
...
The ldd command is pretty handy to list the shared libraries of a program.
However, we should use it with caution, as the ldd utility may execute the program to get the list of the shared libraries. We should never run the ldd command on untrusted executables.

7. Conclusion
In this article, we’ve discussed different ways to list shared libraries of a program.
The ldd command is the most straightforward one to show the shared libraries of a program. The readelf command is a better choice compared to the rest since we deal with “ELF” format on Linux. However, we must keep in mind that we should never use it on untrusted executables.

@teoberi
Copy link
Contributor

teoberi commented Apr 26, 2024

For your request from here: #236 (comment) maybe we could add to Fortify, for "N/A" case in tests/binaries:

  1. from here a version of "Hello World" in C + ASM to test the binary file case without libc dependency
    Build commands:
gcc -o hello main.c start.S hello.S -w -nostdlib -no-pie -s
clang -o hello_cl main.c start.S hello.S -w -nostdlib -no-pie -s
gcc -m32 -o hello32 main.c start.S hello.S -w -nostdlib -no-pie -s
clang -m32 -o hello_cl32 main.c start.S hello.S -w -nostdlib -no-pie -s
  1. from here a version of "Hello World" in C to test the binary file case when "${FS_cnt_total}" == "0"
    Build commands:
gcc -o helloworld helloworld.c -w -D_FORTIFY_SOURCE=0 -O2 -s
clang -o helloworld_cl helloworld.c -w -D_FORTIFY_SOURCE=0 -O2 -s
gcc -m32 -o helloworld32 helloworld.c -w -D_FORTIFY_SOURCE=0 -O2 -s
clang -m32 -o helloworld_cl32 helloworld.c -w -D_FORTIFY_SOURCE=0 -O2 -s

Source files:
hello.zip
helloworld.zip

Fortify testing for the "N/A" case in tests/hardening-checks.sh
using:

# N/A
for bin in rel.o rel32.o rel_cl.o rel_cl32.o; do

is not working!
It works instead with the previously generated files, that is:

# N/A
for bin in hello hello_cl hello32 hello_cl32 helloworld helloworld_cl helloworld32 helloworld_cl32; do

@slimm609 slimm609 force-pushed the fix_duplicate_entries branch 3 times, most recently from 67be104 to 9e63e9e Compare April 27, 2024 00:22
- fix duplicate entries in fortifed count
- check binary to validate that it relies on glibc before comparing against glibc
- update kernel configs
- add n/a and fs_cnt_total = 0 tests
- update gitignore
@slimm609 slimm609 force-pushed the fix_duplicate_entries branch from 9e63e9e to 3e35801 Compare April 27, 2024 00:28
@slimm609 slimm609 merged commit ec535a9 into main Apr 27, 2024
1 check passed
@slimm609 slimm609 deleted the fix_duplicate_entries branch April 27, 2024 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants