Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933515AbdC3K2d (ORCPT ); Thu, 30 Mar 2017 06:28:33 -0400 Received: from mail-eopbgr10125.outbound.protection.outlook.com ([40.107.1.125]:31928 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932582AbdC3K2I (ORCPT ); Thu, 30 Mar 2017 06:28:08 -0400 Authentication-Results: hallyn.com; dkim=none (message not signed) header.d=none;hallyn.com; dmarc=none action=none header.from=virtuozzo.com; Subject: [PATCH RESEND 2/2] pidns: Expose task pid_ns_for_children to userspace From: Kirill Tkhai To: , , , , , , , , , , , , , , Date: Thu, 30 Mar 2017 13:27:59 +0300 Message-ID: <149086967937.4388.471494976517194744.stgit@localhost.localdomain> In-Reply-To: <149086931397.4388.9604947335273204415.stgit@localhost.localdomain> References: <149086931397.4388.9604947335273204415.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR09CA0054.eurprd09.prod.outlook.com (10.174.50.22) To DB6PR0802MB2277.eurprd08.prod.outlook.com (10.172.227.150) X-MS-Office365-Filtering-Correlation-Id: e4235ef0-1b30-46c0-7202-08d477577392 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:DB6PR0802MB2277; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0802MB2277;3:FiLxALTS4/4jyw5jovMiZkN0K22JBIILkGeX4e7izhDCd2pHodjAbqSYWjhMKecVMXDZIMI0zFw9nmk46ERZP5iIUY7insppUibQg1UFlidiBdq+xkD/BEgES54HNPN4typTjSx3vqIE6P/zA8rCq0n7uqV9+3GO4nw3WBb+XzjZS+o9lRbMIICdOx0Hwby9A3W4ZyvlgAs1LurfJUmLMDgmqSkwpSx8JcLl482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X6e+YppKY4WkN3oBLHJv2OxcZluXxa1z4OobF9iGb+0lghYC6SEE2LWjUtzRJGEOtt91B9eoKsJmK6Id3r/DfJTLhRO4L+zYEwru06TYpBqi/BHZAeZLf0N14xZfSK6ZufHKHtInPngQ3+PMiK7oL/3V8atub0t4bo+53YJZK5cR7wee8wKVUAtgCtqJ3I/NY0lwvZsN9g6NawNpJ8MmOS5Q= 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)(6041248)(20161123555025)(20161123564025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(6072148);SRVR:DB6PR0802MB2277;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0802MB2277; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0802MB2277;4:NR1kFg2TSJRZ47HXlIQIdFflqygQ4M0SQZJlBYTphQOpDWz2UH3zixhGClGlqBBp+BUc8Z/8UGNSbFKyD5zkhEWxZsp+VATTIK1oZBnMugUYlsx4WLRRKO81WlL/D5PmoBD5+b77WkwPsl4n4YWlcB8FwpJ5PY89FA7o0P+L4T5psQIbK1lIA6HgToG0lGsC/TiYX4oSLF0zcZ7rmH9BuIFpxTgkRwPAkGwCKqAToJHlf2f6NttxuyWJTZ8zsdFV+TKn5GIAA5safZnsdCENXvtuuxRSCCoccR+K0urCOK8PGq5aZRuWOL2qib1ZWSHlZtEmMANnfVyggvqPIqko9kdjYDwTQMNaZgOjEEUoi61PmAe0XsV0mHNC8N3m1geKbe8dP2XyXYY2EF0V9dbMpv5SeIP0X05c8OIJ4OC52ovpQk/filsiXVdQx+AEHryw2jUc0bCeC1wkY14sGKRRonol1MgMc/khfM9X/Pnxpx+sgC0WJwP5rKKDSXDhm1z3QvbDlbKorpEm217TUHenDMWw9t+CzbWkP3xHKiRDzfoWK2V98RXC2G6z5j7CIhAgoGvfAXsfP3RphuetK2/WbzNUj8gvg122Uu/l0RkWS/aiAFLmnTilImgImwDgLdWpSEZxyjzHYB3+JEx4lsgV07RoPw9BPN4O1YK93OegX8U= X-Forefront-PRVS: 02622CEF0A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6069001)(6009001)(39840400002)(39450400003)(39410400002)(39400400002)(305945005)(23676002)(7736002)(76176999)(54356999)(3846002)(50986999)(6116002)(86362001)(42186005)(575784001)(189998001)(5660300001)(230700001)(7416002)(2201001)(4001350100001)(38730400002)(83506001)(2906002)(6506006)(61506002)(55016002)(25786009)(9686003)(33646002)(103116003)(8676002)(66066001)(47776003)(50466002)(81166006)(6666003)(53936002)(2950100002)(921003)(217873001)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR0802MB2277;H:localhost.localdomain;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtEQjZQUjA4MDJNQjIyNzc7MjM6K01UbTNaUnU0WHpoTXNrbjN2cm1kamRz?= =?utf-8?B?S2o1M28yaDNCWG94ejVDMDV5MXdRWGx4bGFLV3J2eVA0QkxSbit1VEdiR1VJ?= =?utf-8?B?bGVvRGppbXRIZUpBRDVzTFdZYXlYMDFBT2J5N3dwWkxrYUlRdFA3S3BGZHlR?= =?utf-8?B?V3g1L1hubVZtQTV5L25oOWFKQUdKYmZweTh4R1l3Qmx2cjgzVHozZjVDNjc2?= =?utf-8?B?OG1xdndqdnVPVkVUYW5LQmVYYi9sV3FZVlR4ajBPT2ZYbzEzUHVWaG5XMHVa?= =?utf-8?B?dHpNOThJd1hsRm5pV2wyQ2NVN2ZvenFyWVZ2NEhaWExXQlpUQ3BQOE1BMTdN?= =?utf-8?B?ZGJpSjNRQzcreXdIVU5GS1RoWHlIdWxsRERoYkdLTDZuempUYzhPcGxNNmN6?= =?utf-8?B?Zmo2eWhUNStmUUVublVKek8yY2U1MDVmMEhQL1pvM0txb2V6cjFyUUpDT0pQ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TYUdLcEIv?= =?utf-8?B?ZE5uWlI2RUIzZzAvVUNHR1ZWanBSVlN3Si9VYlNSWnNnQ09VNTlyNzhkU3VZ?= =?utf-8?B?TzNnYnRrRTJkajdRWGpWeW5kM2FJVFlZdUNOZElkemtuWjJnZjZJaDhXOTZq?= =?utf-8?Q?16RT7N8VnDYyLRYdquWGQ3b8VAg=3D?= X-Microsoft-Exchange-Diagnostics: 1;DB6PR0802MB2277;6:lgP18voR6M2NO/rCo7SCdmegl5LkYqU+CxapT5+/qsmQoy6RgIZD8d9D/RA1KI64XaEb7WW1ww00nrnyWjYeVa40hUZRy+ifMtfkjQHk74j/MDKYjdMb7BFaH6N1zQhrIjAfsWdnUHpOLlCxczr82SS12nH5VcaLVaZouqude6q02UTjjRI32kadtO9LR46bdZvlU+S/1QsoPIppi4h/ec9TghSP6alx0PUx8ELHB+6hhS/t7cDgG6llPXaxiaQb59u08epAxtJxzzMbjH9nJWru0zgXZZYfVLGSfMg8aEGHrdc2i3N6KLjta1hyte0bfYrfa+Phff4VAKOGmOR2iMXHy1TnD1oURmnRzunI2jTo1IpZzMZKZCvMaTMfLZ5OBBcx7asvve0fxwT4glX/TQ==;5:V7MxHhR8iJjTDNrjOkjkV33hfGoSww1Nh0uob6RHvLdA3622hjs0FLS8b6F6BSYHSQCQup2sbTwrc8R2rZ2EDkPmMQkucLd/DBq2UNjzsiSn499/wiMxUGVax9yYiyGek7Gkc8NR2zcEBJuxlc9ZJw==;24:bMeOEYCmgGWs/YEalT6nWaFMlndusPblL3XpeMklZLdRwsRNEBx3xbHrSW9F5oKTPiuGANdQNOotXeOc1qL3OBf6V49WdiempDzVyPMhYxk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0802MB2277;7:lV2IL+u8045/sIXn5Ga/8zExf2s4J0ofeWYIP2xDOFCbqeAONj+T1IzQ+Lrz6H8Vz3tDYYcqh9l+fNHe9VEStWub7mHSuCsQEcoGG5HUaBLcLJ59z7KYTFaoHElMmtmTutE6FgEwgpf2a4FDakv0ZCr/7+5rh2TfybcarPELkUO2JDruYfktpUc0lKck7EnzmY1jb8NzABj60kMw5OzEMnDuaEUmuynCgB2u6ptAVD8kZ8Hrx/YLjU+ulLefkVSl8EgH0Lnw487IyX5TYQQlFD45gt64PfpegXurZ5uptB+H4q156QA+fDrs4jyiFmP9qwzhwkoDhvvSZxzd1hl8yw==;20:kV5y/vVZOnm5ZswDdkoErBOvJ+JW+bryRTZxpCU65cJMc/uUIB8u4CKTghTAeEq8GuV5mq8ZKe3qebPExzsETBH8TiS0nHotH1+bNGByL/pwUFblpZd6fn1B4DqeGWGPCR6+/t2sqiVeAa26PrA5BHP+Tr/409wGPnz+XUmovgM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2017 10:28:03.4316 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2277 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3071 Lines: 90 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] Signed-off-by: Kirill Tkhai Reviewed-by: Cyrill Gorcunov Acked-by: Andrei Vagin --- fs/proc/namespaces.c | 1 + include/linux/proc_ns.h | 1 + kernel/pid_namespace.c | 25 +++++++++++++++++++++++++ 3 files changed, 27 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..4dd02ff0b0bd 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -374,6 +374,20 @@ 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); + + return ns ? &ns->ns : NULL; +} + static void pidns_put(struct ns_common *ns) { put_pid_ns(to_pid_ns(ns)); @@ -443,6 +457,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);