From patchwork Sat May 1 14:14:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oren Laadan X-Patchwork-Id: 51431 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 29332B8381 for ; Sun, 2 May 2010 00:27:02 +1000 (EST) Received: by ozlabs.org (Postfix) id EC04EB7D5C; Sun, 2 May 2010 00:26:18 +1000 (EST) Delivered-To: linuxppc-dev@ozlabs.org Received: from tarap.cc.columbia.edu (tarap.cc.columbia.edu [128.59.29.7]) by ozlabs.org (Postfix) with ESMTP id 11DA7100945 for ; Sun, 2 May 2010 00:26:17 +1000 (EST) Received: from localhost.localdomain (cpe-66-108-42-212.nyc.res.rr.com [66.108.42.212]) (user=ol2104 mech=PLAIN bits=0) by tarap.cc.columbia.edu (8.14.3/8.14.3) with ESMTP id o41EGS8o028326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 1 May 2010 10:20:44 -0400 (EDT) From: Oren Laadan To: Andrew Morton Subject: [PATCH v21 006/100] eclone (6/11): Check invalid clone flags Date: Sat, 1 May 2010 10:14:48 -0400 Message-Id: <1272723382-19470-7-git-send-email-orenl@cs.columbia.edu> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1272723382-19470-1-git-send-email-orenl@cs.columbia.edu> References: <1272723382-19470-1-git-send-email-orenl@cs.columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.68 on 128.59.29.7 Cc: linux-s390@vger.kernel.org, linux-api@vger.kernel.org, containers@lists.linux-foundation.org, x86@kernel.org, linux-kernel@vger.kernel.org, Oleg Nesterov , linuxppc-dev@ozlabs.org, Matt Helsley , Serge Hallyn , Sukadev Bhattiprolu , Pavel Emelyanov X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org From: Sukadev Bhattiprolu As pointed out by Oren Laadan, we want to ensure that unused bits in the clone-flags remain unused and available for future. To ensure this, define a mask of clone-flags and check the flags in the clone() system calls. Changelog[v9]: - Include the unused clone-flag (CLONE_UNUSED) to VALID_CLONE_FLAGS to avoid breaking any applications that may have set it. IOW, this patch/check only applies to clone-flags bits 33 and higher. Changelog[v8]: - New patch in set Cc: linux-api@vger.kernel.org Cc: x86@kernel.org Cc: linux-s390@vger.kernel.org Cc: linuxppc-dev@ozlabs.org Cc: Oleg Nesterov Signed-off-by: Sukadev Bhattiprolu Acked-by: Serge E. Hallyn Tested-by: Serge E. Hallyn Acked-by: Oren Laadan --- include/linux/sched.h | 12 ++++++++++++ kernel/fork.c | 3 +++ 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index dad7f66..5de3ce5 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -29,6 +29,18 @@ #define CLONE_NEWNET 0x40000000 /* New network namespace */ #define CLONE_IO 0x80000000 /* Clone io context */ +#define CLONE_UNUSED 0x00001000 /* Can be reused ? */ + +#define VALID_CLONE_FLAGS (CSIGNAL | CLONE_VM | CLONE_FS | CLONE_FILES |\ + CLONE_SIGHAND | CLONE_UNUSED | CLONE_PTRACE |\ + CLONE_VFORK | CLONE_PARENT | CLONE_THREAD |\ + CLONE_NEWNS | CLONE_SYSVSEM | CLONE_SETTLS |\ + CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID |\ + CLONE_DETACHED | CLONE_UNTRACED |\ + CLONE_CHILD_SETTID | CLONE_STOPPED |\ + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER |\ + CLONE_NEWPID | CLONE_NEWNET | CLONE_IO) + /* * Scheduling policies */ diff --git a/kernel/fork.c b/kernel/fork.c index 9d2b57e..e41b3d1 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -964,6 +964,9 @@ static struct task_struct *copy_process(unsigned long clone_flags, struct task_struct *p; int cgroup_callbacks_done = 0; + if (clone_flags & ~VALID_CLONE_FLAGS) + return ERR_PTR(-EINVAL); + if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS)) return ERR_PTR(-EINVAL);