From: Paul F. <pa...@so...> - 2025-04-17 19:30:18
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=b13ec72918a1e9d11827bdde5d92c97222d79ea0 commit b13ec72918a1e9d11827bdde5d92c97222d79ea0 Author: Paul Floyd <pj...@wa...> Date: Thu Apr 17 21:26:24 2025 +0200 Illumos: increase coverage of --modify-fds syscalls It looks like Solaris/Illumos is missing some F_DUP* coverage and we aren't handling syscalls that reaturn 2 fds (pipe, socketpair). Otherwise this should cover most Illumos cases at least. Diff: --- coregrind/m_syswrap/syswrap-generic.c | 1 + coregrind/m_syswrap/syswrap-solaris.c | 15 ++++++++++++++- coregrind/m_syswrap/syswrap-x86-solaris.c | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index 1ab494c840..82a682a5ce 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -1814,6 +1814,7 @@ ML_(generic_POST_sys_socketpair) ( ThreadId tid, Int fd1 = ((Int*)arg3)[0]; Int fd2 = ((Int*)arg3)[1]; vg_assert(!sr_isError(res)); /* guaranteed by caller */ + // @todo PJF this needs something like POST_newFd_RES for the two fds? POST_MEM_WRITE( arg3, 2*sizeof(int) ); if (!ML_(fd_allowed)(fd1, "socketcall.socketpair", tid, True) || !ML_(fd_allowed)(fd2, "socketcall.socketpair", tid, True)) { diff --git a/coregrind/m_syswrap/syswrap-solaris.c b/coregrind/m_syswrap/syswrap-solaris.c index 6b61a0e0dc..a5d34bc5d5 100644 --- a/coregrind/m_syswrap/syswrap-solaris.c +++ b/coregrind/m_syswrap/syswrap-solaris.c @@ -2492,6 +2492,7 @@ PRE(sys_pipe) POST(sys_pipe) { Int p0, p1; + // @todo PJF this needs something like POST_newFd_RES for the two fds? #if defined(SOLARIS_NEW_PIPE_SYSCALL) int *fds = (int*)ARG1; @@ -4074,8 +4075,11 @@ PRE(sys_fcntl) POST(sys_fcntl) { + // @todo PJF we're missing + // F_DUP2FD_CLOEXEC F_DUP2FD_CLOFORK F_DUPFD_CLOFORK F_DUP3FD switch (ARG2 /*cmd*/) { case VKI_F_DUPFD: + POST_newFd_RES; if (!ML_(fd_allowed)(RES, "fcntl(F_DUPFD)", tid, True)) { VG_(close)(RES); SET_STATUS_Failure(VKI_EMFILE); @@ -4084,6 +4088,7 @@ POST(sys_fcntl) break; case VKI_F_DUPFD_CLOEXEC: + POST_newFd_RES; if (!ML_(fd_allowed)(RES, "fcntl(F_DUPFD_CLOEXEC)", tid, True)) { VG_(close)(RES); SET_STATUS_Failure(VKI_EMFILE); @@ -4092,6 +4097,7 @@ POST(sys_fcntl) break; case VKI_F_DUP2FD: + POST_newFd_RES; if (!ML_(fd_allowed)(RES, "fcntl(F_DUP2FD)", tid, True)) { VG_(close)(RES); SET_STATUS_Failure(VKI_EMFILE); @@ -4258,6 +4264,7 @@ PRE(sys_openat) POST(sys_openat) { + POST_newFd_RES; if (!ML_(fd_allowed)(RES, "openat", tid, True)) { VG_(close)(RES); SET_STATUS_Failure(VKI_EMFILE); @@ -9555,7 +9562,13 @@ POST(sys_door) switch (ARG6 /*subcode*/) { case VKI_DOOR_CREATE: - door_record_server(tid, ARG1, RES); + POST_newFd_RES; + if (!ML_(fd_allowed)(RES, "door_create", tid, True)) { + VG_(close)(RES); + SET_STATUS_Failure( VKI_EMFILE ); + } else { + door_record_server(tid, ARG1, RES); + } break; case VKI_DOOR_REVOKE: door_record_revoke(tid, ARG1); diff --git a/coregrind/m_syswrap/syswrap-x86-solaris.c b/coregrind/m_syswrap/syswrap-x86-solaris.c index be36625112..59c36c1852 100644 --- a/coregrind/m_syswrap/syswrap-x86-solaris.c +++ b/coregrind/m_syswrap/syswrap-x86-solaris.c @@ -971,6 +971,7 @@ PRE(sys_open64) POST(sys_open64) { + POST_newFd_RES; if (!ML_(fd_allowed)(RES, "open64", tid, True)) { VG_(close)(RES); SET_STATUS_Failure(VKI_EMFILE); |