ColinIanKing / stress-ng

This is the stress-ng upstream project git repository. stress-ng will stress test a computer system in various selectable ways. It was designed to exercise various physical subsystems of a computer as well as the various operating system kernel interfaces.
https://github.com/ColinIanKing/stress-ng
GNU General Public License v2.0
1.82k stars 290 forks source link

verify-elf: ERROR: ./usr/bin/stress-ng: uses non-LFS functions: __ppoll_chk reappeared #452

Closed vt-alt closed 3 weeks ago

vt-alt commented 3 weeks ago

V0.18.05 and V0.18.06 have issue#350 reappeared on 32-bit x86.

verify-elf is a tool we have that checks ELF binaries in the built rpm packages for problems, and there it detects a single non-LFS (large file support) syscall in 32-binary.

verify-elf: ERROR: ./usr/bin/stress-ng: uses non-LFS functions: __ppoll_chk

Proper LFS syscall would be __ppoll64_chk.

Our gcc have -D_FORTIFY_SOURCE=3 added by default into -O (I think Fedora have something like this too), but your code seems to expect fortify level 2. If I add to CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 it then compiles without aforementioned error.

ColinIanKing commented 3 weeks ago

I'm not totally familiar with arch, how does one install verify-elf?

vt-alt commented 3 weeks ago

verify-elf is integrated in our build system and is not independent tool. If you want to reproduce results, basically it reduces to readelf --wide --symbols ./usr/bin/stress-ng | grep -w -f verify-elf-non-lfs-funcs.list:

builder@i586:~/tmp/stress-ng-buildroot$ readelf --wide --symbols ./usr/bin/stress-ng| grep -w -f /usr/lib/rpm/verify-elf-non-lfs-funcs.list
   546: 00000000     0 FUNC    GLOBAL DEFAULT  UND __ppoll_chk@GLIBC_2.16 (35)

The verify-elf-non-lfs-funcs.list is generated with this formula (on 32-bit host):

        readelf --wide --symbols /lib/libc.so.6 /lib/libz.so.1 /lib/librt.so.1 |
                sed -n 's/^[[:space:]]*[0-9]\+:[[:space:]]\+[0-9a-f]\+[[:space:]]\+[0-9]\+[[:space:]]\+FUNC[[:space:]]\+[^[:space:]]\+[[:space:]]\+DEFAULT[[:space:]]\+[0-9]\+[[:space:]]\+\([^@[:space:]]\+\)@\?.*/\1/p' |
                sort -u > all-funcs
sed -r -n 's/^(.+)64(_.*|$)/\1\2/p' all-funcs |
        sort -u |
        grep -E -v '^(wcs|str)' |
        comm -12 - all-funcs |
        LC_ALL=C sort -u \
        > verify-elf-non-lfs-funcs.list
cat verify-elf-non-lfs-funcs.list ``` _IO_fgetpos _IO_fsetpos __clock_gettime __fxstat __fxstatat __gettimeofday __gmtime_r __lxstat __nanosleep __open __open_2 __open_nocancel __openat_2 __ppoll_chk __pread_chk __select __sendmmsg __sigtimedwait __xstat adler32_combine aio_cancel aio_error aio_fsync aio_read aio_return aio_suspend aio_write alphasort crc32_combine crc32_combine_gen creat fallocate fcntl fgetpos fopen freopen fseeko fsetpos fstat fstatat fstatfs fstatvfs ftello ftruncate fts_children fts_close fts_open fts_read fts_set ftw getdirentries getrlimit glob globfree gzoffset gzopen gzseek gztell lio_listio lockf lseek lstat mkostemp mkostemps mkstemp mkstemps mmap nftw open openat posix_fadvise posix_fallocate pread preadv prlimit pwrite pwritev readdir readdir_r scandir scandirat sendfile setrlimit stat statfs statvfs tmpfile truncate versionsort ```
vt-alt commented 3 weeks ago

Does this change help fix the issue?


diff --git a/stress-ng.h b/stress-ng.h
index ae35ddde5..3c5f20e79 100644
--- a/stress-ng.h
+++ b/stress-ng.h
@@ -26,6 +26,10 @@
#define _GNU_SOURCE
#endif

+#if !defined(USE_TIME_BITS64) +#define USE_TIME_BITS64 +#endif +



Yes this helped. Thanks. Strangely, I see your reply on email but not on github web.
ColinIanKing commented 3 weeks ago

I've removed that fix as it breaks other 64 bit builds. I have an improved fix that I'm just testing now on several arches

ColinIanKing commented 3 weeks ago

I've just pushed the following commit that I think should resolve this issue:

commit 9b3e9418715b013889e487ac40d14b85a2def7c4 (HEAD -> master, origin/master, origin/HEAD) Author: Colin Ian King colin.i.king@gmail.com Date: Mon Nov 4 14:29:09 2024 +0000

core-shim: add shim to ppoll() and workaround fortification issues
vt-alt commented 3 weeks ago

Thanks. But, with 9b3e9418715b013889e487ac40d14b85a2def7c4 applied it still produces the error on my setup.

vt-alt commented 3 weeks ago

I see another commit appeared, and with current origin/master (tip 15484dc9c24be214059b5bfecccb6f26bd79833c) the problem is still remains.

ColinIanKing commented 3 weeks ago

Can you try this change:

diff --git a/core-shim.c b/core-shim.c
index a7813474a..f6d0ea959 100644
--- a/core-shim.c
+++ b/core-shim.c
@@ -2843,7 +2843,7 @@ int shim_ppoll(
 #undef STRESS__FORTIFY_SOURCE
 #define STRESS__FORTIFY_SOURCE _FORTIFY_SOURCE
 #undef _FORTIFY_SOURCE
-#define _FORTIFY_SOURCE 2
+//#define _FORTIFY_SOURCE 2
 #endif

        return ppoll(fds, nfds, tmo_p, sigmask);
vt-alt commented 3 weeks ago

When applied over origin/master it still causes an error (non-LFS functions: __ppoll_chk).

ColinIanKing commented 3 weeks ago

I may apply a hammer to fix this.. can you provide me the output from:

gcc -E -dM -xc /dev/null

ColinIanKing commented 3 weeks ago

Can you try this change:


diff --git a/core-shim.c b/core-shim.c
index a7813474a..8da738ffb 100644
--- a/core-shim.c
+++ b/core-shim.c
@@ -19,6 +19,11 @@
  */
 #define STRESS_CORE_SHIM

+#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE == 3
+#undef _FORTIFY_SOURCE
+#define _FORTIFY_SOURCE 2
+#endif
+
vt-alt commented 3 weeks ago

Can you try this change:

After this applied to current master the problem disappeared.

I may apply a hammer to fix this.. can you provide me the output from: gcc -E -dM -xc /dev/null

gcc-dump.tar.gz

gcc-O.txt there is the above command with -O added.

ColinIanKing commented 3 weeks ago

I think the latest commit fixes this issue, I've pushed a fix. Please test and let me know. Thank you :-)

vt-alt commented 3 weeks ago

Tested master and it fixes the problem. Thanks!