Received: by 10.192.165.148 with SMTP id m20csp287374imm; Tue, 24 Apr 2018 22:38:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx49zVSt7Z8NPyCcKtPyISgh3lzxMf5PbyLLO4Vd4e8yDhgpXX43T1imHs7/z4tG/j1bbE+S8 X-Received: by 10.101.102.143 with SMTP id b15mr22008649pgw.183.1524634703217; Tue, 24 Apr 2018 22:38:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524634703; cv=none; d=google.com; s=arc-20160816; b=irKVuEf7ASi0thD/TSYy3cR0RQVdMCTfWe8hmuiMURhdQaAxCrS/W3/AdJYaXlKdC1 eDPtD/AMQZt0C/oinDVSUtBS7QiimhQsb3OgiqvteUB6o9rzL2WkOJbLf+oU7BUrnbaq fneSvR6Sa6kQR0mV+OeDMPqYDYpgxYEuR7cb6E/mZL6t9g1BVm/0SecStrvGGi84sDzW oZ4lyQbI4cnJrbaw/TM1/sHPFVQi38/TOlgXVBDF2PuyVHirZDcRyP8OLd0JdHxALgJ9 66de/wTy9ow7e1sf6EvQucJn4LPCg8sLVFtG0O3hO93LP1Z0rQGrb39Q5J+GHYvx9cyu 3GAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=7ASboPGqZKr+abSGZMc5y/wrKDrzBpFusKnQgTuBqnQ=; b=ERsNqZU0M8YHfSIxsyNlLSeT/QGOvUjpkikA8m96uc+ZrQ/V60gV0WdxOqQe44moD/ CySfPXcV5vTmHoXS2D0/uiPjR50FtzZBIFduWANc4A8uqzK85VocxTvKuabWq6UJlc9g L4UU8z+C1yZSM7BmS24QR16bTbJmD0jkp0JhbYn4OO5HQovVEskjdL5n2d3+hanKcwW4 mWhQkmOrYJfpeIpjwQIJMPlNNaItNALkyoCUDk1YHLl8S1tQaWL/J9skNXmIo2T4MelF +aBHmkP8gIAvJ6Hl0mTZSSoBJNCyhCTMEwiKRgCaFiBoWbgzOL7gkOX1RwWIJ6xfMEF4 JO5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=oDcyy/RI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q23si11240826pfj.8.2018.04.24.22.38.08; Tue, 24 Apr 2018 22:38:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=oDcyy/RI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751283AbeDYFg5 (ORCPT + 99 others); Wed, 25 Apr 2018 01:36:57 -0400 Received: from forwardcorp1g.cmail.yandex.net ([87.250.241.190]:36816 "EHLO forwardcorp1g.cmail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750929AbeDYFgy (ORCPT ); Wed, 25 Apr 2018 01:36:54 -0400 Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::30]) by forwardcorp1g.cmail.yandex.net (Yandex) with ESMTP id DE2F921744; Wed, 25 Apr 2018 08:36:51 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtpcorp1o.mail.yandex.net (Yandex) with ESMTP id D62EC2440DEB; Wed, 25 Apr 2018 08:36:51 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:40c:1d16:36aa:f3f9:c229]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id YqoYeSrNAz-apWuxK2v; Wed, 25 Apr 2018 08:36:51 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1524634611; bh=7ASboPGqZKr+abSGZMc5y/wrKDrzBpFusKnQgTuBqnQ=; h=Subject:To:Cc:References:From:Message-ID:Date:In-Reply-To; b=oDcyy/RIpPChmAlb0xi153WGHFQl4NJ1vrmB7rbPMTmnFZqrqk1dVA1z1X0wop8Jm xBiQ58eA8UOb61fPHKtPNlZbzJWq87nTE5cWHNScWr8IU6U/YdeKebhpbRCi9ovnXA tORhAxxuf7M+GNXl7svgehpA6fNyh2MDIOQM42gI= Authentication-Results: smtpcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: Re: [PATCH RFC v5] pidns: introduce syscall translate_pid To: Nagarathnam Muthusamy , "Eric W. Biederman" Cc: linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Jann Horn , Serge Hallyn , Oleg Nesterov , Andy Lutomirski , Prakash Sangappa , Andrew Morton References: <152286911105.615669.14053871624892399807.stgit@buzz> <87h8oqhagl.fsf@xmission.com> <112c7cac-1982-3a2e-ffc0-878bc5ae4bb6@yandex-team.ru> From: Konstantin Khlebnikov Message-ID: <778ab3d0-b6bc-fdb5-669a-40222e5020d4@yandex-team.ru> Date: Wed, 25 Apr 2018 08:36:51 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: ru-RU Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23.04.2018 20:37, Nagarathnam Muthusamy wrote: > > > On 04/05/2018 12:02 AM, Konstantin Khlebnikov wrote: >> On 05.04.2018 01:29, Eric W. Biederman wrote: >>> Nagarathnam Muthusamy writes: >>> >>>> On 04/04/2018 12:11 PM, Konstantin Khlebnikov wrote: >>>>> Each process have different pids, one for each pid namespace it belongs. >>>>> When interaction happens within single pid-ns translation isn't required. >>>>> More complicated scenarios needs special handling. >>>>> >>>>> For example: >>>>> - reading pid-files or logs written inside container with pid namespace >>>>> - attaching with ptrace to tasks from different pid namespace >>>>> - passing pids across pid namespaces in any kind of API >>>>> >>>>> Currently there are several interfaces that could be used here: >>>>> >>>>> Pid namespaces are identified by inode number of /proc/[pid]/ns/pid. >>> >>> Using the inode number in interfaces is not an option. Especially not >>> withou referencing the device number for the filesystem as well. >> >> This is supposed to be single-instance fs, >> not part of proc but referenced but its magic "symlinks". >> >> Device numbers are not mentioned in "man namespaces". >> >>> >>>>> Pids for nested Pid namespaces are shown in file /proc/[pid]/status. >>>>> In some cases conversion pid -> vpid could be easily done using this >>>>> information, but backward translation requires scanning all tasks. >>>>> >>>>> Unix socket automatically translates pid attached to SCM_CREDENTIALS. >>>>> This requires CAP_SYS_ADMIN for sending arbitrary pids and entering >>>>> into pid namespace, this expose process and could be insecure. >>>>> >>>>> This patch adds new syscall for converting pids between pid namespaces: >>>>> >>>>> pid_t translate_pid(pid_t pid, int source_type, int source, >>>>>                                  int target_type, int target); >>>>> >>>>> @source_type and @target_type defines type of following arguments: >>>>> >>>>> TRANSLATE_PID_CURRENT_PIDNS  - current pid namespace, argument is unused >>>>> TRANSLATE_PID_TASK_PIDNS     - task pid-ns, argument is task pid >>>> >>>> I believe using pid to represent the namespace has been already >>>> discussed in V1 of this patch in https://lkml.org/lkml/2015/9/22/1087 >>>> after which we moved on to fd based version of this interface. >>> >>> Or in short why is the case of pids important? >>> >>> You Konstantin you almost said why they were important in your message >>> saying you were going to send this one.  However you don't explain in >>> your description why you want to identify pid namespaces by pid. >>> >> >> Open of /proc/[pid]/ns/pid requires same permissions as ptrace, >> pid based variant doesn't have such restrictions. > > Can you provide more information on usecase requiring PID translation but not used for tracing related purposes? Any introspection for [nested] containers. It's easier to work when you have all information when you don't have any. For example our CMS https://github.com/yandex/porto allows to start nested sub-container (or even deeper) by request from any container and have to tell back which pid task is have. And it could translate any pid inside into accessible by client and vice versa. > On a side note, can we have the types TRANSLATE_PID_CURRENT_PIDNS and TRANSLATE_PID_FD_PIDNS integrated first and then possibly extend the > interface to include TRANSLATE_PID_TASK_PIDNS in future? I don't see reason for this separation. Pids and pid namespaces are part of the API for a long time. > > Thanks, > Nagarathnam. >> Most pid-based syscalls are racy in some cases but they are >> here for decades and everybody knowns how to deal with it. >> So, I've decided to merge both worlds in one interface which clearly tells what to expect. >