Skip to content

Commit 13585fa

Browse files
anadavIngo Molnar
authored andcommitted
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>
1 parent aad42dd commit 13585fa

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

include/linux/sched/task.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ extern void exit_itimers(struct signal_struct *);
7676
extern long _do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *, unsigned long);
7777
extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *);
7878
struct task_struct *fork_idle(int);
79+
struct mm_struct *copy_init_mm(void);
7980
extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
8081
extern long kernel_wait4(pid_t, int __user *, int, struct rusage *);
8182

kernel/fork.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,13 +1299,20 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm)
12991299
complete_vfork_done(tsk);
13001300
}
13011301

1302-
/*
1303-
* Allocate a new mm structure and copy contents from the
1304-
* mm structure of the passed in task structure.
1302+
/**
1303+
* dup_mm() - duplicates an existing mm 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.
13051311
*/
1306-
static struct mm_struct *dup_mm(struct task_struct *tsk)
1312+
static struct mm_struct *dup_mm(struct task_struct *tsk,
1313+
struct mm_struct *oldmm)
13071314
{
1308-
struct mm_struct *mm, *oldmm = current->mm;
1315+
struct mm_struct *mm;
13091316
int err;
13101317

13111318
mm = allocate_mm();
@@ -1372,7 +1379,7 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk)
13721379
}
13731380

13741381
retval = -ENOMEM;
1375-
mm = dup_mm(tsk);
1382+
mm = dup_mm(tsk, current->mm);
13761383
if (!mm)
13771384
goto fail_nomem;
13781385

@@ -2187,6 +2194,11 @@ struct task_struct *fork_idle(int cpu)
21872194
return task;
21882195
}
21892196

2197+
struct mm_struct *copy_init_mm(void)
2198+
{
2199+
return dup_mm(NULL, &init_mm);
2200+
}
2201+
21902202
/*
21912203
* Ok, this is the main fork-routine.
21922204
*

0 commit comments

Comments
 (0)