From e8a32aa888028c97ec2cf4f0e179eed2709cf7d4 Mon Sep 17 00:00:00 2001 From: Ivo Raisr Date: Tue, 25 Apr 2017 06:44:28 +0000 Subject: [PATCH] Valgrind reports INTERNAL ERROR in rt_sigsuspend syscall wrapper. Fixes BZ#379094. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16311 --- NEWS | 1 + coregrind/m_syswrap/syswrap-linux.c | 16 ++++++++++------ memcheck/tests/x86-linux/scalar.c | 4 ++-- memcheck/tests/x86-linux/scalar.stderr.exp | 15 ++++++++++++++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 24c38e03c8..ef90dbedd5 100644 --- a/NEWS +++ b/NEWS @@ -156,6 +156,7 @@ where XXXXXX is the bug number as listed below. 377930 fcntl syscall wrapper is missing flock structure check 378535 Valgrind reports INTERNAL ERROR in execve syscall wrapper 378673 Update libiberty demangler +379094 Valgrind reports INTERNAL ERROR in rt_sigsuspend syscall wrapper Release 3.12.0 (20 October 2016) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 69e4a18fd6..85a1101c56 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -3995,12 +3995,16 @@ PRE(sys_rt_sigsuspend) PRE_REG_READ2(int, "rt_sigsuspend", vki_sigset_t *, mask, vki_size_t, size) if (ARG1 != (Addr)NULL) { PRE_MEM_READ( "rt_sigsuspend(mask)", ARG1, sizeof(vki_sigset_t) ); - VG_(sigdelset)((vki_sigset_t*)ARG1, VG_SIGVGKILL); - /* We cannot mask VG_SIGVGKILL, as otherwise this thread would not - be killable by VG_(nuke_all_threads_except). - We thus silently ignore the user request to mask this signal. - Note that this is similar to what is done for e.g. - sigprocmask (see m_signals.c calculate_SKSS_from_SCSS). */ + if (ML_(safe_to_deref)((vki_sigset_t *) ARG1, sizeof(vki_sigset_t))) { + VG_(sigdelset)((vki_sigset_t *) ARG1, VG_SIGVGKILL); + /* We cannot mask VG_SIGVGKILL, as otherwise this thread would not + be killable by VG_(nuke_all_threads_except). + We thus silently ignore the user request to mask this signal. + Note that this is similar to what is done for e.g. + sigprocmask (see m_signals.c calculate_SKSS_from_SCSS). */ + } else { + SET_STATUS_Failure(VKI_EFAULT); + } } } diff --git a/memcheck/tests/x86-linux/scalar.c b/memcheck/tests/x86-linux/scalar.c index ebf21cf9f8..0468d9e8dc 100644 --- a/memcheck/tests/x86-linux/scalar.c +++ b/memcheck/tests/x86-linux/scalar.c @@ -800,8 +800,8 @@ int main(void) SY(__NR_rt_sigqueueinfo, x0, x0+1, x0); FAIL; // __NR_rt_sigsuspend 179 - GO(__NR_rt_sigsuspend, "ignore"); - // (I don't know how to test this...) + GO(__NR_rt_sigsuspend, "2s 1m"); + SY(__NR_rt_sigsuspend, x0 + 1, x0 + sizeof(sigset_t)); FAILx(EFAULT); // __NR_pread64 180 GO(__NR_pread64, "5s 1m"); diff --git a/memcheck/tests/x86-linux/scalar.stderr.exp b/memcheck/tests/x86-linux/scalar.stderr.exp index b5dd8584b7..88ddb46b17 100644 --- a/memcheck/tests/x86-linux/scalar.stderr.exp +++ b/memcheck/tests/x86-linux/scalar.stderr.exp @@ -2343,8 +2343,21 @@ Syscall param rt_sigqueueinfo(uinfo) points to unaddressable byte(s) Address 0x........ is not stack'd, malloc'd or (recently) free'd ----------------------------------------------------- -179: __NR_rt_sigsuspend ignore +179: __NR_rt_sigsuspend 2s 1m ----------------------------------------------------- +Syscall param rt_sigsuspend(mask) contains uninitialised byte(s) + ... + by 0x........: main (scalar.c:804) + +Syscall param rt_sigsuspend(size) contains uninitialised byte(s) + ... + by 0x........: main (scalar.c:804) + +Syscall param rt_sigsuspend(mask) points to unaddressable byte(s) + ... + by 0x........: main (scalar.c:804) + Address 0x........ is not stack'd, malloc'd or (recently) free'd + ----------------------------------------------------- 180: __NR_pread64 5s 1m ----------------------------------------------------- -- 2.47.2