Add a call to ML_(fd_allowed) in the PRE handler of fcntl and fcntl64
and block syscalls with EBADF when the file descriptor isn't allowed
to be used by the program.
https://bugs.kde.org/show_bug.cgi?id=337388
(cherry picked from commit
4b83e3d47daaf5eff2ca96867a8c790e13830eb5)
202770 open fd at exit --log-socket=127.0.0.1:1500 with --track-fds=yes
311655 --log-file=FILE leads to apparent fd leak
+337388 fcntl works on Valgrind's own file descriptors
453044 gbserver_tests failures in aarch64
479661 Valgrind leaks file descriptors
486180 [MIPS] 'VexGuestArchState' has no member named 'guest_IP_AT_SYSCALL'
if (ARG2 == VKI_F_SETLKW)
# endif
*flags |= SfMayBlock;
+
+ if (!ML_(fd_allowed)(ARG1, "fcntl", tid, False)) {
+ SET_STATUS_Failure (VKI_EBADF);
+ }
}
POST(sys_fcntl)
if (ARG2 == VKI_F_SETLKW)
# endif
*flags |= SfMayBlock;
+
+ if (!ML_(fd_allowed)(ARG1, "fcntl64", tid, False)) {
+ SET_STATUS_Failure (VKI_EBADF);
+ }
}
POST(sys_fcntl64)