From: Mark Wielaard Date: Tue, 21 Jun 2016 19:58:21 +0000 (+0000) Subject: Bug 364413 pselect sycallwrapper mishandles NULL sigmask. X-Git-Tag: svn/VALGRIND_3_12_0~130 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08086f08557146590f0bf3e6ac0f8d2c385c3d51;p=thirdparty%2Fvalgrind.git Bug 364413 pselect sycallwrapper mishandles NULL sigmask. Don't check or try to copy sigmask if it is NULL. The sigmask might be given in a struct, where the length is non-zero, but the signal set pointer is NULL. Testcase provided by Paul Eggert . git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15893 --- diff --git a/NEWS b/NEWS index 459ce4aaa9..bbccbee36c 100644 --- a/NEWS +++ b/NEWS @@ -107,6 +107,7 @@ where XXXXXX is the bug number as listed below. 363680 add renameat2() support 363705 arm64 missing syscall name_to_handle_at and open_by_handle_at 363714 ppc64 missing syscalls sync, waitid and name_to/open_by_handle_at +364413 pselect sycallwrapper mishandles NULL sigmask n-i-bz Fix incorrect (or infinite loop) unwind on RHEL7 x86 and amd64 n-i-bz massif --pages-as-heap=yes does not report peak caused by mmap+munmap diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 24a5ae9db6..9ace4fde7f 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -1316,11 +1316,15 @@ PRE(sys_pselect6) pas->ss.ss = (void *)1; pas->ss.ss_len = pss->ss_len; if (pss->ss_len == sizeof(*pss->ss)) { - PRE_MEM_READ("pselect6(sig->ss)", (Addr)pss->ss, pss->ss_len); - if (ML_(safe_to_deref)(pss->ss, sizeof(*pss->ss))) { - pas->adjusted_ss = *pss->ss; - pas->ss.ss = &pas->adjusted_ss; - VG_(sanitize_client_sigmask)(&pas->adjusted_ss); + if (pss->ss == NULL) { + pas->ss.ss = NULL; + } else { + PRE_MEM_READ("pselect6(sig->ss)", (Addr)pss->ss, pss->ss_len); + if (ML_(safe_to_deref)(pss->ss, sizeof(*pss->ss))) { + pas->adjusted_ss = *pss->ss; + pas->ss.ss = &pas->adjusted_ss; + VG_(sanitize_client_sigmask)(&pas->adjusted_ss); + } } } } diff --git a/none/tests/Makefile.am b/none/tests/Makefile.am index 0e11492e84..684c1afaaf 100644 --- a/none/tests/Makefile.am +++ b/none/tests/Makefile.am @@ -150,6 +150,8 @@ EXTRA_DIST = \ procfs-non-linux.stderr.exp-with-readlinkat \ procfs-non-linux.stderr.exp-without-readlinkat \ pselect_alarm.stdout.exp pselect_alarm.stderr.exp pselect_alarm.vgtest \ + pselect_signask_null.vgtest \ + pselect_sigmask_null.stdout.exp pselect_sigmask_null.stderr.exp \ pth_atfork1.stderr.exp pth_atfork1.stdout.exp pth_atfork1.vgtest \ pth_blockedsig.stderr.exp \ pth_blockedsig.stdout.exp pth_blockedsig.vgtest \ @@ -219,6 +221,7 @@ check_PROGRAMS = \ pending \ procfs-cmdline-exe \ pselect_alarm \ + pselect_sigmask_null \ pth_atfork1 pth_blockedsig pth_cancel1 pth_cancel2 pth_cvsimple \ pth_empty pth_exit pth_exit2 pth_mutexspeed pth_once pth_rwlock \ pth_stackalign \ diff --git a/none/tests/pselect_sigmask_null.c b/none/tests/pselect_sigmask_null.c new file mode 100644 index 0000000000..34bd584f92 --- /dev/null +++ b/none/tests/pselect_sigmask_null.c @@ -0,0 +1,26 @@ +/* Make sure handling of NULL sigmask is correct. + https://bugs.kde.org/show_bug.cgi?id=XXX + We might try to make a copy and adjust the mask. + Testcase provided by Paul Eggert */ + +#include +#include +#include + +int +main (void) +{ + struct timespec timeout; + timeout.tv_sec = 1; + timeout.tv_nsec = 0; + switch (pselect (0, 0, 0, 0, &timeout, 0)) + { + default: + abort (); + case -1: + perror ("pselect"); + return 1; + case 0: + return 0; + } +} diff --git a/none/tests/pselect_sigmask_null.stderr.exp b/none/tests/pselect_sigmask_null.stderr.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/none/tests/pselect_sigmask_null.stdout.exp b/none/tests/pselect_sigmask_null.stdout.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/none/tests/pselect_sigmask_null.vgtest b/none/tests/pselect_sigmask_null.vgtest new file mode 100644 index 0000000000..e59688c62d --- /dev/null +++ b/none/tests/pselect_sigmask_null.vgtest @@ -0,0 +1,2 @@ +prog: pselect_sigmask_null +vgopts: -q