From patchwork Fri Jun 19 15:35:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 11614389 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3AD1A1731 for ; Fri, 19 Jun 2020 15:36:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EBC9A20732 for ; Fri, 19 Jun 2020 15:36:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="S8CrRxwP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EBC9A20732 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ubuntu.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tC9ic659D0rppZEkwWE3DqcvMH90Vy/dmA2KXNpVraI=; b=S8CrRxwPohNl1T c8O+Cx71Nfl6yaYwupN2lVa5M6P7FX3ZXs0+G+pk7HKz11UCYzuYZcRMCD/2VGZ7wjSfc3IxTJduh HLgNkPL1xkPx/z0pesyTcnSEjc3+xXgFHjw2+lw6qkJ3jV2qqfTq85Q6ewl3UKoeMbBFl2ZzObGlo ehne3i5MYsDjI8FdZ2I1YXqPUOPce+K8VSGGPD1h1kyfmer1jsEFrRfoOWQEn3SrK7toXJBh+14U4 BGhSV1GxeWRbEJkb5pMnnB2pi+IjHJOiRG6HaSjBaV4oYXH8P+USkK+CMjumx9NaZ8zleUPwWV+8L MSWaBIfDSa5MOK/hnvlQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jmJ4C-00038Q-6n; Fri, 19 Jun 2020 15:36:32 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jmJ43-0002xy-Ce for linux-arm-kernel@lists.infradead.org; Fri, 19 Jun 2020 15:36:24 +0000 Received: from ip-109-41-0-196.web.vodafone.de ([109.41.0.196] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jmJ40-0000bE-FM; Fri, 19 Jun 2020 15:36:20 +0000 From: Christian Brauner To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH 1/3] timens: make vdso_join_timens() always succeed Date: Fri, 19 Jun 2020 17:35:57 +0200 Message-Id: <20200619153559.724863-2-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619153559.724863-1-christian.brauner@ubuntu.com> References: <20200619153559.724863-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200619_083623_557056_F193BBA9 X-CRM114-Status: GOOD ( 16.10 ) X-Spam-Score: -5.0 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-5.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [91.189.89.112 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [91.189.89.112 listed in wl.mailspike.net] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Dmitry Safonov , Catalin Marinas , Andrei Vagin , Michael Kerrisk , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Will Deacon , Christian Brauner , Serge Hallyn Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org As discussed on-list (cf. [1]), in order to make setns() support time namespaces properly we need to tweak vdso_join_timens() to always succeed. So switch vdso_join_timens() from mmap_write_lock_killable() to mmap_write_lock(). Last cycle setns() was changed to support attaching to multiple namespaces atomically. This requires all namespaces to have a point of no return where they can't fail anymore. Specifically, _install() is allowed to perform permission checks and install the namespace into the new struct nsset that it has been given but it is not allowed to make visible changes to the affected task. Once _install() returns anything that the given namespace type requires to be setup in addition needs to ideally be done in a function that can't fail or if it fails the failure is not fatal. For time namespaces the relevant functions that fall into this category are timens_set_vvar_page() and vdso_join_timens(). Currently the latter can fail but doesn't need to. With this we can go on to implement a timens_commit() helper in a follow up patch to be used by setns(). [1]: https://lore.kernel.org/lkml/20200611110221.pgd3r5qkjrjmfqa2@wittgenstein Cc: Will Deacon Cc: Vincenzo Frascino Cc: Thomas Gleixner Cc: Andy Lutomirski Cc: Catalin Marinas Cc: Mark Rutland Cc: Dmitry Safonov Cc: Andrei Vagin Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Christian Brauner --- arch/x86/entry/vdso/vma.c | 6 ++---- include/linux/time_namespace.h | 7 +++---- kernel/time/namespace.c | 10 ++-------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c index ea7c1f0b79df..be3f542e419c 100644 --- a/arch/x86/entry/vdso/vma.c +++ b/arch/x86/entry/vdso/vma.c @@ -139,13 +139,12 @@ static struct page *find_timens_vvar_page(struct vm_area_struct *vma) * corresponding layout. * See also the comment near timens_setup_vdso_data() for details. */ -int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) +void vdso_join_timens(struct task_struct *task, struct time_namespace *ns) { struct mm_struct *mm = task->mm; struct vm_area_struct *vma; - if (mmap_write_lock_killable(mm)) - return -EINTR; + mmap_write_lock(mm); for (vma = mm->mmap; vma; vma = vma->vm_next) { unsigned long size = vma->vm_end - vma->vm_start; @@ -155,7 +154,6 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) } mmap_write_unlock(mm); - return 0; } #else static inline struct page *find_timens_vvar_page(struct vm_area_struct *vma) diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h index 824d54e057eb..4d1768c6f836 100644 --- a/include/linux/time_namespace.h +++ b/include/linux/time_namespace.h @@ -31,8 +31,8 @@ struct time_namespace { extern struct time_namespace init_time_ns; #ifdef CONFIG_TIME_NS -extern int vdso_join_timens(struct task_struct *task, - struct time_namespace *ns); +extern void vdso_join_timens(struct task_struct *task, + struct time_namespace *ns); static inline struct time_namespace *get_time_ns(struct time_namespace *ns) { @@ -90,10 +90,9 @@ static inline ktime_t timens_ktime_to_host(clockid_t clockid, ktime_t tim) } #else -static inline int vdso_join_timens(struct task_struct *task, +static inline void vdso_join_timens(struct task_struct *task, struct time_namespace *ns) { - return 0; } static inline struct time_namespace *get_time_ns(struct time_namespace *ns) diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c index 5d9fc22d836a..e5af6fe87af8 100644 --- a/kernel/time/namespace.c +++ b/kernel/time/namespace.c @@ -284,7 +284,6 @@ static int timens_install(struct nsset *nsset, struct ns_common *new) { struct nsproxy *nsproxy = nsset->nsproxy; struct time_namespace *ns = to_time_ns(new); - int err; if (!current_is_single_threaded()) return -EUSERS; @@ -295,9 +294,7 @@ static int timens_install(struct nsset *nsset, struct ns_common *new) timens_set_vvar_page(current, ns); - err = vdso_join_timens(current, ns); - if (err) - return err; + vdso_join_timens(current, ns); get_time_ns(ns); put_time_ns(nsproxy->time_ns); @@ -313,7 +310,6 @@ int timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk) { struct ns_common *nsc = &nsproxy->time_ns_for_children->ns; struct time_namespace *ns = to_time_ns(nsc); - int err; /* create_new_namespaces() already incremented the ref counter */ if (nsproxy->time_ns == nsproxy->time_ns_for_children) @@ -321,9 +317,7 @@ int timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk) timens_set_vvar_page(tsk, ns); - err = vdso_join_timens(tsk, ns); - if (err) - return err; + vdso_join_timens(tsk, ns); get_time_ns(ns); put_time_ns(nsproxy->time_ns); From patchwork Fri Jun 19 15:35:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 11614391 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D37CE90 for ; Fri, 19 Jun 2020 15:37:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A329D20786 for ; Fri, 19 Jun 2020 15:37:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Mt9FeugL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A329D20786 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ubuntu.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vMQfhg61oL+PwWoSvy+dKiTj3mIKGsTgS9nE+IdPM10=; b=Mt9FeugLCSgflx wrgLIRCSPJZ5VZC7dqgHhEIn72KWLhXBTWu7hXacf3F9nwurLISAkCkW8nti47yI0NvG6wX4lJfA4 XZid8y2/4W2eat8oYNQKjJQLm40JubRKgT3vv559jRvnKQS7VBlKvIAICXZZkPXfDH7+WOI+idmW4 P3T1CXReWyStH9zsQHAX9kpogMK15cZ5sma0dgiBqIyIc5frn7J3i8/1qvU4iA/vmy1/f6COH5Mrn 5jDr2aqe6KX3rPlgdKEJ3u5Ww1WUl1eh723ZbPvXMx0d6UMXm/EaecPLsEqh3B5fCAPhO+b6KWGsW +MnIqv9ifrXKFtaCLL/g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jmJ4a-0003SF-Iq; Fri, 19 Jun 2020 15:36:56 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jmJ46-0002zV-6u for linux-arm-kernel@lists.infradead.org; Fri, 19 Jun 2020 15:36:27 +0000 Received: from ip-109-41-0-196.web.vodafone.de ([109.41.0.196] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jmJ44-0000bE-6M; Fri, 19 Jun 2020 15:36:24 +0000 From: Christian Brauner To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH 2/3] timens: add timens_commit() helper Date: Fri, 19 Jun 2020 17:35:58 +0200 Message-Id: <20200619153559.724863-3-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619153559.724863-1-christian.brauner@ubuntu.com> References: <20200619153559.724863-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200619_083626_436160_722BF873 X-CRM114-Status: GOOD ( 11.04 ) X-Spam-Score: -5.0 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-5.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [91.189.89.112 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [91.189.89.112 listed in wl.mailspike.net] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Dmitry Safonov , Catalin Marinas , Andrei Vagin , Michael Kerrisk , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Will Deacon , Christian Brauner , Serge Hallyn Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Wrap the calls to timens_set_vvar_page() and vdso_join_timens() in timens_on_fork() and timens_install() in a new timens_commit() helper. We'll use this helper in a follow-up patch in nsproxy too. Cc: Will Deacon Cc: Vincenzo Frascino Cc: Thomas Gleixner Cc: Catalin Marinas Cc: Mark Rutland Cc: Dmitry Safonov Cc: Andrei Vagin Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Christian Brauner --- kernel/time/namespace.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c index e5af6fe87af8..aa7b90aac2a7 100644 --- a/kernel/time/namespace.c +++ b/kernel/time/namespace.c @@ -280,6 +280,12 @@ static void timens_put(struct ns_common *ns) put_time_ns(to_time_ns(ns)); } +static void timens_commit(struct task_struct *tsk, struct time_namespace *ns) +{ + timens_set_vvar_page(tsk, ns); + vdso_join_timens(tsk, ns); +} + static int timens_install(struct nsset *nsset, struct ns_common *new) { struct nsproxy *nsproxy = nsset->nsproxy; @@ -292,9 +298,8 @@ static int timens_install(struct nsset *nsset, struct ns_common *new) !ns_capable(nsset->cred->user_ns, CAP_SYS_ADMIN)) return -EPERM; - timens_set_vvar_page(current, ns); - vdso_join_timens(current, ns); + timens_commit(current, ns); get_time_ns(ns); put_time_ns(nsproxy->time_ns); @@ -315,14 +320,12 @@ int timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk) if (nsproxy->time_ns == nsproxy->time_ns_for_children) return 0; - timens_set_vvar_page(tsk, ns); - - vdso_join_timens(tsk, ns); - get_time_ns(ns); put_time_ns(nsproxy->time_ns); nsproxy->time_ns = ns; + timens_commit(tsk, ns); + return 0; } From patchwork Fri Jun 19 15:35:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 11614393 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D18713A0 for ; Fri, 19 Jun 2020 15:37:09 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C8B36206FA for ; Fri, 19 Jun 2020 15:37:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="M7A15hQx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8B36206FA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ubuntu.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=izjvNWQLkeVNdM8+JjMGylHxv+S2l1v3cyaXsR43YHM=; b=M7A15hQxEk5nMW yUHT4vN7LVFihckZmznpQi9z6DSXumHeI7eMj+Zcan/ddSoB5X/Y6OWI0tHXfqoP+eSYJZUpK4SHg YpScYN+e9KPodLn7o48cxLi5AbDEkNIuAqSG2LY7zjT7Ndr8AgsG/q3zCt6/rYkU7UvgTgRHLN7Xd Li1kPM1JqBm005fvBYu64veWl+95tTdsV8T6yp5nKNxfi9kcJBVQaxV6KjvQz5NXPtpBS9UA4CDQQ NTeh19JXACSOStkyvb/TBoK2Km3KAzPrWLfIHrRjihba6XAH55AReMjBqEwx+s2gc71g4iYZ9gKD1 ALx2YY9lWX0qgOfI2sPQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jmJ4k-0003eY-VQ; Fri, 19 Jun 2020 15:37:07 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jmJ4A-00034u-0o for linux-arm-kernel@lists.infradead.org; Fri, 19 Jun 2020 15:36:31 +0000 Received: from ip-109-41-0-196.web.vodafone.de ([109.41.0.196] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jmJ47-0000bE-W1; Fri, 19 Jun 2020 15:36:28 +0000 From: Christian Brauner To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH 3/3] nsproxy: support CLONE_NEWTIME with setns() Date: Fri, 19 Jun 2020 17:35:59 +0200 Message-Id: <20200619153559.724863-4-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619153559.724863-1-christian.brauner@ubuntu.com> References: <20200619153559.724863-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200619_083630_208954_5C30E1EC X-CRM114-Status: GOOD ( 12.72 ) X-Spam-Score: -5.0 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-5.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [91.189.89.112 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [91.189.89.112 listed in wl.mailspike.net] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Dmitry Safonov , Catalin Marinas , Andrei Vagin , Michael Kerrisk , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Will Deacon , Christian Brauner , Serge Hallyn Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org So far setns() was missing time namespace support. This was partially due to it simply not being implemented but also because vdso_join_timens() could still fail which made switching to multiple namespaces atomically problematic. This is now fixed so support CLONE_NEWTIME with setns() Cc: Thomas Gleixner Cc: Michael Kerrisk Cc: Serge Hallyn Cc: Dmitry Safonov Cc: Andrei Vagin Signed-off-by: Christian Brauner Reviewed-by: Andrei Vagin --- include/linux/time_namespace.h | 6 ++++++ kernel/nsproxy.c | 21 +++++++++++++++++++-- kernel/time/namespace.c | 5 +---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h index 4d1768c6f836..d308a3812f79 100644 --- a/include/linux/time_namespace.h +++ b/include/linux/time_namespace.h @@ -33,6 +33,7 @@ extern struct time_namespace init_time_ns; #ifdef CONFIG_TIME_NS extern void vdso_join_timens(struct task_struct *task, struct time_namespace *ns); +extern void timens_commit(struct task_struct *tsk, struct time_namespace *ns); static inline struct time_namespace *get_time_ns(struct time_namespace *ns) { @@ -95,6 +96,11 @@ static inline void vdso_join_timens(struct task_struct *task, { } +static inline void timens_commit(struct task_struct *tsk, + struct time_namespace *ns) +{ +} + static inline struct time_namespace *get_time_ns(struct time_namespace *ns) { return NULL; diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index b03df67621d0..f12231c41b69 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c @@ -262,8 +262,8 @@ void exit_task_namespaces(struct task_struct *p) static int check_setns_flags(unsigned long flags) { if (!flags || (flags & ~(CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | - CLONE_NEWNET | CLONE_NEWUSER | CLONE_NEWPID | - CLONE_NEWCGROUP))) + CLONE_NEWNET | CLONE_NEWTIME | CLONE_NEWUSER | + CLONE_NEWPID | CLONE_NEWCGROUP))) return -EINVAL; #ifndef CONFIG_USER_NS @@ -290,6 +290,10 @@ static int check_setns_flags(unsigned long flags) if (flags & CLONE_NEWNET) return -EINVAL; #endif +#ifndef CONFIG_TIME_NS + if (flags & CLONE_NEWTIME) + return -EINVAL; +#endif return 0; } @@ -464,6 +468,14 @@ static int validate_nsset(struct nsset *nsset, struct pid *pid) } #endif +#ifdef CONFIG_TIME_NS + if (flags & CLONE_NEWTIME) { + ret = validate_ns(nsset, &nsp->time_ns->ns); + if (ret) + goto out; + } +#endif + out: if (pid_ns) put_pid_ns(pid_ns); @@ -507,6 +519,11 @@ static void commit_nsset(struct nsset *nsset) exit_sem(me); #endif +#ifdef CONFIG_TIME_NS + if (flags & CLONE_NEWTIME) + timens_commit(me, nsset->nsproxy->time_ns); +#endif + /* transfer ownership */ switch_task_namespaces(me, nsset->nsproxy); nsset->nsproxy = NULL; diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c index aa7b90aac2a7..afc65e6be33e 100644 --- a/kernel/time/namespace.c +++ b/kernel/time/namespace.c @@ -280,7 +280,7 @@ static void timens_put(struct ns_common *ns) put_time_ns(to_time_ns(ns)); } -static void timens_commit(struct task_struct *tsk, struct time_namespace *ns) +void timens_commit(struct task_struct *tsk, struct time_namespace *ns) { timens_set_vvar_page(tsk, ns); vdso_join_timens(tsk, ns); @@ -298,9 +298,6 @@ static int timens_install(struct nsset *nsset, struct ns_common *new) !ns_capable(nsset->cred->user_ns, CAP_SYS_ADMIN)) return -EPERM; - - timens_commit(current, ns); - get_time_ns(ns); put_time_ns(nsproxy->time_ns); nsproxy->time_ns = ns;