From e4f4c62530d7bbdc6230caaf8d7c9f5c76676a7c Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Mon, 23 Aug 2021 19:49:48 +0200 Subject: [PATCH] Update sockopt-timestamp test Pick up the upstream commit v5.13-10-g0211fdc "tests: change sockopt-timestamp test to use syscall(__NR_recvmsg)" and augment it with an additional fix to actually tests SO_TIMESTAMP* socket options. * 0141-tests-change-sockopt-timestamp-test-to-use-syscall-_.patch: New file. * 0154-tests-call-setsockopt-directly-in-sockopt-timestamp.patch: Likewise. * strace.spec (Patch141, Patch154): New patches. (%prep): Apply them (%changelog): Mention the change. Resolves: #1996676 Signed-off-by: Eugene Syromiatnikov --- ...kopt-timestamp-test-to-use-syscall-_.patch | 378 ++++++++++++++++++ ...ckopt-timestamp-on-new-glibc-with-__.patch | 214 ---------- ...ockopt-directly-in-sockopt-timestamp.patch | 171 ++++++++ strace.spec | 10 +- 4 files changed, 558 insertions(+), 215 deletions(-) create mode 100644 0141-tests-change-sockopt-timestamp-test-to-use-syscall-_.patch delete mode 100644 0141-tests-disable-sockopt-timestamp-on-new-glibc-with-__.patch create mode 100644 0154-tests-call-setsockopt-directly-in-sockopt-timestamp.patch diff --git a/0141-tests-change-sockopt-timestamp-test-to-use-syscall-_.patch b/0141-tests-change-sockopt-timestamp-test-to-use-syscall-_.patch new file mode 100644 index 0000000..394c0e4 --- /dev/null +++ b/0141-tests-change-sockopt-timestamp-test-to-use-syscall-_.patch @@ -0,0 +1,378 @@ +From 9aada05f4c7f95220a5b16416f530419db6b4dff Mon Sep 17 00:00:00 2001 +From: "Dmitry V. Levin" +Date: Fri, 23 Jul 2021 08:00:00 +0000 +Subject: [PATCH] tests: change sockopt-timestamp test to use + syscall(__NR_recvmsg) + +Since the glibc recvmsg wrapper became unsuitable for our needs, +invoke __NR_recvmsg syscall directly. + +* tests/sockopt-timestamp.c: Include "scno.h" and , +conditionalize on __NR_recvmsg. +(TEST_OLD_SCM_TIMESTAMPS): Remove. +(k_recvmsg): New function. +(test_sockopt): Use it instead of recvmsg. +--- + tests/sockopt-timestamp.c | 72 ++++++++++++++++++++++------------------------- + 1 file changed, 34 insertions(+), 38 deletions(-) + +diff --git a/tests/sockopt-timestamp.c b/tests/sockopt-timestamp.c +index 56627bb..ed73ca1 100644 +--- a/tests/sockopt-timestamp.c ++++ b/tests/sockopt-timestamp.c +@@ -9,44 +9,45 @@ + */ + + #include "tests.h" +-#include +-#include +-#include +-#include +- +-#if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ +- || defined HAVE_STRUCT___KERNEL_TIMESPEC +-# include +-#endif ++#include "scno.h" + +-#include "kernel_timeval.h" +-#include "kernel_old_timespec.h" ++#ifdef __NR_recvmsg + +-#define XLAT_MACROS_ONLY +-# include "xlat/sock_options.h" +-#undef XLAT_MACROS_ONLY ++# include ++# include ++# include ++# include ++# include + +-#undef TEST_OLD_SCM_TIMESTAMPS ++# if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ ++ || defined HAVE_STRUCT___KERNEL_TIMESPEC ++# include ++# endif + +-/* +- * Sadly, starting with commit +- * glibc-2.33.9000-707-g13c51549e2077f2f3bf84e8fd0b46d8b0c615912, on every +- * 32-bit architecture where 32-bit time_t support is enabled, +- * glibc mangles old scm timestamps. +- */ +-#if GLIBC_PREREQ_GE(2, 33) && defined __TIMESIZE && __TIMESIZE != 64 +-# define TEST_OLD_SCM_TIMESTAMPS 0 +-#endif ++# include "kernel_timeval.h" ++# include "kernel_old_timespec.h" + +-#ifndef TEST_OLD_SCM_TIMESTAMPS +-# define TEST_OLD_SCM_TIMESTAMPS 1 +-#endif ++# define XLAT_MACROS_ONLY ++# include "xlat/sock_options.h" ++# undef XLAT_MACROS_ONLY + +-#if TEST_OLD_SCM_TIMESTAMPS \ +- || defined HAVE_STRUCT___KERNEL_TIMESPEC \ +- || defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL ++static const char *errstr; ++ ++static long ++k_recvmsg(const unsigned int fd, const void *const ptr, const unsigned int flags) ++{ ++ const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL; ++ const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL; ++ const kernel_ulong_t arg1 = fill | fd; ++ const kernel_ulong_t arg2 = (uintptr_t) ptr; ++ const kernel_ulong_t arg3 = fill | flags; ++ const long rc = syscall(__NR_recvmsg, arg1, arg2, arg3, bad, bad, bad); ++ if (rc && errno == ENOSYS) ++ perror_msg_and_skip("recvmsg"); ++ errstr = sprintrc(rc); ++ return rc; ++} + +-# if TEST_OLD_SCM_TIMESTAMPS + static void + print_timestamp_old(const struct cmsghdr *c) + { +@@ -84,7 +85,6 @@ print_timestampns_old(const struct cmsghdr *c) + printf("{tv_sec=%lld, tv_nsec=%lld}", + (long long) ts.tv_sec, (long long) ts.tv_nsec); + } +-# endif /* TEST_OLD_SCM_TIMESTAMPS */ + + # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL + static void +@@ -162,7 +162,7 @@ test_sockopt(int so_val, const char *str, void (*fun)(const struct cmsghdr *)) + .msg_controllen = sizeof(control) + }; + +- if (recvmsg(sv[0], &mh, 0) != (int) size) ++ if (k_recvmsg(sv[0], &mh, 0) != (int) size) + perror_msg_and_fail("recvmsg"); + if (close(sv[0])) + perror_msg_and_fail("close recv"); +@@ -210,10 +210,8 @@ main(void) + const char *str; + void (*fun)(const struct cmsghdr *); + } tests[] = { +-# if TEST_OLD_SCM_TIMESTAMPS + { SO_TIMESTAMP_OLD, "SO_TIMESTAMP_OLD", print_timestamp_old }, + { SO_TIMESTAMPNS_OLD, "SO_TIMESTAMPNS_OLD", print_timestampns_old }, +-# endif + # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL + { SO_TIMESTAMP_NEW, "SO_TIMESTAMP_NEW", print_timestamp_new }, + # endif +@@ -235,8 +233,6 @@ main(void) + + #else + +-SKIP_MAIN_UNDEFINED("TEST_OLD_SCM_TIMESTAMPS" +- " || HAVE_STRUCT___KERNEL_TIMESPEC" +- " || HAVE_STRUCT___KERNEL_SOCK_TIMEVAL") ++SKIP_MAIN_UNDEFINED("__NR_recvmsg") + + #endif +diff --git a/tests-m32/sockopt-timestamp.c b/tests-m32/sockopt-timestamp.c +index 56627bb..ed73ca1 100644 +--- a/tests-m32/sockopt-timestamp.c ++++ b/tests-m32/sockopt-timestamp.c +@@ -9,44 +9,45 @@ + */ + + #include "tests.h" +-#include +-#include +-#include +-#include +- +-#if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ +- || defined HAVE_STRUCT___KERNEL_TIMESPEC +-# include +-#endif ++#include "scno.h" + +-#include "kernel_timeval.h" +-#include "kernel_old_timespec.h" ++#ifdef __NR_recvmsg + +-#define XLAT_MACROS_ONLY +-# include "xlat/sock_options.h" +-#undef XLAT_MACROS_ONLY ++# include ++# include ++# include ++# include ++# include + +-#undef TEST_OLD_SCM_TIMESTAMPS ++# if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ ++ || defined HAVE_STRUCT___KERNEL_TIMESPEC ++# include ++# endif + +-/* +- * Sadly, starting with commit +- * glibc-2.33.9000-707-g13c51549e2077f2f3bf84e8fd0b46d8b0c615912, on every +- * 32-bit architecture where 32-bit time_t support is enabled, +- * glibc mangles old scm timestamps. +- */ +-#if GLIBC_PREREQ_GE(2, 33) && defined __TIMESIZE && __TIMESIZE != 64 +-# define TEST_OLD_SCM_TIMESTAMPS 0 +-#endif ++# include "kernel_timeval.h" ++# include "kernel_old_timespec.h" + +-#ifndef TEST_OLD_SCM_TIMESTAMPS +-# define TEST_OLD_SCM_TIMESTAMPS 1 +-#endif ++# define XLAT_MACROS_ONLY ++# include "xlat/sock_options.h" ++# undef XLAT_MACROS_ONLY + +-#if TEST_OLD_SCM_TIMESTAMPS \ +- || defined HAVE_STRUCT___KERNEL_TIMESPEC \ +- || defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL ++static const char *errstr; ++ ++static long ++k_recvmsg(const unsigned int fd, const void *const ptr, const unsigned int flags) ++{ ++ const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL; ++ const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL; ++ const kernel_ulong_t arg1 = fill | fd; ++ const kernel_ulong_t arg2 = (uintptr_t) ptr; ++ const kernel_ulong_t arg3 = fill | flags; ++ const long rc = syscall(__NR_recvmsg, arg1, arg2, arg3, bad, bad, bad); ++ if (rc && errno == ENOSYS) ++ perror_msg_and_skip("recvmsg"); ++ errstr = sprintrc(rc); ++ return rc; ++} + +-# if TEST_OLD_SCM_TIMESTAMPS + static void + print_timestamp_old(const struct cmsghdr *c) + { +@@ -84,7 +85,6 @@ print_timestampns_old(const struct cmsghdr *c) + printf("{tv_sec=%lld, tv_nsec=%lld}", + (long long) ts.tv_sec, (long long) ts.tv_nsec); + } +-# endif /* TEST_OLD_SCM_TIMESTAMPS */ + + # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL + static void +@@ -162,7 +162,7 @@ test_sockopt(int so_val, const char *str, void (*fun)(const struct cmsghdr *)) + .msg_controllen = sizeof(control) + }; + +- if (recvmsg(sv[0], &mh, 0) != (int) size) ++ if (k_recvmsg(sv[0], &mh, 0) != (int) size) + perror_msg_and_fail("recvmsg"); + if (close(sv[0])) + perror_msg_and_fail("close recv"); +@@ -210,10 +210,8 @@ main(void) + const char *str; + void (*fun)(const struct cmsghdr *); + } tests[] = { +-# if TEST_OLD_SCM_TIMESTAMPS + { SO_TIMESTAMP_OLD, "SO_TIMESTAMP_OLD", print_timestamp_old }, + { SO_TIMESTAMPNS_OLD, "SO_TIMESTAMPNS_OLD", print_timestampns_old }, +-# endif + # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL + { SO_TIMESTAMP_NEW, "SO_TIMESTAMP_NEW", print_timestamp_new }, + # endif +@@ -235,8 +233,6 @@ main(void) + + #else + +-SKIP_MAIN_UNDEFINED("TEST_OLD_SCM_TIMESTAMPS" +- " || HAVE_STRUCT___KERNEL_TIMESPEC" +- " || HAVE_STRUCT___KERNEL_SOCK_TIMEVAL") ++SKIP_MAIN_UNDEFINED("__NR_recvmsg") + + #endif +diff --git a/tests-mx32/sockopt-timestamp.c b/tests-mx32/sockopt-timestamp.c +index 56627bb..ed73ca1 100644 +--- a/tests-mx32/sockopt-timestamp.c ++++ b/tests-mx32/sockopt-timestamp.c +@@ -9,44 +9,45 @@ + */ + + #include "tests.h" +-#include +-#include +-#include +-#include +- +-#if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ +- || defined HAVE_STRUCT___KERNEL_TIMESPEC +-# include +-#endif ++#include "scno.h" + +-#include "kernel_timeval.h" +-#include "kernel_old_timespec.h" ++#ifdef __NR_recvmsg + +-#define XLAT_MACROS_ONLY +-# include "xlat/sock_options.h" +-#undef XLAT_MACROS_ONLY ++# include ++# include ++# include ++# include ++# include + +-#undef TEST_OLD_SCM_TIMESTAMPS ++# if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \ ++ || defined HAVE_STRUCT___KERNEL_TIMESPEC ++# include ++# endif + +-/* +- * Sadly, starting with commit +- * glibc-2.33.9000-707-g13c51549e2077f2f3bf84e8fd0b46d8b0c615912, on every +- * 32-bit architecture where 32-bit time_t support is enabled, +- * glibc mangles old scm timestamps. +- */ +-#if GLIBC_PREREQ_GE(2, 33) && defined __TIMESIZE && __TIMESIZE != 64 +-# define TEST_OLD_SCM_TIMESTAMPS 0 +-#endif ++# include "kernel_timeval.h" ++# include "kernel_old_timespec.h" + +-#ifndef TEST_OLD_SCM_TIMESTAMPS +-# define TEST_OLD_SCM_TIMESTAMPS 1 +-#endif ++# define XLAT_MACROS_ONLY ++# include "xlat/sock_options.h" ++# undef XLAT_MACROS_ONLY + +-#if TEST_OLD_SCM_TIMESTAMPS \ +- || defined HAVE_STRUCT___KERNEL_TIMESPEC \ +- || defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL ++static const char *errstr; ++ ++static long ++k_recvmsg(const unsigned int fd, const void *const ptr, const unsigned int flags) ++{ ++ const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL; ++ const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL; ++ const kernel_ulong_t arg1 = fill | fd; ++ const kernel_ulong_t arg2 = (uintptr_t) ptr; ++ const kernel_ulong_t arg3 = fill | flags; ++ const long rc = syscall(__NR_recvmsg, arg1, arg2, arg3, bad, bad, bad); ++ if (rc && errno == ENOSYS) ++ perror_msg_and_skip("recvmsg"); ++ errstr = sprintrc(rc); ++ return rc; ++} + +-# if TEST_OLD_SCM_TIMESTAMPS + static void + print_timestamp_old(const struct cmsghdr *c) + { +@@ -84,7 +85,6 @@ print_timestampns_old(const struct cmsghdr *c) + printf("{tv_sec=%lld, tv_nsec=%lld}", + (long long) ts.tv_sec, (long long) ts.tv_nsec); + } +-# endif /* TEST_OLD_SCM_TIMESTAMPS */ + + # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL + static void +@@ -162,7 +162,7 @@ test_sockopt(int so_val, const char *str, void (*fun)(const struct cmsghdr *)) + .msg_controllen = sizeof(control) + }; + +- if (recvmsg(sv[0], &mh, 0) != (int) size) ++ if (k_recvmsg(sv[0], &mh, 0) != (int) size) + perror_msg_and_fail("recvmsg"); + if (close(sv[0])) + perror_msg_and_fail("close recv"); +@@ -210,10 +210,8 @@ main(void) + const char *str; + void (*fun)(const struct cmsghdr *); + } tests[] = { +-# if TEST_OLD_SCM_TIMESTAMPS + { SO_TIMESTAMP_OLD, "SO_TIMESTAMP_OLD", print_timestamp_old }, + { SO_TIMESTAMPNS_OLD, "SO_TIMESTAMPNS_OLD", print_timestampns_old }, +-# endif + # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL + { SO_TIMESTAMP_NEW, "SO_TIMESTAMP_NEW", print_timestamp_new }, + # endif +@@ -235,8 +233,6 @@ main(void) + + #else + +-SKIP_MAIN_UNDEFINED("TEST_OLD_SCM_TIMESTAMPS" +- " || HAVE_STRUCT___KERNEL_TIMESPEC" +- " || HAVE_STRUCT___KERNEL_SOCK_TIMEVAL") ++SKIP_MAIN_UNDEFINED("__NR_recvmsg") + + #endif +-- +2.1.4 + diff --git a/0141-tests-disable-sockopt-timestamp-on-new-glibc-with-__.patch b/0141-tests-disable-sockopt-timestamp-on-new-glibc-with-__.patch deleted file mode 100644 index efc6a97..0000000 --- a/0141-tests-disable-sockopt-timestamp-on-new-glibc-with-__.patch +++ /dev/null @@ -1,214 +0,0 @@ -From c766a2cb430ae6e382855859048f4ce2055ef0a4 Mon Sep 17 00:00:00 2001 -From: Eugene Syromyatnikov -Date: Tue, 20 Jul 2021 20:29:18 +0200 -Subject: [PATCH] tests: disable sockopt-timestamp on new glibc with - __TIMESIZE!=64 altogether - ---- - tests/sockopt-timestamp.c | 23 +++++++---------------- - 1 file changed, 7 insertions(+), 16 deletions(-) - -diff --git a/tests/sockopt-timestamp.c b/tests/sockopt-timestamp.c -index 33e0c1a..50ab867 100644 ---- a/tests/sockopt-timestamp.c -+++ b/tests/sockopt-timestamp.c -@@ -26,27 +26,23 @@ - # include "xlat/sock_options.h" - #undef XLAT_MACROS_ONLY - --#undef TEST_OLD_SCM_TIMESTAMPS -+#undef TEST_SCM_TIMESTAMPS - - /* - * Sadly, starting with commit - * glibc-2.33.9000-707-g13c51549e2077f2f3bf84e8fd0b46d8b0c615912, on every - * 32-bit architecture where 32-bit time_t support is enabled, -- * glibc mangles old scm timestamps. -+ * glibc mangles scm timestamps. - */ - #if GLIBC_PREREQ_GE(2, 33) && defined __TIMESIZE && __TIMESIZE != 64 --# define TEST_OLD_SCM_TIMESTAMPS 0 -+# define TEST_SCM_TIMESTAMPS 0 - #endif - --#ifndef TEST_OLD_SCM_TIMESTAMPS --# define TEST_OLD_SCM_TIMESTAMPS 1 -+#ifndef TEST_SCM_TIMESTAMPS -+# define TEST_SCM_TIMESTAMPS 1 - #endif - --#if TEST_OLD_SCM_TIMESTAMPS \ -- || defined HAVE_STRUCT___KERNEL_TIMESPEC \ -- || defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL -- --# if TEST_OLD_SCM_TIMESTAMPS -+#if TEST_SCM_TIMESTAMPS - static void - print_timestamp_old(const struct cmsghdr *c) - { -@@ -84,7 +80,6 @@ print_timestampns_old(const struct cmsghdr *c) - printf("{tv_sec=%lld, tv_nsec=%lld}", - (long long) ts.tv_sec, (long long) ts.tv_nsec); - } --# endif /* TEST_OLD_SCM_TIMESTAMPS */ - - # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL - static void -@@ -212,10 +207,8 @@ main(void) - const char *str; - void (*fun)(const struct cmsghdr *); - } tests[] = { --# if TEST_OLD_SCM_TIMESTAMPS - { SO_TIMESTAMP_OLD, "SO_TIMESTAMP_OLD", print_timestamp_old }, - { SO_TIMESTAMPNS_OLD, "SO_TIMESTAMPNS_OLD", print_timestampns_old }, --# endif - # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL - { SO_TIMESTAMP_NEW, "SO_TIMESTAMP_NEW", print_timestamp_new }, - # endif -@@ -237,8 +230,6 @@ main(void) - - #else - --SKIP_MAIN_UNDEFINED("TEST_OLD_SCM_TIMESTAMPS" -- " || HAVE_STRUCT___KERNEL_TIMESPEC" -- " || HAVE_STRUCT___KERNEL_SOCK_TIMEVAL") -+SKIP_MAIN_UNDEFINED("TEST_SCM_TIMESTAMPS") - - #endif -diff --git a/tests-m32/sockopt-timestamp.c b/tests-m32/sockopt-timestamp.c -index 33e0c1a..50ab867 100644 ---- a/tests-m32/sockopt-timestamp.c -+++ b/tests-m32/sockopt-timestamp.c -@@ -26,27 +26,23 @@ - # include "xlat/sock_options.h" - #undef XLAT_MACROS_ONLY - --#undef TEST_OLD_SCM_TIMESTAMPS -+#undef TEST_SCM_TIMESTAMPS - - /* - * Sadly, starting with commit - * glibc-2.33.9000-707-g13c51549e2077f2f3bf84e8fd0b46d8b0c615912, on every - * 32-bit architecture where 32-bit time_t support is enabled, -- * glibc mangles old scm timestamps. -+ * glibc mangles scm timestamps. - */ - #if GLIBC_PREREQ_GE(2, 33) && defined __TIMESIZE && __TIMESIZE != 64 --# define TEST_OLD_SCM_TIMESTAMPS 0 -+# define TEST_SCM_TIMESTAMPS 0 - #endif - --#ifndef TEST_OLD_SCM_TIMESTAMPS --# define TEST_OLD_SCM_TIMESTAMPS 1 -+#ifndef TEST_SCM_TIMESTAMPS -+# define TEST_SCM_TIMESTAMPS 1 - #endif - --#if TEST_OLD_SCM_TIMESTAMPS \ -- || defined HAVE_STRUCT___KERNEL_TIMESPEC \ -- || defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL -- --# if TEST_OLD_SCM_TIMESTAMPS -+#if TEST_SCM_TIMESTAMPS - static void - print_timestamp_old(const struct cmsghdr *c) - { -@@ -84,7 +80,6 @@ print_timestampns_old(const struct cmsghdr *c) - printf("{tv_sec=%lld, tv_nsec=%lld}", - (long long) ts.tv_sec, (long long) ts.tv_nsec); - } --# endif /* TEST_OLD_SCM_TIMESTAMPS */ - - # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL - static void -@@ -212,10 +207,8 @@ main(void) - const char *str; - void (*fun)(const struct cmsghdr *); - } tests[] = { --# if TEST_OLD_SCM_TIMESTAMPS - { SO_TIMESTAMP_OLD, "SO_TIMESTAMP_OLD", print_timestamp_old }, - { SO_TIMESTAMPNS_OLD, "SO_TIMESTAMPNS_OLD", print_timestampns_old }, --# endif - # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL - { SO_TIMESTAMP_NEW, "SO_TIMESTAMP_NEW", print_timestamp_new }, - # endif -@@ -237,8 +230,6 @@ main(void) - - #else - --SKIP_MAIN_UNDEFINED("TEST_OLD_SCM_TIMESTAMPS" -- " || HAVE_STRUCT___KERNEL_TIMESPEC" -- " || HAVE_STRUCT___KERNEL_SOCK_TIMEVAL") -+SKIP_MAIN_UNDEFINED("TEST_SCM_TIMESTAMPS") - - #endif -diff --git a/tests-mx32/sockopt-timestamp.c b/tests-mx32/sockopt-timestamp.c -index 33e0c1a..50ab867 100644 ---- a/tests-mx32/sockopt-timestamp.c -+++ b/tests-mx32/sockopt-timestamp.c -@@ -26,27 +26,23 @@ - # include "xlat/sock_options.h" - #undef XLAT_MACROS_ONLY - --#undef TEST_OLD_SCM_TIMESTAMPS -+#undef TEST_SCM_TIMESTAMPS - - /* - * Sadly, starting with commit - * glibc-2.33.9000-707-g13c51549e2077f2f3bf84e8fd0b46d8b0c615912, on every - * 32-bit architecture where 32-bit time_t support is enabled, -- * glibc mangles old scm timestamps. -+ * glibc mangles scm timestamps. - */ - #if GLIBC_PREREQ_GE(2, 33) && defined __TIMESIZE && __TIMESIZE != 64 --# define TEST_OLD_SCM_TIMESTAMPS 0 -+# define TEST_SCM_TIMESTAMPS 0 - #endif - --#ifndef TEST_OLD_SCM_TIMESTAMPS --# define TEST_OLD_SCM_TIMESTAMPS 1 -+#ifndef TEST_SCM_TIMESTAMPS -+# define TEST_SCM_TIMESTAMPS 1 - #endif - --#if TEST_OLD_SCM_TIMESTAMPS \ -- || defined HAVE_STRUCT___KERNEL_TIMESPEC \ -- || defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL -- --# if TEST_OLD_SCM_TIMESTAMPS -+#if TEST_SCM_TIMESTAMPS - static void - print_timestamp_old(const struct cmsghdr *c) - { -@@ -84,7 +80,6 @@ print_timestampns_old(const struct cmsghdr *c) - printf("{tv_sec=%lld, tv_nsec=%lld}", - (long long) ts.tv_sec, (long long) ts.tv_nsec); - } --# endif /* TEST_OLD_SCM_TIMESTAMPS */ - - # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL - static void -@@ -212,10 +207,8 @@ main(void) - const char *str; - void (*fun)(const struct cmsghdr *); - } tests[] = { --# if TEST_OLD_SCM_TIMESTAMPS - { SO_TIMESTAMP_OLD, "SO_TIMESTAMP_OLD", print_timestamp_old }, - { SO_TIMESTAMPNS_OLD, "SO_TIMESTAMPNS_OLD", print_timestampns_old }, --# endif - # ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL - { SO_TIMESTAMP_NEW, "SO_TIMESTAMP_NEW", print_timestamp_new }, - # endif -@@ -237,8 +230,6 @@ main(void) - - #else - --SKIP_MAIN_UNDEFINED("TEST_OLD_SCM_TIMESTAMPS" -- " || HAVE_STRUCT___KERNEL_TIMESPEC" -- " || HAVE_STRUCT___KERNEL_SOCK_TIMEVAL") -+SKIP_MAIN_UNDEFINED("TEST_SCM_TIMESTAMPS") - - #endif --- -2.1.4 - diff --git a/0154-tests-call-setsockopt-directly-in-sockopt-timestamp.patch b/0154-tests-call-setsockopt-directly-in-sockopt-timestamp.patch new file mode 100644 index 0000000..8e019c1 --- /dev/null +++ b/0154-tests-call-setsockopt-directly-in-sockopt-timestamp.patch @@ -0,0 +1,171 @@ +From 719ccf8f4bf4263b02c686f16f579fd6119bb52c Mon Sep 17 00:00:00 2001 +From: Eugene Syromyatnikov +Date: Mon, 23 Aug 2021 18:24:39 +0200 +Subject: [PATCH] tests: call setsockopt directly in sockopt-timestamp + +While commit v5.13-10-g0211fdc "tests: change sockopt-timestamp test to +use syscall(__NR_recvmsg)" has fixed issues with glibc-induced mangling +on newer kernels, the combination of an older kernel and new glibc still +causes issues, as glibc silently falls back to SO_TIMESTAMP{,NS}_OLD, as +implemented in glibc-2.34~294 "linux: Add fallback for 64-bit time_t +SO_TIMESTAMP{NS}". Avoid that by calling setsockopt directly as well. + +* tests/sockopt-timestamp.c (SC_setsockopt): New macro constant. +(k_setsockopt): New function. +(test_sockopt): Call k_setsockopt instead of setsockopt. + +Complements: v5.13-10-g0211fdc "tests: change sockopt-timestamp test to use syscall(__NR_recvmsg)" +--- + tests/sockopt-timestamp.c | 31 ++++++++++++++++++++++++++++++- + 1 file changed, 30 insertions(+), 1 deletion(-) + +diff --git a/tests/sockopt-timestamp.c b/tests/sockopt-timestamp.c +index 34c4d89..4bd96fd 100644 +--- a/tests/sockopt-timestamp.c ++++ b/tests/sockopt-timestamp.c +@@ -48,6 +48,30 @@ k_recvmsg(const unsigned int fd, const void *const ptr, const unsigned int flags + return rc; + } + ++#define SC_setsockopt 14 ++static long ++k_setsockopt(const unsigned int fd, const unsigned int level, ++ const unsigned int optname, const void *const optval, ++ const unsigned int len) ++{ ++ const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL; ++#ifdef __NR_setsockopt ++ const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL; ++#endif ++ ++ return syscall( ++#ifdef __NR_setsockopt ++ __NR_setsockopt, ++#else /* socketcall */ ++ __NR_socketcall, SC_setsockopt, ++#endif ++ fill | fd , fill | level, fill | optname, optval, fill | len ++#ifdef __NR_setsockopt ++ , bad ++#endif ++ ); ++} ++ + static void + print_timestamp_old(const struct cmsghdr *c) + { +@@ -139,7 +163,12 @@ test_sockopt(int so_val, const char *str, void (*fun)(const struct cmsghdr *)) + perror_msg_and_skip(data); + + const int opt_1 = 1; +- if (setsockopt(sv[0], SOL_SOCKET, so_val, &opt_1, sizeof(opt_1))) { ++ /* ++ * glibc-2.34~294 adds fallsback for SO_TIMESTAMP{,NS}_NEW that calls ++ * SO_TIMESTAMP{,NS}_OLD, so we have to call the setsockopt directly ++ * in order to avoid unexpected recvmsg msg types. ++ */ ++ if (k_setsockopt(sv[0], SOL_SOCKET, so_val, &opt_1, sizeof(opt_1))) { + perror(str); + return 0; + } +diff --git a/tests-m32/sockopt-timestamp.c b/tests-m32/sockopt-timestamp.c +index 34c4d89..4bd96fd 100644 +--- a/tests-m32/sockopt-timestamp.c ++++ b/tests-m32/sockopt-timestamp.c +@@ -48,6 +48,30 @@ k_recvmsg(const unsigned int fd, const void *const ptr, const unsigned int flags + return rc; + } + ++#define SC_setsockopt 14 ++static long ++k_setsockopt(const unsigned int fd, const unsigned int level, ++ const unsigned int optname, const void *const optval, ++ const unsigned int len) ++{ ++ const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL; ++#ifdef __NR_setsockopt ++ const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL; ++#endif ++ ++ return syscall( ++#ifdef __NR_setsockopt ++ __NR_setsockopt, ++#else /* socketcall */ ++ __NR_socketcall, SC_setsockopt, ++#endif ++ fill | fd , fill | level, fill | optname, optval, fill | len ++#ifdef __NR_setsockopt ++ , bad ++#endif ++ ); ++} ++ + static void + print_timestamp_old(const struct cmsghdr *c) + { +@@ -139,7 +163,12 @@ test_sockopt(int so_val, const char *str, void (*fun)(const struct cmsghdr *)) + perror_msg_and_skip(data); + + const int opt_1 = 1; +- if (setsockopt(sv[0], SOL_SOCKET, so_val, &opt_1, sizeof(opt_1))) { ++ /* ++ * glibc-2.34~294 adds fallsback for SO_TIMESTAMP{,NS}_NEW that calls ++ * SO_TIMESTAMP{,NS}_OLD, so we have to call the setsockopt directly ++ * in order to avoid unexpected recvmsg msg types. ++ */ ++ if (k_setsockopt(sv[0], SOL_SOCKET, so_val, &opt_1, sizeof(opt_1))) { + perror(str); + return 0; + } +diff --git a/tests-mx32/sockopt-timestamp.c b/tests-mx32/sockopt-timestamp.c +index 34c4d89..4bd96fd 100644 +--- a/tests-mx32/sockopt-timestamp.c ++++ b/tests-mx32/sockopt-timestamp.c +@@ -48,6 +48,30 @@ k_recvmsg(const unsigned int fd, const void *const ptr, const unsigned int flags + return rc; + } + ++#define SC_setsockopt 14 ++static long ++k_setsockopt(const unsigned int fd, const unsigned int level, ++ const unsigned int optname, const void *const optval, ++ const unsigned int len) ++{ ++ const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL; ++#ifdef __NR_setsockopt ++ const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL; ++#endif ++ ++ return syscall( ++#ifdef __NR_setsockopt ++ __NR_setsockopt, ++#else /* socketcall */ ++ __NR_socketcall, SC_setsockopt, ++#endif ++ fill | fd , fill | level, fill | optname, optval, fill | len ++#ifdef __NR_setsockopt ++ , bad ++#endif ++ ); ++} ++ + static void + print_timestamp_old(const struct cmsghdr *c) + { +@@ -139,7 +163,12 @@ test_sockopt(int so_val, const char *str, void (*fun)(const struct cmsghdr *)) + perror_msg_and_skip(data); + + const int opt_1 = 1; +- if (setsockopt(sv[0], SOL_SOCKET, so_val, &opt_1, sizeof(opt_1))) { ++ /* ++ * glibc-2.34~294 adds fallsback for SO_TIMESTAMP{,NS}_NEW that calls ++ * SO_TIMESTAMP{,NS}_OLD, so we have to call the setsockopt directly ++ * in order to avoid unexpected recvmsg msg types. ++ */ ++ if (k_setsockopt(sv[0], SOL_SOCKET, so_val, &opt_1, sizeof(opt_1))) { + perror(str); + return 0; + } +-- +2.1.4 + diff --git a/strace.spec b/strace.spec index 96961a7..4049078 100644 --- a/strace.spec +++ b/strace.spec @@ -42,7 +42,8 @@ BuildRequires: pkgconfig(bluez) %{?!buildroot:BuildRoot: %_tmppath/buildroot-%name-%version-%release} %define maybe_use_defattr %{?suse_version:%%defattr(-,root,root)} -Patch141: 0141-tests-disable-sockopt-timestamp-on-new-glibc-with-__.patch +# v5.13-10-g0211fdc "tests: change sockopt-timestamp test to use syscall(__NR_recvmsg)" +Patch141: 0141-tests-change-sockopt-timestamp-test-to-use-syscall-_.patch # v5.13-55-g6b2191f "filter_qualify: free allocated data on the error path exit of parse_poke_token" Patch150: 0150-filter_qualify-free-allocated-data-on-the-error-path.patch # v5.13-56-g80dc60c "macros: expand BIT macros, add MASK macros; add *_SAFE macros" @@ -51,6 +52,7 @@ Patch151: 0151-macros-expand-BIT-macros-add-MASK-macros-add-_SAFE-m.patch Patch152: 0152-trie-use-BIT-and-MASK-macros.patch # v5.13-65-g41b753e "tee: rewrite num_params access in tee_fetch_buf_data" Patch153: 0153-tee-rewrite-num_params-access-in-tee_fetch_buf_data.patch +Patch154: 0154-tests-call-setsockopt-directly-in-sockopt-timestamp.patch # Fallback definitions for make_build/make_install macros %{?!__make: %global __make %_bindir/make} @@ -76,6 +78,7 @@ received by a process. %patch151 -p1 %patch152 -p1 %patch153 -p1 +%patch154 -p1 echo -n %version-%release > .tarball-version echo -n 2021 > .year @@ -125,6 +128,11 @@ echo 'END OF TEST SUITE INFORMATION' %changelog * Mon Aug 23 2021 Eugene Syromiatnikov - 5.13-3 - Address some issues reported by covscan (#1996691). +- Replace 0141-tests-disable-sockopt-timestamp-on-new-glibc-with-__.patch + with upstream v5.13-10-g0211fdc "tests: change sockopt-timestamp test + to use syscall(__NR_recvmsg)" + and 0154-tests-call-setsockopt-directly-in-sockopt-timestamp.patch. + * Tue Aug 10 2021 Mohan Boddu - 5.13-2 - Rebuilt for IMA sigs, glibc 2.34, aarch64 flags Related: rhbz#1991688