From: Paul Floyd Date: Sat, 12 Jul 2025 20:23:05 +0000 (+0200) Subject: Bug 506499 - Unhandled syscall 592 (exterrctl - FreeBSD) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=thirdparty%2Fvalgrind.git Bug 506499 - Unhandled syscall 592 (exterrctl - FreeBSD) Also add wrapers for inotify_add_watch_at and inotify_rm_watch No specific tests for these yet. --- diff --git a/NEWS b/NEWS index ce162cb18..73488cbc1 100644 --- a/NEWS +++ b/NEWS @@ -52,6 +52,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. AMD64_GET_TLSBASE 505228 Wrap linux specific mseal syscall 502968 Wrap linux specific syscalls 457 (listmount) and 458 (statmount) +506499 Unhandled syscall 592 (exterrctl - FreeBSD 506795 Better report which clone flags are problematic To see details of a given bug, visit diff --git a/coregrind/m_syswrap/priv_syswrap-freebsd.h b/coregrind/m_syswrap/priv_syswrap-freebsd.h index f8d404239..f16831933 100644 --- a/coregrind/m_syswrap/priv_syswrap-freebsd.h +++ b/coregrind/m_syswrap/priv_syswrap-freebsd.h @@ -543,6 +543,10 @@ DECL_TEMPLATE(freebsd, sys_getrlimitusage) // 589 DECL_TEMPLATE(freebsd, sys_fchroot) // 590 DECL_TEMPLATE(freebsd, sys_setcred) // 591 +DECL_TEMPLATE(freebsd, sys_exterrctl) // 592 +DECL_TEMPLATE(freebsd, sys_inotify_add_watch_at) // 593 +DECL_TEMPLATE(freebsd, sys_inotify_rm_watch) // 594 + DECL_TEMPLATE(freebsd, sys_fake_sigreturn) #endif // PRIV_SYSWRAP_FREEBSD_H diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index 4ce860976..79e30f7d3 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -4864,8 +4864,8 @@ PRE(sys_kmq_notify) // int kmq_unlink(const char *path); PRE(sys_kmq_unlink) { - PRINT("sys_kmq_unlink ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1); - PRE_REG_READ1(int, "mq_unlink", const char *, name); + PRINT("sys_kmq_unlink ( %#" FMT_REGWORD "x(%s) )", ARG1,(HChar *)ARG1); + PRE_REG_READ1(int, "mq_unlink", const HChar *, name); PRE_MEM_RASCIIZ( "mq_unlink(name)", ARG1 ); } @@ -7054,7 +7054,7 @@ POST(sys_getrlimitusage) // int fchroot(int fd); PRE(sys_fchroot) { - PRINT("sys_fchroot(%ld)", ARG1); + PRINT("sys_fchroot(%" FMT_REGWORD "d)", ARG1); PRE_REG_READ1(int, "fchroot", int, fd); /* Be strict. */ @@ -7066,11 +7066,55 @@ PRE(sys_fchroot) // int setcred(u_int flags, const struct setcred *wcred, size_t size); PRE(sys_setcred) { - PRINT("sys_setcred(%ld, %#" FMT_REGWORD "x, %lu)", ARG1, ARG2, ARG3); + PRINT("sys_setcred(%" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u)", ARG1, ARG2, ARG3); PRE_REG_READ3(int, "setcred", u_int, flags, const struct setcred*, wcred, size_t, size); PRE_MEM_READ("setcred(wcred)", ARG2, sizeof(struct vki_setcred)); } +// SYS_exterrctl +// int exterrctl(u_int op, u_int flags, _In_reads_bytes_(4) void *ptr +PRE(sys_exterrctl) +{ + PRINT("sys_exterrctl(%" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x)", + ARG1, ARG2, ARG3); + PRE_REG_READ3(int, "exterrctl", u_int, op, u_int, flags, void*, ptr); + // the void* points to struct uexterror which at the time of writing has 10 fields + // but this syscall just turns this feature on and off and it's only th first 4 bytes + // for the version that gets checked + PRE_MEM_READ("exterrctl(ptr)", ARG3, 4); +} + +// SYS_inotify_add_watch_at +// int inotify_add_watch_at(int fd, int dfd, _In_z_ const char *path, uint32_t mask); +PRE(sys_inotify_add_watch_at) +{ + PRINT("sys_inotify_add_watch_at(%" FMT_REGWORD "d, %" FMT_REGWORD "d, %" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x)", SARG1, SARG2, ARG3, (HChar*)ARG3, ARG4); + PRE_REG_READ4(int, "inotify_add_watch_at", int, fd, int, dfd, const char*, path, uint32_t, mask); + PRE_MEM_RASCIIZ("inotify_add_watch_at(path)", ARG3); + if (!ML_(fd_allowed)(ARG1, "inotify_add_watch_at", tid, False)) { + SET_STATUS_Failure( VKI_EBADF ); + } + if (ARG2 != VKI_AT_FDCWD) { + if (!ML_(fd_allowed)(ARG2, "inotify_add_watch_at", tid, False)) { + SET_STATUS_Failure( VKI_EBADF ); + } + } +} + +// SYS_inotify_rm_watch +// int inotify_rm_watch(int fd, int wd); +PRE(sys_inotify_rm_watch) +{ + PRINT("sys_inotify_rm_watch(%" FMT_REGWORD "d, %" FMT_REGWORD "d)", SARG1, SARG2); + PRE_REG_READ2(int, "sys_inotify_rm_watch", int, fd, int, wd); + if (!ML_(fd_allowed)(ARG1, "inotify_rm_watch", tid, False)) { + SET_STATUS_Failure( VKI_EBADF ); + } + // PJF I don't think that this can be AT_FDCWD + if (!ML_(fd_allowed)(ARG2, "inotify_rm_watch", tid, False)) { + SET_STATUS_Failure( VKI_EBADF ); + } +} #undef PRE #undef POST @@ -7768,6 +7812,10 @@ const SyscallTableEntry ML_(syscall_table)[] = { BSDX_(__NR_fchroot, sys_fchroot), // 590 BSDX_(__NR_setcred, sys_setcred), // 591 + BSDX_(__NR_exterrctl, sys_exterrctl), // 592 + BSDX_(__NR_inotify_add_watch_at, sys_inotify_add_watch_at), // 593 + BSDX_(__NR_inotify_rm_watch, sys_inotify_rm_watch), // 593 + BSDX_(__NR_fake_sigreturn, sys_fake_sigreturn), // 1000, fake sigreturn }; diff --git a/include/vki/vki-scnums-freebsd.h b/include/vki/vki-scnums-freebsd.h index a92abb9a1..a15140285 100644 --- a/include/vki/vki-scnums-freebsd.h +++ b/include/vki/vki-scnums-freebsd.h @@ -630,6 +630,10 @@ #define __NR_fchroot 590 #define __NR_setcred 591 +#define __NR_exterrctl 592 +#define __NR_inotify_add_watch_at 593 +#define __NR_inotify_rm_watch 594 + #define __NR_fake_sigreturn 1000 #endif /* VKI_UNISTD_FREEBSD_H */ diff --git a/memcheck/tests/freebsd/scalar.c b/memcheck/tests/freebsd/scalar.c index bae3d943b..ce76ffdb2 100644 --- a/memcheck/tests/freebsd/scalar.c +++ b/memcheck/tests/freebsd/scalar.c @@ -2479,6 +2479,59 @@ int main(void) FAKE_SY("\n"); #endif +#if defined(SYS_exterrctl) + GO(SYS_exterrctl, "3s, 1m"); + SY(SYS_exterrctl, x0, x0+1, x0+1); +#else + FAKE_GO("592: SYS_exterrctl 3s, 1m"); + FAKE_SY("Syscall param exterrctl(op) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param exterrctl(flags) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param exterrctl(ptr) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param exterrctl(ptr) points to unaddressable byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\ Address 0x........ is not stack'd, malloc'd or (recently) free'd\n"); + FAKE_SY("\n"); +#endif + +#if defined(SYS_inotify_add_watch_at) + GO(SYS_inotify_add_watch_at, "3s, 1m"); + SY(SYS_inotify_add_watch_at, x0, x0+1, x0+1); +#else + FAKE_GO("593:SYS_inotify_add_watch_at 3s, 1m"); + FAKE_SY("Syscall param inotify_add_watch_at(fd) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param inotify_add_watch_at(dfd) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param inotify_add_watch_at(path) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param inotify_add_watch_at(path) points to unaddressable byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY(" Address 0x........ is not stack'd, malloc'd or (recently) free'd\n"); + FAKE_SY("\n"); +#endif + +#if defined(SYS_inotify_rm_watch) + GO(SYS_inotify_rm_watch, "2s, 0m"); + SY(SYS_inotify_rm_watch, x0+1000, x0+1000); +#else + FAKE_GO("594: SYS_inotify_rm_watch 2s, 0m"); + FAKE_SY("Syscall param sys_inotify_rm_watch(fd) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param sys_inotify_rm_watch(wd) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); +#endif + /* SYS_exit 1 */ GO(SYS_exit, "1s 0m"); SY(SYS_exit, x0); FAIL; diff --git a/memcheck/tests/freebsd/scalar.stderr.exp b/memcheck/tests/freebsd/scalar.stderr.exp index ae8adcd1b..dbe79c6e8 100644 --- a/memcheck/tests/freebsd/scalar.stderr.exp +++ b/memcheck/tests/freebsd/scalar.stderr.exp @@ -5746,6 +5746,47 @@ Syscall param setcred(wcred) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd +--------------------------------------------------------- +592: SYS_exterrctl 3s, 1m +--------------------------------------------------------- +Syscall param exterrctl(op) contains uninitialised byte(s) + ... + +Syscall param exterrctl(flags) contains uninitialised byte(s) + ... + +Syscall param exterrctl(ptr) contains uninitialised byte(s) + ... + +Syscall param exterrctl(ptr) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +--------------------------------------------------------- +593:SYS_inotify_add_watch_at 3s, 1m +--------------------------------------------------------- +Syscall param inotify_add_watch_at(fd) contains uninitialised byte(s) + ... + +Syscall param inotify_add_watch_at(dfd) contains uninitialised byte(s) + ... + +Syscall param inotify_add_watch_at(path) contains uninitialised byte(s) + ... + +Syscall param inotify_add_watch_at(path) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +--------------------------------------------------------- +594: SYS_inotify_rm_watch 2s, 0m +--------------------------------------------------------- +Syscall param sys_inotify_rm_watch(fd) contains uninitialised byte(s) + ... + +Syscall param sys_inotify_rm_watch(wd) contains uninitialised byte(s) + ... + --------------------------------------------------------- 1: SYS_exit 1s 0m --------------------------------------------------------- diff --git a/memcheck/tests/freebsd/scalar.stderr.exp-x86 b/memcheck/tests/freebsd/scalar.stderr.exp-x86 index 47beb3dce..ea5abb9c6 100644 --- a/memcheck/tests/freebsd/scalar.stderr.exp-x86 +++ b/memcheck/tests/freebsd/scalar.stderr.exp-x86 @@ -5818,6 +5818,47 @@ Syscall param setcred(wcred) points to unaddressable byte(s) ... Address 0x........ is not stack'd, malloc'd or (recently) free'd +--------------------------------------------------------- +592: SYS_exterrctl 3s, 1m +--------------------------------------------------------- +Syscall param exterrctl(op) contains uninitialised byte(s) + ... + +Syscall param exterrctl(flags) contains uninitialised byte(s) + ... + +Syscall param exterrctl(ptr) contains uninitialised byte(s) + ... + +Syscall param exterrctl(ptr) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +--------------------------------------------------------- +593:SYS_inotify_add_watch_at 3s, 1m +--------------------------------------------------------- +Syscall param inotify_add_watch_at(fd) contains uninitialised byte(s) + ... + +Syscall param inotify_add_watch_at(dfd) contains uninitialised byte(s) + ... + +Syscall param inotify_add_watch_at(path) contains uninitialised byte(s) + ... + +Syscall param inotify_add_watch_at(path) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +--------------------------------------------------------- +594: SYS_inotify_rm_watch 2s, 0m +--------------------------------------------------------- +Syscall param sys_inotify_rm_watch(fd) contains uninitialised byte(s) + ... + +Syscall param sys_inotify_rm_watch(wd) contains uninitialised byte(s) + ... + --------------------------------------------------------- 1: SYS_exit 1s 0m ---------------------------------------------------------