namespace: Clone root dir descriptor before use

Before doing anything with the root directory file descriptor, let's
make sure we clone it first so that the caller can't mess with mount fd
attributes via mount_setattr() anymore.

We clone during parsing instead of in executor so that the caller can't
mess with the mount fd between invocations.
This commit is contained in:
Daan De Meyer
2025-12-14 11:32:06 +01:00
parent 273c6bc045
commit 5eb0639faa
3 changed files with 39 additions and 8 deletions
+1
View File
@@ -2877,6 +2877,7 @@ void exec_params_shallow_clear(ExecParameters *p) {
p->fd_names = strv_free(p->fd_names);
p->files_env = strv_free(p->files_env);
p->fds = mfree(p->fds);
p->root_directory_fd = safe_close(p->root_directory_fd);
p->exec_fd = safe_close(p->exec_fd);
p->user_lookup_fd = -EBADF;
p->bpf_restrict_fs_map_fd = -EBADF;