]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-fdtab: Clear CLOEXEC descriptors upon execve
authorMichalis Pappas <michalis@unikraft.io>
Mon, 13 Jan 2025 14:03:08 +0000 (15:03 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Fri, 17 Jan 2025 14:59:21 +0000 (14:59 +0000)
Add an event handler for POSIX_PROCESS_EXECVE_EVENT to clear
upon execve() file descriptors with CLOEXEC set.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1386

lib/posix-fdtab/fdtab.c

index 3266c43e280dff90bd2009bcd943e9e489116e81..e942926f4ec54d4f53adef880ebe9733fc30f5cb 100644 (file)
 #include <uk/posix-fdtab-legacy.h>
 #endif /* CONFIG_LIBPOSIX_FDTAB_LEGACY_SHIM */
 
+#if CONFIG_LIBPOSIX_PROCESS_EXECVE
+#include <uk/event.h>
+#include <uk/prio.h>
+#endif /* CONFIG_LIBPOSIX_PROCESS_EXECVE */
+
 #define UK_FDTAB_SIZE CONFIG_LIBPOSIX_FDTAB_MAXFDS
 UK_CTASSERT(UK_FDTAB_SIZE <= UK_FD_MAX);
 
@@ -377,6 +382,17 @@ void uk_fdtab_cloexec(void)
        fdtab_cleanup(0);
 }
 
+static int fdtab_handle_execve(void *data __unused)
+{
+       uk_fdtab_cloexec();
+       return 0;
+}
+
+#if CONFIG_LIBPOSIX_PROCESS_EXECVE
+UK_EVENT_HANDLER_PRIO(POSIX_PROCESS_EXECVE_EVENT, fdtab_handle_execve,
+                     UK_PRIO_EARLIEST);
+#endif /* CONFIG_LIBPOSIX_PROCESS_EXECVE */
+
 /* Cleanup all leftover open fds */
 static void term_posix_fdtab(const struct uk_term_ctx *tctx __unused)
 {