slimm609 / checksec

Checksec
https://slimm609.github.io/checksec
Other
2.04k stars 306 forks source link

Fortify check is quadratic and slow in FS_comparison() #216

Closed Artoria2e5 closed 1 year ago

Artoria2e5 commented 1 year ago

Issue tracker

If any of these values are not included, the issue will be closed and not worked

Issue

Fortify check takes a couple seconds.

Debug Report; OS Ver

include the output of checksec --debug_report

This is a custom distro run in WSL1. It's a very ancient version of what AOSC-Dev ships -- from the day I got too tired to use Linux.

***** Checksec debug *****
uid=0(root) gid=0(root) groups=0(root)
Linux Arisu 4.4.0-22621-Microsoft #1020-Microsoft Fri Jan 01 08:00:00 PST 2016 x86_64 GNU/Linux
checksec version: 2.6.0 -- 2022052701
OS=AOSC OS
VER=8
-rwxr-xr-x 1 root root 34912 Jan 18  2021 /usr/bin/cat
/usr/bin/cat: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=d770a5b27eb5b0e8da013179ce72765f3920b243, for GNU/Linux 3.4.0, stripped
lrwxrwxrwx 1 root root 21 Jul  2  2020 /usr/bin/awk -> /etc/alternatives/awk
-rwxr-xr-x 2 root root 708888 Jan 18  2021 /usr/bin/gawk
/usr/bin/gawk: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=f629fa0c574434657248b22f492e7edf89ab0ff3, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 30736 Jan 18  2021 /usr/bin/sysctl
/usr/bin/sysctl: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=554bc7d967393fd9c4f8f986a7891a92cdc738ff, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 211328 Jan 18  2021 /usr/bin/sed
/usr/bin/sed: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=83fac3d3465961c345579b6ba431f489d9a6b6e7, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 30864 Jan 18  2021 /usr/bin/uname
/usr/bin/uname: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=5dc1016c3d51cfa6569e6dfca4db4a6398bc8854, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 467560 Dec 14  2020 /usr/bin/objdump
/usr/bin/objdump: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=c01c247e52af077e409b8113e5a4a6eababb253c, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 34960 Jan 18  2021 /usr/bin/mktemp
/usr/bin/mktemp: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=d4a56cd3f53cfce09dc1451f25ea2ebaff179dce, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 777880 Mar 17  2021 /usr/bin/openssl
/usr/bin/openssl: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=f377e35829aa899bdda7ece5cb66411819c505d0, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 182504 Jan 18  2021 /usr/bin/grep
/usr/bin/grep: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=dd112a2ce6b3d8e50285a438d0cdd9224779d677, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 80024 Jan 18  2021 /usr/bin/stat
/usr/bin/stat: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=cdbab3024e4abe794394e9c892d68d4b32f354a5, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 31088 Jan 18  2021 /usr/bin/file
/usr/bin/file: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=76b2c08970814a82720c42bece61aa28e14d288a, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 285808 Jan 18  2021 /usr/bin/find
/usr/bin/find: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=e0a7cff714cd83e1cec67448ae319f265491f145, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 43152 Jan 18  2021 /usr/bin/head
/usr/bin/head: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=f5725cc77e54bb5269474a6e4be6d640f205012f, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 137456 Jan 18  2021 /usr/bin/ps
/usr/bin/ps: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=bdf10d876eb93802e1a5c5bb69e679ae8c34564c, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 34864 Jan 18  2021 /usr/bin/readlink
/usr/bin/readlink: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=1b94c8b5c7e718063066e0adf59bd2569a6071b5, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 30864 Jan 18  2021 /usr/bin/basename
/usr/bin/basename: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=6e94b2a1df0fb80149956090a814c2c562f58b0c, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 39056 Jan 18  2021 /usr/bin/id
/usr/bin/id: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=c23a4d39d68fadd2daf788b9bf9f8ba9e53a022e, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 31224 Jan 18  2021 /usr/bin/which
/usr/bin/which: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=045a2f7a3abfbcc304774fac29b0e2e855e9cdec, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 519280 Jan 18  2021 /usr/bin/wget
/usr/bin/wget: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=266361d1e513243a1dcfa69108c0491ba8532df5, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 231432 Sep 27  2020 /usr/bin/curl
/usr/bin/curl: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=bc016e2543a7c184acd350d0e5fdd843743c8fa5, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 760592 Dec 14  2020 /usr/bin/readelf
/usr/bin/readelf: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=05b1f826ad72be1830cd1a7784e388ee430fa908, for GNU/Linux 3.4.0, stripped
-rwxr-xr-x 1 root root 256200 Jan 18  2021 /usr/bin/eu-readelf
/usr/bin/eu-readelf: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=8ddbff8b1de6eba8e3af333fe7adab19e89253b9, for GNU/Linux 3.4.0, stripped

Command run to produce the error

time ./cs.sh --fortify-file=/bin/bash

real    0m3.403s        50.96%
user    0m1.391s
sys     0m0.344s

OS version and Kernel version

AOSC OS "8", which is 4 years ago? MS WSL1, which emulates 4.4.

Debug output

No, nothing new in --debug. The performance bottleneck is found by tracing.


Fix suggestion

The obvious way is to use the bash 4 associative array data type. But the better way is to enforce sorting on these arrays so we only need to play catch up, which should end up linear to array size (whichever is larger).