Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933420AbdCaPZ1 (ORCPT ); Fri, 31 Mar 2017 11:25:27 -0400 Received: from mail-eopbgr40122.outbound.protection.outlook.com ([40.107.4.122]:17312 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933140AbdCaPZZ (ORCPT ); Fri, 31 Mar 2017 11:25:25 -0400 Authentication-Results: hallyn.com; dkim=none (message not signed) header.d=none;hallyn.com; dmarc=none action=none header.from=virtuozzo.com; Subject: Re: [PATCH RESEND 2/2] pidns: Expose task pid_ns_for_children to userspace To: Kees Cook , Michael Kerrisk References: <149086931397.4388.9604947335273204415.stgit@localhost.localdomain> <149086967937.4388.471494976517194744.stgit@localhost.localdomain> <20170330150520.1bdf20e599ff464bda0776b9@linux-foundation.org> <20170331010409.GA22895@outlook.office365.com> <0825f166-6f20-59a9-45a9-5ffe9009150e@virtuozzo.com> CC: Andrei Vagin , Andrew Morton , Andreas Gruenbacher , Linux API , LKML , Al Viro , Oleg Nesterov , Paul Moore , "Eric W. Biederman" , Andrew Vagin , "linux-fsdevel@vger.kernel.org" , Andy Lutomirski , Ingo Molnar , "Serge E. Hallyn" From: Kirill Tkhai Message-ID: <3f2ec6f5-3d66-15e5-ad3a-a8709a254273@virtuozzo.com> Date: Fri, 31 Mar 2017 18:25:11 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: AM5PR0101CA0005.eurprd01.prod.exchangelabs.com (10.169.240.15) To HE1PR0802MB2283.eurprd08.prod.outlook.com (10.172.127.13) X-MS-Office365-Filtering-Correlation-Id: 3c98eb98-bac4-4006-2216-08d4784a23d6 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:HE1PR0802MB2283; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0802MB2283;3:e9BHpGhrBgFjcsrGGh+k6ky7HaBZtpjQyIiR/jCcRtae53Szp4WtT5oGoOiXIIuTlQBPYjwiZ5bFAu9KQlGSOim/5wRcw3XBJdfo7AW9/AD9+4vzSLKkd7ETWJB8zwG8sjlwGF+GHYQqFrP1upYaQsTCA3zP589jE2ayL6CbFmRmlmD5htdcAGyA2AL+pFNpItsh9a5+i73gxT4wm5sH5Sj6vgNDBOkQD2VE8HMyJ+io5CvUhXS+rIphcSxrKbai3uCdZHNJRMGQObb0Px+Sm1dArNmyKOGYTZbmXR61FbP7eACsd8l9LlvEECcr7NxxNVH7inFxV0rWm6mkYSAntQ==;25:640OQC3YKSTjW1Kg9zk6VkArAyh+eI3WzTGdR6XQoQhzhgJpMlP9T+4VLEx5rSzPGHD+9HCzyM0ytefP0TNSxKV0gWn36YTShQ5O5KJfgZZR2sGBFrrIKyZ4LKR0osAGrgm18FbtvWIPJXusug1YHriv3IR2NpMAYqPh8wHKbuI6sdZKAKgsl9OQi/wSQ0mSRN4hwreJJ6C4M6u2tU/9XTedkXgW/hn+37fB1NncM6mAgCx2Tw8UdL7CEf4VLsLFFllDKBBcVbWKXlxHwgMBNSmhlMcbCl/7T2ODKxhwX2gKcX/NkX2wcc4yevO98FKCcqhSPfW39H9+2uNWvOIDA2e/fs0V+x5+eh26xypcawImY1BQlI9gnh8Cibtxg04l9c4CTKBqcX8sK0chzYbNj3KxItGUkPdcub+6D6Uxk0nX9YWuh3S4RaP7azYoIXqgRcwTdjnCpY4i/Ri4mj95CQ== X-Microsoft-Exchange-Diagnostics: 1;HE1PR0802MB2283;31:DdNI1qvij6dtWe8qmcbeqyD7GkrSDPnbsdi5oiQGpRQd4lTP6ecfuF0iVVLhv2gtJdluZE0niU1lSuUJ8nQAkNCFuySTs8xxWgKk3Q6oE4PDquDP+GtJj/aENH5nasZ1tQlr63XQsAjQWXEYD7iXh73wJfcl01vjI9SY2H97vl6kaublHuaR/C/hvNmAV2SWfSJ3juMAxfirIRm4uoh3fVOePn3qEc0fNOKKclc2gcw=;20:dioRr0P5IkoAkhXC/TOOm6P03rTEXVGUpSO3GAeUlOvQzghFDbs1h63hfvJ0KNsLlcfurTIguhChr36Iw3RIywdeDyEpCUgTpLCR7em86UUmAXkPW0JvDHAWl7rS7SDWB5KD8C644d5nqUmHXZx8s6coMs0Don4RkMkQpF5iIgrJiy7QuqOnSA57wvkwLT99wDa0Ihum0uFP4OxS3gX6qSoyilHPRdpxjr93zrshqGB7/LxEXx9xnjUhqnHf68oR4ehiW2P9B7CKV9uP+lie8M9IFOwVJKv0rIA6/PnFVJHMqOawyetI7eXPqnOIa7OSKt2fdEQ+0AZJRNPEWZ5jcIf5BGrjNc7CqgWdf7gjCa5byXNjZh/W4vdshNw+/CICzEMN5Bu+eKFWrZQ1hibnleuoN37gjUu8Ll7jW3SVXGg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(84791874153150); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(10201501046)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(20161123555025)(20161123564025)(20161123562025)(6072148);SRVR:HE1PR0802MB2283;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0802MB2283; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0802MB2283;4:WE/Eb1sM+ksh/h9CxLDEwovXgZUhMsw1Bj+LXiyztQ7iNn3HSWef+jvaO5JJygx8Ty2n36pJweATOIk+QkSQEKd9XRIKGiTeEW2NMw6R9wla4crqsJDMMY8PPMGcUZqJQlV9r03fn5PrhcMNg8XNEWAOQT7gQs5dSwPsw/I/qwpngnMpH2f+uBvJ6hJ/sFPLybqwqjGY4KDjhvmFB0AVf6PtVc/U3Y6LQhxF8Amxzzp4AOsmd+ahhG1YCTPK6lZfVnhZKXUpwTPGTtngWCm0hanpfo+deCNXERK4Ml9NwRtJOk8COuTgC8Yg136L3MPzihmk/mE1iUOuWjLRSAYOq7O2PLFSwb3SZnb4z7dT/GgGrtfpQRPwd5rg21UN5QdYeK7XveqVlGu7n2ZuM9ZHzjrn96nNThRj0ZSeD+augOLm2YNnZsjpsszZIK2rawNBlWAL9oaoLw4pbAoV5uBIPyTz79gobqJZPf+iTFUR902bHK/j3Tip/ikjqgTm1npxB1vfPNdWvmXjtmPGWRoXBTBaTqli3Je/YzZCL7yjDXkoyMHg95G0PGCVA6lOwPkqCh2NcpraecWcrdlARd2/Ab8DKbSrhxSQQ1jeFPf2+aHPwu4mkMQUrsqmF5K5WVz8aNo7M7+dVW/1ZRGdC7omfW580eBfps8QegQyZ3sfRZy1+E1HNZ47gRpCjzFH9/uXtD84E6F+0KEhn/br07lZJoN51SQf7sjucnNOUAiHNuRvusEIRKYoZfiMC+tZ/tdzyAEOSrYVX7RgoI6IslaQHQ== X-Forefront-PRVS: 02638D901B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6049001)(39410400002)(39840400002)(39400400002)(39450400003)(377454003)(24454002)(230700001)(31686004)(64126003)(42186005)(54356999)(8676002)(50986999)(81166006)(33646002)(50466002)(38730400002)(6666003)(76176999)(23676002)(6246003)(4326008)(53546009)(25786009)(6306002)(2950100002)(93886004)(189998001)(53936002)(54906002)(47776003)(66066001)(65956001)(229853002)(77096006)(6486002)(4001350100001)(2906002)(305945005)(36756003)(5660300001)(65806001)(31696002)(3846002)(6116002)(7416002)(83506001)(65826007)(86362001)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:HE1PR0802MB2283;H:[172.16.25.3];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtIRTFQUjA4MDJNQjIyODM7MjM6dnlhZTdZQ2h0aVhMN0FkOWFuS2t4NnRH?= =?utf-8?B?UW9T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pTlym0xgMaTbm/DiUuh1Ie9SL2Y7Ys1UFEDYI1Oj6ZwWFmD0vpfvcdISg9B4zARKUypSkQ0WhbEuZfcFyBReSFJSvqIC5Ukpuo3yi2IlLq0t+Q6jH0pbSmEHDjfEVqUlHwqBgBU4OrUDKKjjc0o5f6iY/1w= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2017 15:25:17.6089 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2283 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4128 Lines: 94 On 31.03.2017 18:06, Kees Cook wrote: > On Fri, Mar 31, 2017 at 2:45 AM, Kirill Tkhai wrote: >> On 31.03.2017 04:04, Andrei Vagin wrote: >>> On Thu, Mar 30, 2017 at 03:05:20PM -0700, Andrew Morton wrote: >>>> On Thu, 30 Mar 2017 13:27:59 +0300 Kirill Tkhai wrote: >>>> >>>>> 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] >>>>> >>>>> --- 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 >>>> >>>> This interface should be documented somewhere under Documentation/. >>>> But I can't immediately find where the /proc/pid/ns/ pseudo-files are >>>> documented... >>> >>> I know that they are documented in man7/namespaces.7 >>> >>> https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/man7/namespaces.7#n187 >> >> I suggest the below patch, but it's too early for the man description till >> the feature is in mainline, because the man page requires commit id of the feature. >> >> [PATCH] namespaces.7: Document the /proc/[pid]/ns/pid_for_children file >> >> Signed-off-by: Kirill Tkhai >> --- >> man7/namespaces.7 | 10 +++++++++- >> 1 file changed, 9 insertions(+), 1 deletion(-) >> diff --git a/man7/namespaces.7 b/man7/namespaces.7 >> index 6dfceaa2a..06041774f 100644 >> --- a/man7/namespaces.7 >> +++ b/man7/namespaces.7 >> @@ -125,6 +125,7 @@ lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 ipc \-> ipc:[4026531839] >> lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 mnt \-> mnt:[4026531840] >> lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 net \-> net:[4026531969] >> lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 pid \-> pid:[4026531836] >> +lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 pid_for_children -> pid:[4026531834] > > Minor nit: this needs to be "\-" for the "-" Thanks, Kees. The updated version is below: [PATCH] namespaces.7: Document the /proc/[pid]/ns/pid_for_children file Signed-off-by: Kirill Tkhai --- man7/namespaces.7 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/man7/namespaces.7 b/man7/namespaces.7 index 6dfceaa2a..b4e9b13f0 100644 --- a/man7/namespaces.7 +++ b/man7/namespaces.7 @@ -125,6 +125,7 @@ lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 ipc \-> ipc:[4026531839] lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 mnt \-> mnt:[4026531840] lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 net \-> net:[4026531969] lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 pid \-> pid:[4026531836] +lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 pid_for_children \-> pid:[4026531834] lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 user \-> user:[4026531837] lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 uts \-> uts:[4026531838] .fi @@ -186,7 +187,14 @@ This file is a handle for the network namespace of the process. .TP .IR /proc/[pid]/ns/pid " (since Linux 3.8)" .\" commit 57e8391d327609cbf12d843259c968b9e5c1838f -This file is a handle for the PID namespace of the process. +This file is a handle for the PID namespace of the process. It's +permanent during the whole process life. +.TP +.IR /proc/[pid]/ns/pid_for_children " (since Linux 4.12)" +.\" commit FIXME +This file is a handle for the PID namespace of a next born child +of the process. It's changed after unshare(2) and via setns(2), +so the file may differ from /proc/[pid]/ns/pid. .TP .IR /proc/[pid]/ns/user " (since Linux 3.8)" .\" commit cde1975bc242f3e1072bde623ef378e547b73f91