From: Paul F. <pa...@so...> - 2025-07-24 20:47:52
|
https://sourceware.org/cgit/valgrind/commit/?id=359e33acaf8cded1312e75709b91d4f8156ae574 commit 359e33acaf8cded1312e75709b91d4f8156ae574 Author: Paul Floyd <pj...@wa...> Date: Thu Jul 24 22:45:01 2025 +0200 FreeBSD syscall: improve sigwait and sigwaitinfo wrapper. Both take two pointers. We were allowing null pointers for all of them. Only the 2nd argument of sigwaitinfo, info, is allowed to be NULL. Update the scalar test with some NULL arguments for these syscalls. Diff: --- coregrind/m_syswrap/syswrap-freebsd.c | 23 ++++++++++------------- memcheck/tests/freebsd/scalar.c | 10 +++++++++- memcheck/tests/freebsd/scalar.stderr.exp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index ac371e125a..08c4ec3c3c 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -3317,9 +3317,7 @@ PRE(sys_sigwaitinfo) ARG1,ARG2); PRE_REG_READ2(int, "sigwaitinfo", const vki_sigset_t *, set, vki_siginfo_t *, info); - if (ARG1 != 0) { - PRE_MEM_READ( "sigwaitinfo(set)", ARG1, sizeof(vki_sigset_t)); - } + PRE_MEM_READ( "sigwaitinfo(set)", ARG1, sizeof(vki_sigset_t)); if (ARG2 != 0) { PRE_MEM_WRITE( "sigwaitinfo(info)", ARG2, sizeof(vki_siginfo_t) ); } @@ -4099,21 +4097,20 @@ PRE(sys_sigwait) ARG1,ARG2); PRE_REG_READ2(int, "sigwait", const vki_sigset_t *, set, int *, sig); - if (ARG1 != 0) { - PRE_MEM_READ( "sigwait(set)", ARG1, sizeof(vki_sigset_t)); - vki_sigset_t* set = (vki_sigset_t*)ARG1; - if (ML_(safe_to_deref)(set, sizeof(vki_sigset_t))) { - *flags |= SfMayBlock; - } - } - if (ARG2 != 0) { - PRE_MEM_WRITE( "sigwait(sig)", ARG2, sizeof(int)); + PRE_MEM_READ( "sigwait(set)", ARG1, sizeof(vki_sigset_t)); + vki_sigset_t* set = (vki_sigset_t*)ARG1; + if (ML_(safe_to_deref)(set, sizeof(vki_sigset_t))) { + *flags |= SfMayBlock; } + PRE_MEM_WRITE( "sigwait(sig)", ARG2, sizeof(int)); } +// sigwait doesn't follow the norm of returning -1 on error +// instead it returns errno if there is an error POST(sys_sigwait) { - if (RES == 0 && ARG2 != 0) { + if (RES == 0) + { POST_MEM_WRITE( ARG2, sizeof(int)); } } diff --git a/memcheck/tests/freebsd/scalar.c b/memcheck/tests/freebsd/scalar.c index 9c67888f98..234e649f78 100644 --- a/memcheck/tests/freebsd/scalar.c +++ b/memcheck/tests/freebsd/scalar.c @@ -1271,7 +1271,11 @@ int main(void) /* SYS_sigwaitinfo 346 */ GO(SYS_sigwaitinfo, "2s 2m"); - SY(SYS_sigwaitinfo, x0+1, x0+2, x0+3); FAIL; + SY(SYS_sigwaitinfo, x0+1, x0+2); FAIL; + + GO(SYS_sigwaitinfo, "(NULL info) 2s 1m"); + SY(SYS_sigwaitinfo, x0, x0); FAIL; + /* SYS___acl_get_file 347 */ GO(SYS___acl_get_file, "3s 2m"); @@ -1549,6 +1553,10 @@ int main(void) SY(SYS_sigwait, x0+1, x0+2); SUCC; assert(res == EFAULT); + GO(SYS_sigwait, "(NULL ags) 2s 2m"); + SY(SYS_sigwait, x0, x0); SUCC; + assert(res == EFAULT); + // thr_create 430 /* SYS_thr_exit 431 */ diff --git a/memcheck/tests/freebsd/scalar.stderr.exp b/memcheck/tests/freebsd/scalar.stderr.exp index dbe79c6e84..ae9c15f6a8 100644 --- a/memcheck/tests/freebsd/scalar.stderr.exp +++ b/memcheck/tests/freebsd/scalar.stderr.exp @@ -2509,6 +2509,19 @@ Syscall param sigwaitinfo(info) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd +--------------------------------------------------------- +346: SYS_sigwaitinfo (NULL info) 2s 1m +--------------------------------------------------------- +Syscall param sigwaitinfo(set) contains uninitialised byte(s) + ... + +Syscall param sigwaitinfo(info) contains uninitialised byte(s) + ... + +Syscall param sigwaitinfo(set) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + --------------------------------------------------------- 347: SYS___acl_get_file 3s 2m --------------------------------------------------------- @@ -3360,6 +3373,23 @@ Syscall param sigwait(sig) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd +--------------------------------------------------------- +429: SYS_sigwait (NULL ags) 2s 2m +--------------------------------------------------------- +Syscall param sigwait(set) contains uninitialised byte(s) + ... + +Syscall param sigwait(sig) contains uninitialised byte(s) + ... + +Syscall param sigwait(set) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param sigwait(sig) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + --------------------------------------------------------- 431: SYS_thr_exit other --------------------------------------------------------- |