From 128017143a942263542a1d87132f3bae782ce645 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Sun, 31 Aug 2025 16:32:20 +0200 Subject: [PATCH] Bug 508958 - FreeBSD: add getgroups and setgroups wrappers --- NEWS | 1 + coregrind/m_syswrap/priv_syswrap-freebsd.h | 7 +- coregrind/m_syswrap/syswrap-freebsd.c | 23 +++++- include/vki/vki-scnums-freebsd.h | 16 ++++ memcheck/tests/freebsd/scalar.c | 83 ++++++++++++++++---- memcheck/tests/freebsd/scalar.stderr.exp | 26 ++++++ memcheck/tests/freebsd/scalar.stderr.exp-x86 | 26 ++++++ 7 files changed, 160 insertions(+), 22 deletions(-) diff --git a/NEWS b/NEWS index 8b7f688f3..2f77a2dd6 100644 --- a/NEWS +++ b/NEWS @@ -93,6 +93,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 508778 syscall-wrapper waitid warns about infop=null 508779 PRE(sys_prlimit64): reorder check for memory validity 508869 x86-linux: simplify scalar test output +508958 FreeBSD: add getgroups and setgroups wrappers To see details of a given bug, visit https://bugs.kde.org/show_bug.cgi?id=XXXXXX diff --git a/coregrind/m_syswrap/priv_syswrap-freebsd.h b/coregrind/m_syswrap/priv_syswrap-freebsd.h index f16831933..65f69e85a 100644 --- a/coregrind/m_syswrap/priv_syswrap-freebsd.h +++ b/coregrind/m_syswrap/priv_syswrap-freebsd.h @@ -107,8 +107,8 @@ DECL_TEMPLATE(freebsd, sys_sbrk) // 69 // generic mprotect 74 // generic madvise 75 // generic mincore 78 -// generic getgroups 79 -// generic setgroups 80 +// generic freebsd14_getgroups 79 +// generic freebsd14_setgroups 80 // generic getpgrp 81 // generic setpgid 82 // generic setitimer 83 @@ -547,6 +547,9 @@ DECL_TEMPLATE(freebsd, sys_exterrctl) // 592 DECL_TEMPLATE(freebsd, sys_inotify_add_watch_at) // 593 DECL_TEMPLATE(freebsd, sys_inotify_rm_watch) // 594 +// generic getgroups 595 +// generic setgroups 596 + 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 6679e58fb..bf7c96a8f 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -7304,9 +7304,17 @@ const SyscallTableEntry ML_(syscall_table)[] = { // obsol vhangup 76 // obsol vlimit 77 GENXY(__NR_mincore, sys_mincore), // 78 - GENXY(__NR_getgroups, sys_getgroups), // 79 - - GENX_(__NR_setgroups, sys_setgroups), // 80 + #if defined(__NR_freebsd14_getgroups) + GENXY(__NR_freebsd14_getgroups, sys_getgroups), // 79 + #else + GENXY(__NR_getgroups, sys_getgroups), // 79 + #endif + + #if defined(__NR_freebsd14_setgroups) + GENX_(__NR_freebsd14_setgroups, sys_setgroups), // 80 + #else + GENX_(__NR_setgroups, sys_setgroups), // 80 + #endif GENX_(__NR_getpgrp, sys_getpgrp), // 81 GENX_(__NR_setpgid, sys_setpgid), // 82 GENXY(__NR_setitimer, sys_setitimer), // 83 @@ -7891,7 +7899,14 @@ const SyscallTableEntry ML_(syscall_table)[] = { 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_inotify_rm_watch, sys_inotify_rm_watch), // 594 + +#if defined(__NR_freebsd14_setgroups) + GENX_(__NR_setgroups, sys_setgroups), // 595 +#endif +#if defined(__NR_freebsd14_getgroups) + GENXY(__NR_getgroups, sys_getgroups), // 596 +#endif 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 a15140285..50df8136a 100644 --- a/include/vki/vki-scnums-freebsd.h +++ b/include/vki/vki-scnums-freebsd.h @@ -28,6 +28,7 @@ #define VKI_UNISTD_FREEBSD_H #include "config.h" +#include // this is the syscall format used by e.g., libc functions like 'write' // this is the one used 99.999% of the time @@ -129,8 +130,16 @@ /* obs vhangup 76 */ /* obs vlimit 77 */ #define __NR_mincore 78 +#if defined(SYS_freebsd_getgroups) +#define __NR_freebsd14_getgroups 79 +#else #define __NR_getgroups 79 +#endif +#if defined(SYS_freebsd14_setgroups) +#define __NR_freebsd14_setgroups 80 +#else #define __NR_setgroups 80 +#endif #define __NR_getpgrp 81 #define __NR_setpgid 82 #define __NR_setitimer 83 @@ -634,6 +643,13 @@ #define __NR_inotify_add_watch_at 593 #define __NR_inotify_rm_watch 594 +#if defined(SYS_freebsd_getgroups) +#define __NR_getgroups 595 +#endif +#if defined(SYS_freebsd_setgroups) +#define __NR_setgroups 596 +#endif + #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 0709d1873..c3e700f27 100644 --- a/memcheck/tests/freebsd/scalar.c +++ b/memcheck/tests/freebsd/scalar.c @@ -348,13 +348,23 @@ int main(void) GO(SYS_mincore, "3s 1m"); SY(SYS_mincore, x0, x0+40960, x0); FAIL; - /* SYS_getgroups 79 */ + /* SYS_freeebsd14_getgroups 79 */ +#if defined(SYS_freebsd14_getgroups) + GO(SYS_freebsd14_getgroups, "2s 1m"); + SY(SYS_freebsd14_getgroups, x0+1, x0+1); FAIL; +#else GO(SYS_getgroups, "2s 1m"); SY(SYS_getgroups, x0+1, x0+1); FAIL; +#endif - /* SYS_setgroups 80 */ + /* SYS_freebsd14_setgroups 80 */ +#if defined(SYS_freebsd14_getgroups) + GO(SYS_freebsd14_getgroups, "2s 1m"); + SY(SYS_freebsd14_getgroups, x0+1, x0+1); FAIL; +#else GO(SYS_setgroups, "2s 1m"); SY(SYS_setgroups, x0+1, x0+1); FAIL; +#endif /* SYS_getpgrp 81 */ GO(SYS_getpgrp, "0s 0m"); @@ -2169,7 +2179,7 @@ int main(void) // __FreeBSD_version 1201522 // __FreeBSD_version 1300045 - /* SYS___sysctlbyname 570 */ + /* SYS___sysctlbyname 570 */ GO(SYS___sysctlbyname, "(getoldlen) 3s 2m"); SY(SYS___sysctlbyname, x0, x0+1, NULL, x0+1, NULL, x0); FAIL; @@ -2180,7 +2190,7 @@ int main(void) SY(SYS___sysctlbyname, x0, x0+1, NULL, NULL, x0+1, x0+2); FAIL; // FreeBSD 13 (and any backports) - /* SYS_shm_open2 571 */ + /* SYS_shm_open2 571 */ #if defined(SYS_shm_open2) GO(SYS_shm_open2, " 5s 2m"); SY(SYS_shm_open2, x0+0xf00c, x0+1, x0+2, x0+3, x0+4); FAIL; @@ -2235,7 +2245,7 @@ int main(void) FAKE_SY("\n"); #endif - /* SYS___realpathat 574 */ + /* SYS___realpathat 574 */ #if defined(SYS___realpathat) GO(SYS___realpathat, " 5s 2m"); SY(SYS___realpathat, x0+0xffff, x0, x0, x0+100, x0+2); FAIL; @@ -2266,14 +2276,14 @@ int main(void) FAKE_SY("\n"); #endif - /* SYS_close_range 575 */ + /* SYS_close_range 575 */ #if defined(SYS_close_range) GO(SYS_close_range, "3s 0m"); SY(SYS_close_range, x0+5, x0+10, x0+12345); FAIL; #else #endif - /* SYS___specialfd 577 */ + /* SYS___specialfd 577 */ #if defined(SYS___specialfd) GO(SYS___specialfd, "3s 1m"); SY(SYS___specialfd, x0+0xf000, x0+1, x0+10); FAIL; @@ -2294,7 +2304,7 @@ int main(void) FAKE_SY("\n"); #endif - /* SYS_aio_writev 578 */ + /* SYS_aio_writev 578 */ #if defined(SYS_aio_writev) GO(SYS_aio_writev, "1s 1m"); SY(SYS_aio_writev, x0+1); FAIL; @@ -2309,7 +2319,7 @@ int main(void) FAKE_SY("\n"); #endif - /* SYS_aio_readv 579 */ + /* SYS_aio_readv 579 */ #if defined(SYS_aio_readv) GO(SYS_aio_readv, "1s 1m"); SY(SYS_aio_readv, x0+1); FAIL; @@ -2325,7 +2335,7 @@ int main(void) #endif // FreeBSD 15 (and any backports) - /* SYS_kqueuex 583 */ + /* SYS_kqueuex 583 */ #if defined(SYS_kqueuex) GO(SYS_kqueuex, " 1s 0m"); SY(SYS_kqueuex, x0+123); FAIL; @@ -2336,7 +2346,7 @@ int main(void) FAKE_SY("\n"); #endif - /* SYS_membarrier 584 */ + /* SYS_membarrier 584 */ #if defined(SYS_membarrier) GO(SYS_membarrier, " 3s 0m"); SY(SYS_membarrier, x0+123, x0+456, x0+789); FAIL; @@ -2353,7 +2363,7 @@ int main(void) FAKE_SY("\n"); #endif - /* SYS_timerfd_create 585 */ + /* SYS_timerfd_create 585 */ #if defined(SYS_timerfd_create) GO(SYS_timerfd_create, " 2s 0m"); SY(SYS_timerfd_create, x0+123, x0+23456); FAIL; @@ -2367,7 +2377,7 @@ int main(void) FAKE_SY("\n"); #endif - /* SYS_timerfd_gettime 586 */ + /* SYS_timerfd_gettime 586 */ #if defined(SYS_timerfd_gettime) GO(SYS_timerfd_gettime, " 2s 1m"); SY(SYS_timerfd_gettime, x0+100, x0); FAIL; @@ -2385,7 +2395,7 @@ int main(void) FAKE_SY("\n"); #endif - /* SYS_timerfd_settime 587 */ + /* SYS_timerfd_settime 587 */ #if defined(SYS_timerfd_settime) GO(SYS_timerfd_settime, "4s 2m"); SY(SYS_timerfd_settime, x0+321, x0, x0+10, x0+5); FAIL; @@ -2413,7 +2423,7 @@ int main(void) FAKE_SY("\n"); #endif - /* SYS_kcmp 588 */ + /* SYS_kcmp 588 */ #if defined(SYS_kcmp) GO(SYS_kcmp, "5s 0m"); SY(SYS_kcmp, x0+1, x0+2, x0+3, x0+4, x0+5); @@ -2436,7 +2446,7 @@ int main(void) FAKE_SY("\n"); #endif - /* SYS_getrlimitusage 589 */ + /* SYS_getrlimitusage 589 */ #if defined(SYS_getrlimitusage) GO(SYS_getrlimitusage, "3s, 1m"); SY(SYS_getrlimitusage, x0+3, x0, x0+2); @@ -2457,6 +2467,7 @@ int main(void) FAKE_SY("\n"); #endif + /* SYS_fchroot 590 */ #if defined(SYS_fchroot) GO(SYS_fchroot, "1s, 0m"); SY(SYS_fchroot, x0+1000); @@ -2467,6 +2478,7 @@ int main(void) FAKE_SY("\n"); #endif + /* SYS_setcred 591 */ #if defined(SYS_setcred) GO(SYS_setcred, "3s, 1m"); SY(SYS_setcred, x0+100, x0+3, x0+50); @@ -2487,6 +2499,7 @@ int main(void) FAKE_SY("\n"); #endif + /* SYS_wxterrctl 592 */ #if defined(SYS_exterrctl) GO(SYS_exterrctl, "3s, 1m"); SY(SYS_exterrctl, x0, x0+1, x0+1); @@ -2507,6 +2520,7 @@ int main(void) FAKE_SY("\n"); #endif + /* SYS_inotify_add_watch_at 593 */ #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); @@ -2527,6 +2541,7 @@ int main(void) FAKE_SY("\n"); #endif + /* SYS_inotify_rm_watch 594 */ #if defined(SYS_inotify_rm_watch) GO(SYS_inotify_rm_watch, "2s, 0m"); SY(SYS_inotify_rm_watch, x0+1000, x0+1000); @@ -2540,6 +2555,42 @@ int main(void) FAKE_SY("\n"); #endif + /* SYS_getgroups 595 */ +#if defined(SYS_freebsd14_getgroups) + GO(SYS_getgroups, "2s 1m"); + SY(SYS_getgroups, x0+1, x0+1); FAIL; +#else + FAKE_GO("595: SYS_getgroups 2s 1m"); + FAKE_SY("Syscall param getgroups(size) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param getgroups(list) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param getgroups(list) 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 + + /* SYS_setgroups 596 */ +#if defined(SYS_freebsd14_getgroups) + GO(SYS_getgroups, "2s 1m"); + SY(SYS_getgroups, x0+1, x0+1); FAIL; +#else + FAKE_GO("596: SYS_setgroups 2s 1m"); + FAKE_SY("Syscall param setgroups(size) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param setgroups(list) contains uninitialised byte(s)\n"); + FAKE_SY(" ...\n"); + FAKE_SY("\n"); + FAKE_SY("Syscall param setgroups(list) 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 + /* 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 882433a92..166552caf 100644 --- a/memcheck/tests/freebsd/scalar.stderr.exp +++ b/memcheck/tests/freebsd/scalar.stderr.exp @@ -5825,6 +5825,32 @@ Syscall param sys_inotify_rm_watch(fd) contains uninitialised byte(s) Syscall param sys_inotify_rm_watch(wd) contains uninitialised byte(s) ... +--------------------------------------------------------- +595: SYS_getgroups 2s 1m +--------------------------------------------------------- +Syscall param getgroups(size) contains uninitialised byte(s) + ... + +Syscall param getgroups(list) contains uninitialised byte(s) + ... + +Syscall param getgroups(list) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +--------------------------------------------------------- +596: SYS_setgroups 2s 1m +--------------------------------------------------------- +Syscall param setgroups(size) contains uninitialised byte(s) + ... + +Syscall param setgroups(list) contains uninitialised byte(s) + ... + +Syscall param setgroups(list) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + --------------------------------------------------------- 1: SYS_exit 1s 0m --------------------------------------------------------- diff --git a/memcheck/tests/freebsd/scalar.stderr.exp-x86 b/memcheck/tests/freebsd/scalar.stderr.exp-x86 index 20d8d3ca7..52c7ce8c3 100644 --- a/memcheck/tests/freebsd/scalar.stderr.exp-x86 +++ b/memcheck/tests/freebsd/scalar.stderr.exp-x86 @@ -5897,6 +5897,32 @@ Syscall param sys_inotify_rm_watch(fd) contains uninitialised byte(s) Syscall param sys_inotify_rm_watch(wd) contains uninitialised byte(s) ... +--------------------------------------------------------- +595: SYS_getgroups 2s 1m +--------------------------------------------------------- +Syscall param getgroups(size) contains uninitialised byte(s) + ... + +Syscall param getgroups(list) contains uninitialised byte(s) + ... + +Syscall param getgroups(list) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +--------------------------------------------------------- +596: SYS_setgroups 2s 1m +--------------------------------------------------------- +Syscall param setgroups(size) contains uninitialised byte(s) + ... + +Syscall param setgroups(list) contains uninitialised byte(s) + ... + +Syscall param setgroups(list) points to unaddressable byte(s) + ... + Address 0x........ is not stack'd, malloc'd or (recently) free'd + --------------------------------------------------------- 1: SYS_exit 1s 0m --------------------------------------------------------- -- 2.47.3