From: Paul Floyd Date: Mon, 8 Sep 2025 05:31:02 +0000 (+0200) Subject: Bug 509258 - FreeBSD: add jail_attach_jd and jail_remove_jd syscall wrappers X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4cfbb3aaa6db1a4d5ee4c9c5d61ed94315570f8c;p=thirdparty%2Fvalgrind.git Bug 509258 - FreeBSD: add jail_attach_jd and jail_remove_jd syscall wrappers --- diff --git a/NEWS b/NEWS index 85b7a17b1..0158a23af 100644 --- a/NEWS +++ b/NEWS @@ -97,6 +97,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 509103 Fix tests/arm64/bug484935.c build with "-O2 -flto -ffat-lto-objects" 509107 memcheck/tests/duplicate_align_size_errors.cpp fails 509139 Update BadSize error messages +509258 FreeBSD: add jail_attach_jd and jail_remove_jd syscall 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 b30cce4e8..8ac3b8e92 100644 --- a/coregrind/m_syswrap/priv_syswrap-freebsd.h +++ b/coregrind/m_syswrap/priv_syswrap-freebsd.h @@ -550,6 +550,9 @@ DECL_TEMPLATE(freebsd, sys_inotify_rm_watch) // 594 // generic getgroups 595 // generic setgroups 596 +DECL_TEMPLATE(freebsd, sys_jail_attach_jd) // 597 +DECL_TEMPLATE(freebsd, sys_jail_remove_jd) // 598 + 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 ef4712391..eb8a16058 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -7148,7 +7148,7 @@ PRE(sys_fchroot) SET_STATUS_Failure(VKI_EBADF); } -// SYS_setcred +// SYS_setcred 591 // int setcred(u_int flags, const struct setcred *wcred, size_t size); PRE(sys_setcred) { @@ -7157,7 +7157,7 @@ PRE(sys_setcred) PRE_MEM_READ("setcred(wcred)", ARG2, sizeof(struct vki_setcred)); } -// SYS_exterrctl +// SYS_exterrctl 592 // int exterrctl(u_int op, u_int flags, _In_reads_bytes_(4) void *ptr PRE(sys_exterrctl) { @@ -7170,7 +7170,7 @@ PRE(sys_exterrctl) PRE_MEM_READ("exterrctl(ptr)", ARG3, 4); } -// SYS_inotify_add_watch_at +// SYS_inotify_add_watch_at 593 // int inotify_add_watch_at(int fd, int dfd, _In_z_ const char *path, uint32_t mask); PRE(sys_inotify_add_watch_at) { @@ -7180,12 +7180,12 @@ PRE(sys_inotify_add_watch_at) ML_(fd_at_check_allowed)(SARG1, (const HChar*)ARG2, "inotify_add_watch_at", tid, status); } -// SYS_inotify_rm_watch +// SYS_inotify_rm_watch 594 // 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); + PRE_REG_READ2(int, "inotify_rm_watch", int, fd, int, wd); if (!ML_(fd_allowed)(ARG1, "inotify_rm_watch", tid, False)) { SET_STATUS_Failure( VKI_EBADF ); } @@ -7195,6 +7195,34 @@ PRE(sys_inotify_rm_watch) } } +// __NR_setgroups 595 +// generic + +// __NR_getgroups 596 +// generic + +// __NR_jail_attach_jd 597 +// int jail_attach_jd(int fd); +PRE(sys_jail_attach_jd) +{ + PRINT("sys_jail_attach_jd(%" FMT_REGWORD"d)", SARG1); + PRE_REG_READ1(int, "jail_attach_jd", int, fd); + + if (!ML_(fd_allowed)(ARG1, "jail_attach_id", tid, False)) + SET_STATUS_Failure(VKI_EBADF); +} + +// __NR_jail_remove_jd 598 +// int jail_remove_jd(int fd); +PRE(sys_jail_remove_jd) +{ + PRINT("sys_jail_remove_jd(%" FMT_REGWORD"d)", SARG1); + PRE_REG_READ1(int, "jail_remove_jd", int, fd); + + if (!ML_(fd_allowed)(ARG1, "jail_remove_id", tid, False)) + SET_STATUS_Failure(VKI_EBADF); +} + #undef PRE #undef POST @@ -7910,6 +7938,9 @@ const SyscallTableEntry ML_(syscall_table)[] = { GENXY(__NR_getgroups, sys_getgroups), // 596 #endif + BSDX_(__NR_jail_attach_jd, sys_jail_attach_jd), // 597 + BSDX_(__NR_jail_remove_jd, sys_jail_remove_jd), // 598 + 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 1f2df9be4..8af22bde7 100644 --- a/include/vki/vki-scnums-freebsd.h +++ b/include/vki/vki-scnums-freebsd.h @@ -650,6 +650,9 @@ #define __NR_setgroups 596 #endif +#define __NR_jail_attach_jd 597 +#define __NR_jail_remove_jd 598 + #define __NR_fake_sigreturn 1000 #endif /* VKI_UNISTD_FREEBSD_H */