From: Luca Boccassi Date: Thu, 26 Oct 2023 20:55:55 +0000 (+0100) Subject: core: rename and add comment to ExecParameters cleanup functions X-Git-Tag: v255-rc1~81 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fba173ff6adabb3fc19c7d115fa7916f5d09ad5c;p=thirdparty%2Fsystemd.git core: rename and add comment to ExecParameters cleanup functions --- diff --git a/src/core/execute.c b/src/core/execute.c index f220e9ee5e8..e83a2ab239f 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -2464,10 +2464,13 @@ void exec_runtime_clear(ExecRuntime *rt) { rt->ephemeral_copy = mfree(rt->ephemeral_copy); } -void exec_params_clear(ExecParameters *p) { +void exec_params_shallow_clear(ExecParameters *p) { if (!p) return; + /* This is called on the PID1 side, as many of the struct's FDs are only borrowed, and actually + * owned by the manager or other objects, and reused across multiple units. */ + p->environment = strv_free(p->environment); p->fd_names = strv_free(p->fd_names); p->files_env = strv_free(p->files_env); @@ -2481,10 +2484,14 @@ void exec_params_clear(ExecParameters *p) { p->confirm_spawn = mfree(p->confirm_spawn); } -void exec_params_serialized_done(ExecParameters *p) { +void exec_params_deep_clear(ExecParameters *p) { if (!p) return; + /* This is called on the sd-executor side, where everything received is owned by the process and has + * to be fully cleaned up to make sanitizers and analyzers happy, as opposed as the shallow clean + * function above. */ + close_many_unset(p->fds, p->n_socket_fds + p->n_storage_fds); p->cgroup_path = mfree(p->cgroup_path); @@ -2512,7 +2519,7 @@ void exec_params_serialized_done(ExecParameters *p) { p->fallback_smack_process_label = mfree(p->fallback_smack_process_label); - exec_params_clear(p); + exec_params_shallow_clear(p); } void exec_directory_done(ExecDirectory *d) { diff --git a/src/core/execute.h b/src/core/execute.h index 16295da1864..4896a424923 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -552,9 +552,9 @@ ExecRuntime* exec_runtime_destroy(ExecRuntime *rt); void exec_runtime_clear(ExecRuntime *rt); int exec_params_get_cgroup_path(const ExecParameters *params, const CGroupContext *c, char **ret); -void exec_params_clear(ExecParameters *p); +void exec_params_shallow_clear(ExecParameters *p); void exec_params_dump(const ExecParameters *p, FILE* f, const char *prefix); -void exec_params_serialized_done(ExecParameters *p); +void exec_params_deep_clear(ExecParameters *p); bool exec_context_get_cpu_affinity_from_numa(const ExecContext *c); diff --git a/src/core/executor.c b/src/core/executor.c index a7fb3112928..e19e8718162 100644 --- a/src/core/executor.c +++ b/src/core/executor.c @@ -178,7 +178,7 @@ int main(int argc, char *argv[]) { _cleanup_(cgroup_context_done) CGroupContext cgroup_context = {}; _cleanup_(exec_context_done) ExecContext context = {}; _cleanup_(exec_command_done) ExecCommand command = {}; - _cleanup_(exec_params_serialized_done) ExecParameters params = EXEC_PARAMETERS_INIT(/* flags= */ 0); + _cleanup_(exec_params_deep_clear) ExecParameters params = EXEC_PARAMETERS_INIT(/* flags= */ 0); _cleanup_(exec_shared_runtime_done) ExecSharedRuntime shared = { .netns_storage_socket = EBADF_PAIR, .ipcns_storage_socket = EBADF_PAIR, diff --git a/src/core/fuzz-execute-serialize.c b/src/core/fuzz-execute-serialize.c index d71fb487e5a..862b525974b 100644 --- a/src/core/fuzz-execute-serialize.c +++ b/src/core/fuzz-execute-serialize.c @@ -26,14 +26,7 @@ #include "service.h" static void exec_fuzz_one(FILE *f, FDSet *fdset) { - _cleanup_(exec_params_serialized_done) ExecParameters params = { - .stdin_fd = -EBADF, - .stdout_fd = -EBADF, - .stderr_fd = -EBADF, - .exec_fd = -EBADF, - .user_lookup_fd = -EBADF, - .bpf_outer_map_fd = -EBADF, - }; + _cleanup_(exec_params_deep_clear) ExecParameters params = EXEC_PARAMETERS_INIT(/* flags= */ 0); _cleanup_(exec_context_done) ExecContext exec_context = {}; _cleanup_(cgroup_context_done) CGroupContext cgroup_context = {}; DynamicCreds dynamic_creds = {}; diff --git a/src/core/mount.c b/src/core/mount.c index 140286792a2..ded322d3323 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -908,7 +908,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) { static int mount_spawn(Mount *m, ExecCommand *c, PidRef *ret_pid) { - _cleanup_(exec_params_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT( + _cleanup_(exec_params_shallow_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT( EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN); _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; pid_t pid; diff --git a/src/core/service.c b/src/core/service.c index c63576ce790..d3e8d458544 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1611,7 +1611,7 @@ static int service_spawn_internal( ExecFlags flags, PidRef *ret_pid) { - _cleanup_(exec_params_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(flags); + _cleanup_(exec_params_shallow_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(flags); _cleanup_(sd_event_source_unrefp) sd_event_source *exec_fd_source = NULL; _cleanup_strv_free_ char **final_env = NULL, **our_env = NULL; _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; diff --git a/src/core/socket.c b/src/core/socket.c index 55de5f96eb5..156ac4a2d59 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1913,7 +1913,7 @@ static int socket_coldplug(Unit *u) { static int socket_spawn(Socket *s, ExecCommand *c, PidRef *ret_pid) { - _cleanup_(exec_params_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT( + _cleanup_(exec_params_shallow_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT( EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN); _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; pid_t pid; diff --git a/src/core/swap.c b/src/core/swap.c index 3a9f0e798dd..488b1719c53 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -632,7 +632,7 @@ static void swap_dump(Unit *u, FILE *f, const char *prefix) { static int swap_spawn(Swap *s, ExecCommand *c, PidRef *ret_pid) { - _cleanup_(exec_params_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT( + _cleanup_(exec_params_shallow_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT( EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN); _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; pid_t pid;