[LTP] [PATCH 1/1] tst_clocks.c: Fix stack smashing on 32bit

Petr Vorel pvorel@suse.cz
Thu Oct 12 11:15:46 CEST 2023


63e8c1eba introduced a regression on 32 bit compilation when compiled
with -fstack-protector-strong, because struct timespec is probably too
small for timespec64.

    PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig CFLAGS="-m32 -fstack-protector-strong" LDFLAGS="-m32 -fstack-protector-strong" ./configure
    ...
    # gdb ./abort01
    (gdb) set follow-fork-mode child
    (gdb) run
    Starting program: testcases/kernel/syscalls/abort/abort01
    Missing separate debuginfos, use: zypper install glibc-32bit-debuginfo-2.31-150300.52.2.x86_64
    tst_test.c:1690: TINFO: LTP version: 20230929-7-gff6cdc67f
    tst_test.c:1576: TINFO: Timeout per run is 0h 00m 30s
    [Attaching after process 3357 fork to child process 3360]
    [New inferior 2 (process 3360)]
    [Detaching after fork from parent process 3357]
    [Inferior 1 (process 3357) detached]
    *** stack smashing detected ***: terminated

    Thread 2.1 "abort01" received signal SIGABRT, Aborted.
    [Switching to process 3360]
    0xf7fd2559 in __kernel_vsyscall ()
    (gdb) bt
    #0  0xf7fd2559 in __kernel_vsyscall ()
    #1  0xf7e08aa2 in raise () from /lib/libc.so.6
    #2  0xf7e09efd in abort () from /lib/libc.so.6
    #3  0xf7e4d91b in __libc_message () from /lib/libc.so.6
    #4  0xf7eeb2cc in __fortify_fail () from /lib/libc.so.6
    #5  0xf7eeb299 in __stack_chk_fail () from /lib/libc.so.6
    #6  0x0805c501 in syscall_supported_by_kernel (sysnr=403) at tst_clocks.c:27
    #7  0x0805c80d in tst_clock_gettime (clk_id=1, ts=0x807cfb0 <tst_start_time>) at tst_clocks.c:66
    #8  0x080531df in heartbeat () at tst_test.c:1374
    #9  0x08053ba2 in testrun () at tst_test.c:1458
    #10 fork_testrun () at tst_test.c:1608
    #11 0x08055afa in tst_run_tcases (argc=<optimized out>, argv=<optimized out>, self=<optimized out>) at tst_test.c:1704
    #12 0x0804b3f0 in main (argc=1, argv=0xffffc414) at ../../../../include/tst_test.h:401
    (gdb) Test timeouted, sending SIGKILL!
    Test timeouted, sending SIGKILL!

Fixes: 63e8c1eba ("tst_clocks: Fix unaddressable byte warning")
Reported-by: Petr Cervinka <pcervinka@suse.com>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 lib/tst_clocks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
index 2144a6ae5..29f4b420c 100644
--- a/lib/tst_clocks.c
+++ b/lib/tst_clocks.c
@@ -17,7 +17,7 @@ typedef int (*mysyscall)(clockid_t clk_id, void *ts);
 int syscall_supported_by_kernel(long sysnr)
 {
 	int ret;
-	struct timespec foo;
+	struct __kernel_timespec foo;
 
 	ret = syscall(sysnr, 0, &foo);
 	if (ret == -1 && errno == ENOSYS)
-- 
2.42.0



More information about the ltp mailing list