From patchwork Wed May 3 10:32:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 9709169 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 1E53460385 for ; Wed, 3 May 2017 10:33:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C67A284E5 for ; Wed, 3 May 2017 10:33:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 010D228557; Wed, 3 May 2017 10:33:27 +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 CBFA2285FD for ; Wed, 3 May 2017 10:33:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753686AbdECKdH (ORCPT ); Wed, 3 May 2017 06:33:07 -0400 Received: from mail-db5eur01on0115.outbound.protection.outlook.com ([104.47.2.115]:11344 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753365AbdECKct (ORCPT ); Wed, 3 May 2017 06:32:49 -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=qCBxD8h0kZ3/pVU67nynFelG8scUk2Y8lqF3yqrfDeI=; b=Vo2Cf711fKf5ChJdO1dM+Ww4s5Sd9Psdk5mR6p/7aupwq4vY9SEENW6RY4CmwKaXndfw/1TN0Br2nEVs/sRESkuDZ9RAh9MNv33aNvVgKw5ctEUsdkOUxfTNeTcb+ZQQPph616FIZXZ1OwfIvpaaWCn7uUmP1LtZvLNgteUk2Rs= Authentication-Results: hallyn.com; dkim=none (message not signed) header.d=none; hallyn.com; dmarc=none action=none header.from=virtuozzo.com; Received: from localhost.localdomain (195.214.232.6) by AM4PR0802MB2274.eurprd08.prod.outlook.com (10.172.218.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1061.12; Wed, 3 May 2017 10:32:39 +0000 Subject: [PATCH v3 2/2] pidns: Expose task pid_ns_for_children to userspace From: Kirill Tkhai To: , , , , , , , , , , , , , , , , Date: Wed, 3 May 2017 13:32:37 +0300 Message-ID: <149380755708.3812.7454892577172259238.stgit@localhost.localdomain> In-Reply-To: <149380742825.3812.2073418607639032138.stgit@localhost.localdomain> References: <149380742825.3812.2073418607639032138.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0402CA0020.eurprd04.prod.outlook.com (10.175.27.30) To AM4PR0802MB2274.eurprd08.prod.outlook.com (10.172.218.7) X-MS-Office365-Filtering-Correlation-Id: ad3ec9e9-42cc-4d84-eadf-08d4920fba09 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:AM4PR0802MB2274; X-Microsoft-Exchange-Diagnostics: 1; AM4PR0802MB2274; 3:LSohW+m5erTXaqpFriOl/W4wSYQo/VNd9iKEJrw5AByaBFi9rIrQ5bsEUCA7h0AKw49ao8ZhmET8b0t3YsbM2uG1ncKetj4Od4pbz9avuugwlzubhk6KOO3ku56Y6NcTYHB7SFSvVvXxdrMVv6HYQ6RmkFXRJJrzzbgjPnlxJvQ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eIyDwYgnhZu1LhqK7y/p+4FrP4fPe5alhlecVcagjqwcMf8ZOB56Z/x2zZSROwlqbnumfNF97jciRln2KILnBp7Y+yYzBjOLWrM4YTk1aMi6aD0hVMrXZ4Kt3p7t9htt8Mat/9LVGUc2gkqhr9z1UxpezQ3zJQn1FmBDwnp5pizuzS6pa2mfO42dfWcNkQuwg+jJoATbDruE4VxYSvDs0Yw2nPu9Ut7v6HpIJNHa2ka5erzxWWYQPcl01rRyaEibZq5UHvlRQQMB9zSiDNhg= 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)(93006095)(93001095)(10201501046)(3002001)(6041248)(20161123560025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(6072148); SRVR:AM4PR0802MB2274; BCL:0; PCL:0; RULEID:; SRVR:AM4PR0802MB2274; X-Microsoft-Exchange-Diagnostics: 1; AM4PR0802MB2274; 4:NOM+MsMibFMqo5Wpc+O7cJ6hyCThPl1csdcSTCiSrQXyIKJI83zg/oP2CKAWuWSLKYgwS7PIX+vxRgHwjC+tnugtXYvfnUjbAeDACsSC+/LrmX50G+3yt2pm9HmB6Ypww7yZabJjtVW/dQvKGW6qzTsrZXeXvAtwnKr2wNzwvcv4nu7HTPR9nu7b7Tybl1etQkjTArOGRQTnLq085qcHNapdASAgeQiBBr1EKghqOTL/LEKtNwsu7Cl8d8I4Z5XhkviHwte30t8GC+9ASzPs7pwMAPZ8YkM/xpuAXVXFwcBfMyNmCs7g0/E2J35JSlOP1I8+3disA7w22ULUTs23/OLTNCW4L88CvDjxNawmwkpvmlkKS26lnR1GyjpZMqQlmaBIjkbHKNFJlE7tZBF8x8fRU6tvGNPJJH8zT4R8ZS1AtigEo0jbdQXm60JpT3m/dO4K8HOKwE6DD19dcSFQQcmYzSswpw8DAwPkqnEM4rYMvLobPcfObhR8JXe9ArfYluyGHwsq9gQh1H5/aV+PTOzpM3xOgnqbioqy81fRn7YZybBgDudoEy2p84AvJR3iuqI0xBCikkCuG+Ve+THHauamA9HhgXy08NRKrMdXdXK4Gpaw4rxwUBDs0s1zlZpS4Jc2O9YRa4Pf13jXKLCgUzkClYKMExYtnHLDDS0N1OmeHpAGF4vK7GyVjTVQf00TJpSkJf1T5CWnE5I5sluO0hEE3xFq/Sz8Ob/GJEzy522KvhXlb2P4NyCw8W5srNG8j2S9v4slrSEebL4+dQZo10pJZMbJUC5divr+Sl/mnXM= X-Forefront-PRVS: 029651C7A1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(39450400003)(39410400002)(39400400002)(39840400002)(2201001)(55016002)(6506006)(6116002)(9686003)(3846002)(33646002)(42186005)(478600001)(50986999)(86362001)(53936002)(2906002)(5660300001)(575784001)(2950100002)(189998001)(4001350100001)(61506002)(230700001)(103116003)(25786009)(83506001)(50466002)(76176999)(23676002)(81166006)(8676002)(305945005)(66066001)(38730400002)(7416002)(7736002)(47776003)(54356999)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:AM4PR0802MB2274; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTTRQUjA4MDJNQjIyNzQ7MjM6TUNTU1dicGhMcWJYRVdLL0lZOXhvd0l5?= =?utf-8?B?T1I0V0JHbEloRmthWlFGdU9SaFYvanV3WWJDU200V3VhMVc4dkRZbTlNbmtK?= =?utf-8?B?aXB3R0lJSnoxTjJWcS9WaHNzSmlLS1JHUDdNV2hEb0N4dDFhbWIwcE9EQ2JY?= =?utf-8?B?VjJldE83RFN5N1ZEQmN3aSthT0VsVFFTRFlQaUhMTEFFemVqNFFJZjY0NVh1?= =?utf-8?B?OTdrdm8rMWN3em5PWEVBK0pna2p2UitCS0h6cUQweVQxazVLSThFQ2VOMnFQ?= =?ut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ztS5pYzBG6hEfw4sceQhdxd+/IzYH35rMpZEg==; 24:XXZtjdmUJsut6eRwsVJdIWPTpjmop3P/wzuxGSBg+72r/AFHt3O89nuGcAn9gJsTLGDic4flGoPNEKPfB976Dj0HDMlIaevQqbdp+m6m/UQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM4PR0802MB2274; 7:iiOIjch6f/7MtSn8yUFWRsIJlomDZ9hCZTt+7M8bPbFdB6nRMGbYJJ1cqBU4zmHyl8Qhy3DtpggkwT01qTNkE0jaxtejI8JNrPTiH6MGimhmRRE8wyBllBIVmVANtEo8KBjrWWhh6FEJ0/Rsqe/J2Y6bZWPG4QtDiCPd4uRvrPoCxnz6a6RYgCmjY+4/chxvWECPr5Dg7Fendmct38nA0GtdDkJMF8RRRJMqKJPzNqqwtFMrp8/fM57Bhyvmfz/VzD0WYSmqSi6W4BdmIXgQwDbp7wrS2tv+e7EhYxD61COG78uTZTO0SkriQl4OdECzRZQVjZv7vfOByQA8n9VARw==; 20:/b3h1Yp0Q3qZKyDcKRye7sajrJ098/AVfqMN6MTWcXQh8h3Dza91m8wUP42AVACqxsDE3EJ6opyVk/5ovSxfCZfqVI+OwtBP5GcDAt0GkBGD/LcmTxAd/cZtURF0UImZUIP1u4ZB6cmW81IAxGkQhIqugOL7toXLpc4ih1Tv1Rk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2017 10:32:39.4486 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0802MB2274 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] v3: Check child_reaper without tasklist_lock as we are only interested of it's not zero, not in specific value. 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 | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 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..2a5ec0a00127 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -374,6 +374,23 @@ 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; + if (ns->child_reaper) + get_pid_ns(ns); + else + ns = NULL; + } + task_unlock(task); + + return ns ? &ns->ns : NULL; +} + static void pidns_put(struct ns_common *ns) { put_pid_ns(to_pid_ns(ns)); @@ -443,6 +460,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);