From 1aea2b98d82d95ae2d1465a19fa0c2b79e3ee62b Mon Sep 17 00:00:00 2001 From: Dmitry Safonov Date: Fri, 20 Jan 2017 18:49:00 +0300 Subject: [PATCH] zdtm/sigpending/32: check only 12 bytes of _si_fields The kernel does touch only relevant union member on x86_32. travis-ci: success for zdtm/sigpending/32: check only 12 bytes of _si_fields Cc: Andrei Vagin Signed-off-by: Dmitry Safonov Signed-off-by: Pavel Emelyanov Signed-off-by: Andrei Vagin --- test/zdtm/static/sigpending.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/test/zdtm/static/sigpending.c b/test/zdtm/static/sigpending.c index d1dbd251d..70c2580a1 100644 --- a/test/zdtm/static/sigpending.c +++ b/test/zdtm/static/sigpending.c @@ -29,6 +29,26 @@ static int thread_nr; # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #endif +#ifdef __i386__ +/* + * On x86_32 kernel puts only relevant union member when signal arrives, + * leaving _si_fields to be filled with junk from stack. Check only + * first 12 bytes: + * // POSIX.1b signals. + * struct + * { + * __pid_t si_pid; // Sending process ID. + * __uid_t si_uid; // Real user ID of sending process. + * sigval_t si_sigval; // Signal value. + * } _rt; + * Look at __copy_siginfo_to_user32() for more information. + */ +# define _si_fields_sz 12 +#else +# define _si_fields_sz (sizeof(siginfo_t) - offsetof(siginfo_t, _sifields)) +#endif +#define siginfo_filled (offsetof(siginfo_t, _sifields) + _si_fields_sz) + static pthread_mutex_t exit_lock; static pthread_mutex_t init_lock; @@ -71,13 +91,12 @@ static void sig_handler(int signal, siginfo_t *info, void *data) } crc = ~0; - if (datachk((uint8_t *) &info->_sifields, - sizeof(siginfo_t) - offsetof(siginfo_t, _sifields), &crc)) { + if (datachk((uint8_t *) &info->_sifields, _si_fields_sz, &crc)) { fail("CRC mismatch\n"); return; } - if (memcmp(info, src, sizeof(siginfo_t))) { + if (memcmp(info, src, siginfo_filled)) { fail("Source and received info are differ\n"); return; } @@ -154,8 +173,7 @@ int send_siginfo(int signo, pid_t pid, pid_t tid, int group, siginfo_t *info) info->si_code = si_code; si_code--; info->si_signo = signo; - datagen((uint8_t *) &info->_sifields, - sizeof(siginfo_t) - offsetof(siginfo_t, _sifields), &crc); + datagen((uint8_t *) &info->_sifields, _si_fields_sz, &crc); sent_sigs++;