summaryrefslogtreecommitdiffstats
path: root/kernel/fork.c
diff options
context:
space:
mode:
authorNadav Amit <namit@vmware.com>2019-04-25 20:11:25 -0400
committerIngo Molnar <mingo@kernel.org>2019-04-30 06:37:51 -0400
commit13585fa0668c724efab9635aaeef6ec390217415 (patch)
tree9297a8546413b27537cdb4a699afcec63c3741c8 /kernel/fork.c
parentaad42dd44db086c79ca3f470ad563d2ac4ac218d (diff)
fork: Provide a function for copying init_mm
Provide a function for copying init_mm. This function will be later used for setting a temporary mm. Tested-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Nadav Amit <namit@vmware.com> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org> Cc: <akpm@linux-foundation.org> Cc: <ard.biesheuvel@linaro.org> Cc: <deneen.t.dock@intel.com> Cc: <kernel-hardening@lists.openwall.com> Cc: <kristen@linux.intel.com> Cc: <linux_dti@icloud.com> Cc: <will.deacon@arm.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Kees Cook <keescook@chromium.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Rik van Riel <riel@surriel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/20190426001143.4983-6-namit@vmware.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 44fba5e5e916..fbe9dfcd8680 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1299,13 +1299,20 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm)
1299 complete_vfork_done(tsk); 1299 complete_vfork_done(tsk);
1300} 1300}
1301 1301
1302/* 1302/**
1303 * Allocate a new mm structure and copy contents from the 1303 * dup_mm() - duplicates an existing mm structure
1304 * mm structure of the passed in task structure. 1304 * @tsk: the task_struct with which the new mm will be associated.
1305 * @oldmm: the mm to duplicate.
1306 *
1307 * Allocates a new mm structure and duplicates the provided @oldmm structure
1308 * content into it.
1309 *
1310 * Return: the duplicated mm or NULL on failure.
1305 */ 1311 */
1306static struct mm_struct *dup_mm(struct task_struct *tsk) 1312static struct mm_struct *dup_mm(struct task_struct *tsk,
1313 struct mm_struct *oldmm)
1307{ 1314{
1308 struct mm_struct *mm, *oldmm = current->mm; 1315 struct mm_struct *mm;
1309 int err; 1316 int err;
1310 1317
1311 mm = allocate_mm(); 1318 mm = allocate_mm();
@@ -1372,7 +1379,7 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk)
1372 } 1379 }
1373 1380
1374 retval = -ENOMEM; 1381 retval = -ENOMEM;
1375 mm = dup_mm(tsk); 1382 mm = dup_mm(tsk, current->mm);
1376 if (!mm) 1383 if (!mm)
1377 goto fail_nomem; 1384 goto fail_nomem;
1378 1385
@@ -2187,6 +2194,11 @@ struct task_struct *fork_idle(int cpu)
2187 return task; 2194 return task;
2188} 2195}
2189 2196
2197struct mm_struct *copy_init_mm(void)
2198{
2199 return dup_mm(NULL, &init_mm);
2200}
2201
2190/* 2202/*
2191 * Ok, this is the main fork-routine. 2203 * Ok, this is the main fork-routine.
2192 * 2204 *