Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2715046imu; Sat, 10 Nov 2018 22:39:38 -0800 (PST) X-Google-Smtp-Source: AJdET5cDoUli/vZ5KqpVsqUT3BdGem8FWHyIqR25Wn8OyF0/7CrKO0GsFmYx3sGCWqmmv1tXe1hw X-Received: by 2002:a65:4946:: with SMTP id q6mr6128820pgs.201.1541918377962; Sat, 10 Nov 2018 22:39:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541918377; cv=none; d=google.com; s=arc-20160816; b=zg/4DfoVfL0NjYyiQwdQRHz6xxV48W8hLJA5xYrF/hBcg1ApUtlw7rb7Mvqa8dQtLR cZX4shWrhtFUs6oWzbNGK3LeRIrTS0+QBQkdeqUjBT1ixax/Au/8WPFUBXnAMVGdbn/c EhI/S4JVcKS11KkTHcC+eKpDA4gLoS9cDutHEhVZ1Y4fdbd61jW7ytdkIeqbZHeGKo2O wXkVFd4yIw9Uq/qvDoyKl7Idn01P9ToEUWYWI7TOcKrHRKtIY7RcMSFVwQWG4SmpC6BP sBbJ10yS0MjpHYNF3Vj4kWo7f9e5yRKEowpGPhYcO2cavMHGzD3Ls9e8wHcVtYJzM6CM +9uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=TU5S11W+4/P/nvq0gRAs4FWCRJ4P/Vc801qFHvfGOBg=; b=oWXGRIaXacQHoP7oq+rx4cvAvYtB+9u3yKT52JnMPTv1KjR5q5oK86COoj9jQDcM/w gFAcIGMGpRVHvoesm3ed6UaLV42K12Dtk0uGybpWFXqPbx45T3sFFpfjFucdNMljWsf3 ObgRk8ClzdNa6T9aDILk9B0wjJT3WIzNLE9OleCBnjpi/YwXkJD7kNKoqVlZxa3PCXnD 8y1aZHpS7yuCCkgVVH90+Zv7l+zqu7C2ZaJ7poKiLD+tu2QiNiu5q889KX1/WvVyuflr ln33Adawra9LIAHDh8KmYEQPVhj16jEGuYdU05fgEpp71kIx7z8qrQlFy7s43Q1py7kg hxQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l91-v6si14112905plb.315.2018.11.10.22.39.22; Sat, 10 Nov 2018 22:39:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727594AbeKKQXG (ORCPT + 99 others); Sun, 11 Nov 2018 11:23:06 -0500 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:25452 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727427AbeKKQXF (ORCPT ); Sun, 11 Nov 2018 11:23:05 -0500 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Sat, 10 Nov 2018 22:35:01 -0800 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 57EC740788; Sat, 10 Nov 2018 22:35:24 -0800 (PST) From: Nadav Amit To: Ingo Molnar CC: , , "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov , Dave Hansen , Nadav Amit , Andy Lutomirski , Kees Cook , Peter Zijlstra , Dave Hansen Subject: [PATCH v4 04/10] fork: provide a function for copying init_mm Date: Sat, 10 Nov 2018 15:17:26 -0800 Message-ID: <20181110231732.15060-5-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181110231732.15060-1-namit@vmware.com> References: <20181110231732.15060-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-001.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide a function for copying init_mm. This function will be later used for setting a temporary mm. Cc: Andy Lutomirski Cc: Kees Cook Cc: Peter Zijlstra Cc: Dave Hansen Reviewed-by: Masami Hiramatsu Tested-by: Masami Hiramatsu Signed-off-by: Nadav Amit --- include/linux/sched/task.h | 1 + kernel/fork.c | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index 108ede99e533..ac0a675678f5 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -74,6 +74,7 @@ extern void exit_itimers(struct signal_struct *); extern long _do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *, unsigned long); extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *); struct task_struct *fork_idle(int); +struct mm_struct *copy_init_mm(void); extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags); extern long kernel_wait4(pid_t, int __user *, int, struct rusage *); diff --git a/kernel/fork.c b/kernel/fork.c index 07cddff89c7b..01d3f5b39363 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1297,13 +1297,20 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm) complete_vfork_done(tsk); } -/* - * Allocate a new mm structure and copy contents from the - * mm structure of the passed in task structure. +/** + * dup_mm() - duplicates an existing mm structure + * @tsk: the task_struct with which the new mm will be associated. + * @oldmm: the mm to duplicate. + * + * Allocates a new mm structure and copy contents from the provided + * @oldmm structure. + * + * Return: the duplicated mm or NULL on failure. */ -static struct mm_struct *dup_mm(struct task_struct *tsk) +static struct mm_struct *dup_mm(struct task_struct *tsk, + struct mm_struct *oldmm) { - struct mm_struct *mm, *oldmm = current->mm; + struct mm_struct *mm; int err; mm = allocate_mm(); @@ -1370,7 +1377,7 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk) } retval = -ENOMEM; - mm = dup_mm(tsk); + mm = dup_mm(tsk, current->mm); if (!mm) goto fail_nomem; @@ -2176,6 +2183,11 @@ struct task_struct *fork_idle(int cpu) return task; } +struct mm_struct *copy_init_mm(void) +{ + return dup_mm(NULL, &init_mm); +} + /* * Ok, this is the main fork-routine. * -- 2.17.1