From patchwork Wed Apr 12 15:34:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 9677637 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3B26F601C3 for ; Wed, 12 Apr 2017 15:34:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E62C28625 for ; Wed, 12 Apr 2017 15:34:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 230912862D; Wed, 12 Apr 2017 15:34:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B059828625 for ; Wed, 12 Apr 2017 15:34:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754419AbdDLPei (ORCPT ); Wed, 12 Apr 2017 11:34:38 -0400 Received: from mail-eopbgr20127.outbound.protection.outlook.com ([40.107.2.127]:3440 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752500AbdDLPeg (ORCPT ); Wed, 12 Apr 2017 11:34:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=EusCfBxPDpcgtbOVihrnKsUbmeqz7eEZlER6vhFsiOI=; b=BmtfBMBppZT2Mb3a44zYRyFZDQvTq/Gz/nMh1rqu1ZM1id08uzyGAfanjErr/2HVQhUqRY/UpsVn5WIAJnmN1LA76jXnm/+gykg25VP5ldijR7uwCP6jh9atGwpggSWVuJu3+2GujFj8fHkzRNeJpH0VCQskfXw8R5w1tFhltwI= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=virtuozzo.com; Received: from localhost.localdomain (195.214.232.6) by DB6PR0802MB2280.eurprd08.prod.outlook.com (10.172.228.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1019.17; Wed, 12 Apr 2017 15:34:31 +0000 Subject: [PATCH v2 2/2] pidns: Expose task pid_ns_for_children to userspace From: Kirill Tkhai To: , , , , , , , , , , , , , , , , Date: Wed, 12 Apr 2017 18:34:27 +0300 Message-ID: <149201123914.6007.2187327078064239572.stgit@localhost.localdomain> In-Reply-To: <149201102204.6007.8628824763325355297.stgit@localhost.localdomain> References: <149201102204.6007.8628824763325355297.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: VI1PR08CA0023.eurprd08.prod.outlook.com (10.164.95.33) To DB6PR0802MB2280.eurprd08.prod.outlook.com (10.172.228.8) X-MS-Office365-Filtering-Correlation-Id: 382e0ed2-dd55-4c95-7143-08d481b96afa X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:DB6PR0802MB2280; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2280; 3:lsUY0EneosCbSGYhmLTZktnaPdHo/S3NE127hJRDFBC/dV64ucyvzpzEeNOF8Yjsr0kTbIqDrpPy5mxWWK21K6EkCk6jlVIKNJrX/fWAn/pk0zGfuoSpZoXjvDNuZ0I53YRHnT4TR85NiLGmCWaKqbv460WqHs3GgI+bb/VQTBQj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CxeRQGiLMK3tV6EyTMbLvR1DeRBkwy5GHmAdfxzjBcndUi4zzcwc4vzwINfvpPJJ0X+DYdSYPeP3+lrkfw89LDmdhtQ7LAWIyBfnq5TZKfCjyfJDKv06bZ3UwjSWNsaVE9B8wBQoDtWIPVXXDQtOtN0TEFE0ZjTOyM/gfekftKOJkCBG9VGRqQxehpBnNxG5qRyDZoM/jXlL83roGGAc/GGU6m0YrfbsNHtIuqohL3BrsGtLC8b3Ktc0pbvXHQhDg1ZAdAFzq93CkDGm7dVbJeynAiLIcrQMwm3Jrw/4DrVB4xjzRyrK4yoiOnt8DgqFPw= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(6041248)(201703131423075)(201702281528075)(201703061421075)(20161123564025)(20161123560025)(20161123555025)(20161123562025)(6072148); SRVR:DB6PR0802MB2280; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0802MB2280; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2280; 4:9ohr9pfLmNxTtlJA1ddCLLD3Oad+DyRYX4xYlt8chUTQpK8TZkqqc7xxuJOoWY23EuGuzzA1oN+w9m8Wqh2XrwnfmVaQGY5IwSjJVHwWUnIFld/UJ1gvdpTvXTrfJ8NmvAaCr7gM+rTr0LSSpJ6hxJcqNHT3dPRWZxYgVCWqX6j4VIEFh3EuqodgTUb8AT33tZxWb0184fE2rlx7a9WxgcjDy445d/t6y1cR0EVny8QWVJ6NCpI1KtxXzaY9TBiwYEILGwAAH/y5IqwnDa42/Gmtelu/GmIUDiV1HagNzHp1UPc0TEJtMZ8Ti+vAtd+BiCMaNtqA/vNHZzbCjuGrW28Pdpgi8ga2cD3pTRVMtOVDKx0wmAgczTeDFQn5ntPoO8UfM2buyidiWgHDfPkPPbvkFd09OTprqeLS5/GDPDGNHqrZGeWy7YRfuohK/3ZN6zDgcK5gjxVzQNi9+vPEra8AXlwKeGY+srjPwpZpgAfLjno3Sx/sK4AEkKA9buJWmqSS5sIhmqsefSqaaB2wEQTQM/9xUItMB6t7mjxEbX87kerXeA9CV6CytOzppXaix0LBJhMQIkj1dgkgetVBycksVaNYd2DiQldmFFgNOlroc+mDoZMHTmaAkGXzWqhmi6H46+Mh6AOzOBLPp8AMwArILmSKHEOgCJHDV6j+sT9W6PyQliOkdCDYDCCMEz0eM9nAGOvcM3RYzCOIETZ9Vg== X-Forefront-PRVS: 027578BB13 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(39450400003)(39830400002)(39400400002)(39410400002)(23676002)(305945005)(103116003)(7736002)(7416002)(4001350100001)(5660300001)(2950100002)(6666003)(54356999)(50986999)(76176999)(189998001)(38730400002)(42186005)(61506002)(2906002)(6506006)(33646002)(8676002)(55016002)(81166006)(53936002)(66066001)(83506001)(9686003)(575784001)(230700001)(86362001)(3846002)(50466002)(6116002)(2201001)(25786009)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0802MB2280; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtEQjZQUjA4MDJNQjIyODA7MjM6Zzg0MEdDSmVXc0dGbFhnOFdiaUhOTTBr?= =?utf-8?B?RU1QdXNNTHF0MjR0cEt3bWNqQW5QbnJUTUR4R3dFQkszcitOWTBFa1BKYjlX?= =?utf-8?B?TVVLbVd1c3dsVTRtYWwzdDRmMzRxNk1iVjN3cXpHMWdwaGVzdm1nYVhiWFlG?= =?utf-8?B?SUdLcVRkZEYxbjlaVVlYQm1hNlFSNGszMEpPQWE4OGVFT1N1TmZxNm9SOHpT?= =?utf-8?B?VTcrbElrZjNpV2gxaDNOdm9HL1BnRy84TENZN05XcVVnU0tVWWNZZUNrSTV3?= =?utf-8?B?NGh2TnA4Vmtrd0RSUWQrNWpGMExV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83NQKe4cYDsE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2280; 7:qMWqoNnBAa67QFLli1nPm25XvxwcE1pWRNWNg8iJ8o5bmaWMeaW0zxSe4rofpV1qcttoia+7kbt9SbhXlCScQwom7lSn5dCOxGemgKkQOEXWXXIdzjJfl+moR8pGO1kUPhVA9clMkgiRAj4/IhEW5bJqRib71a9KcYv9Dw7iqCipoMrUwD0OEI2ykjbQeym54MkRl1JcuhEvzyKHQ8l2lIvwZoGPZAMqW1LkOmzXFttE91XqfwgR2erNkydf3JvV6z1AygeIpiNvvYHErqScDq38+mOZ8zAzCyDDvYRaEArDMO5mq19FV0fo3/uxN97nMU5kLMlXQlngqaTSUaqCUw==; 20:UCgMgNadGHG04aOA18p7iLEvpg+LNLqMsx5dEks/JI9d6cjiE4UHWk8wCytOhq0x9ARsPrsSwHo1wr9/3v6nJ2dMw2786H2j6yxFAo1rn/Er/lTLLw7NH9lrBbyNjpbq3XnZF/Hjx/h41kN7xaS7mdttZeU5vMAV2UbwCnYIqlc= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2017 15:34:31.1347 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2280 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pid_ns_for_children set by a task is known only to the task itself, and it's impossible to identify it from outside. It's a big problem for checkpoint/restore software like CRIU, because it can't correctly handle tasks, that do setns(CLONE_NEWPID) in proccess of their work. This patch solves the problem, and it exposes pid_ns_for_children to ns directory in standard way with the name "pid_for_children": ~# ls /proc/5531/ns -l | grep pid lrwxrwxrwx 1 root root 0 Jan 14 16:38 pid -> pid:[4026531836] lrwxrwxrwx 1 root root 0 Jan 14 16:38 pid_for_children -> pid:[4026532286] v2: Do not allow to get namespace if there is no child reaper created, as other tasks need initializations it did (e.g., pid_namespace::proc_mnt), and we don't want they race. Signed-off-by: Kirill Tkhai --- fs/proc/namespaces.c | 1 + include/linux/proc_ns.h | 1 + kernel/pid_namespace.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c index 766f0c637ad1..3803b24ca220 100644 --- a/fs/proc/namespaces.c +++ b/fs/proc/namespaces.c @@ -23,6 +23,7 @@ static const struct proc_ns_operations *ns_entries[] = { #endif #ifdef CONFIG_PID_NS &pidns_operations, + &pidns_for_children_operations, #endif #ifdef CONFIG_USER_NS &userns_operations, diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h index 88dba3b53375..58ab28d81fc2 100644 --- a/include/linux/proc_ns.h +++ b/include/linux/proc_ns.h @@ -27,6 +27,7 @@ extern const struct proc_ns_operations netns_operations; extern const struct proc_ns_operations utsns_operations; extern const struct proc_ns_operations ipcns_operations; extern const struct proc_ns_operations pidns_operations; +extern const struct proc_ns_operations pidns_for_children_operations; extern const struct proc_ns_operations userns_operations; extern const struct proc_ns_operations mntns_operations; extern const struct proc_ns_operations cgroupns_operations; diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index de461aa0bf9a..d1f3e9f558b8 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -374,6 +374,29 @@ static struct ns_common *pidns_get(struct task_struct *task) return ns ? &ns->ns : NULL; } +static struct ns_common *pidns_for_children_get(struct task_struct *task) +{ + struct pid_namespace *ns = NULL; + + task_lock(task); + if (task->nsproxy) { + ns = task->nsproxy->pid_ns_for_children; + get_pid_ns(ns); + } + task_unlock(task); + + if (ns) { + read_lock(&tasklist_lock); + if (!ns->child_reaper) { + put_pid_ns(ns); + ns = NULL; + } + read_unlock(&tasklist_lock); + } + + return ns ? &ns->ns : NULL; +} + static void pidns_put(struct ns_common *ns) { put_pid_ns(to_pid_ns(ns)); @@ -443,6 +466,17 @@ const struct proc_ns_operations pidns_operations = { .get_parent = pidns_get_parent, }; +const struct proc_ns_operations pidns_for_children_operations = { + .name = "pid_for_children", + .real_ns_name = "pid", + .type = CLONE_NEWPID, + .get = pidns_for_children_get, + .put = pidns_put, + .install = pidns_install, + .owner = pidns_owner, + .get_parent = pidns_get_parent, +}; + static __init int pid_namespaces_init(void) { pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC);