summaryrefslogtreecommitdiff
path: root/kernel/fork.c
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2026-06-01 15:56:34 +0200
committerChristian Brauner <brauner@kernel.org>2026-06-29 10:38:48 +0200
commit21bcea3ef2025796a29ba88f2747d864ed535758 (patch)
tree37d723cb3d486273a3e58e055222277f3166bf2b /kernel/fork.c
parentdc59e4fea9d83f03bad6bddf3fa2e52491777482 (diff)
fs: add switch_fs_struct()
Don't open-code the guts of replacing current's fs struct. Link: https://patch.msgid.link/20260601-work-kthread-nullfs-v4-1-77ee053060e0@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 13e38e89a1f3..27f775113be6 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -3215,7 +3215,7 @@ static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp
*/
int ksys_unshare(unsigned long unshare_flags)
{
- struct fs_struct *fs, *new_fs = NULL;
+ struct fs_struct *new_fs = NULL;
struct files_struct *new_fd = NULL;
struct cred *new_cred = NULL;
struct nsproxy *new_nsproxy = NULL;
@@ -3293,23 +3293,13 @@ int ksys_unshare(unsigned long unshare_flags)
new_nsproxy = NULL;
}
- task_lock(current);
+ if (new_fs)
+ new_fs = switch_fs_struct(new_fs);
- if (new_fs) {
- fs = current->fs;
- read_seqlock_excl(&fs->seq);
- current->fs = new_fs;
- if (--fs->users)
- new_fs = NULL;
- else
- new_fs = fs;
- read_sequnlock_excl(&fs->seq);
- }
-
- if (new_fd)
+ if (new_fd) {
+ guard(task_lock)(current);
swap(current->files, new_fd);
-
- task_unlock(current);
+ }
if (new_cred) {
/* Install the new user namespace */