Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3058626ybz; Mon, 27 Apr 2020 09:14:54 -0700 (PDT) X-Google-Smtp-Source: APiQypJpn+ytaLLi5HLFIf//AHrGsO822g0QwDQDETwGj31uuYJDsnpzqkg0H8kDWobcBD3+XwYJ X-Received: by 2002:a17:907:b11:: with SMTP id h17mr21504409ejl.371.1588004094004; Mon, 27 Apr 2020 09:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588004093; cv=none; d=google.com; s=arc-20160816; b=UBwSz24IG0W/xlJbZVxnT14WfIRdk1fkraBE94dMgY6/jbFSWNTdu5CRd+cD/lOr4k DPyZQpjyVCNxIwLtV7xWrLBqpO+f9Ol7dPl/R4E6+eQFQ1F3WnNIWGVoIU760sHP+lC+ E0oGvHaZBYyCAEQ6CmdGq+oUj7Vj0x5knivCPPx7V0GWpRFZpYZO2TubkRC0rCCnwFcU 9OwoxTFqzFnGOxvvyf+C5BhsrMA6W8+6bYEJJ1T6xk/QrlDYbWTgLEiyv1e9tMRS9OZS /V2HC/HnpC725B2Qdu6USBRuhIdMebFg3myUB2sENY3fyS1pppMvVCA7CNlsY32zyCHx 0tMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=eYwpiGBCHeE8+vkbeq1uwgdekT+cIQHOIlEn2fXi5b8=; b=zF4J79OkUBo+6Ep4sMkS+JSv2PP/FeKQVc2YOHLU9wQUpz53sln+fQN1TbDxS5Pkt0 XOJzO118yTPRXSed9l2OQFpc2BcBTS8c7BQmhwe4nnzeMb+HlRuZIFw2rQdm1R2Qz+Wx maEc76p/QhYgz/CNh+7ZD4VkBvxrTYoeFR/VwtzUL5XEg3f1wtsyx8fIctylep1T4f5z M1iO4zkRG/ctuWM7gZWuRctzlfLwB8CDuydUkLDDob7BEO9ohgbSi5RSZG9PvA0/exxL lJsoJniLwJ43n3ReNcNePI4MdFVisPC++diM462zf0eEcXtJBw35pfR5IaoigFA1Zs6e piNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g7si5250ejf.410.2020.04.27.09.14.30; Mon, 27 Apr 2020 09:14:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728169AbgD0QLv (ORCPT + 99 others); Mon, 27 Apr 2020 12:11:51 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:36130 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726000AbgD0QLv (ORCPT ); Mon, 27 Apr 2020 12:11:51 -0400 Received: from ip5f5af183.dynamic.kabel-deutschland.de ([95.90.241.131] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jT6MG-0007ay-2S; Mon, 27 Apr 2020 16:11:48 +0000 Date: Mon, 27 Apr 2020 18:11:47 +0200 From: Christian Brauner To: "Eric W. Biederman" Cc: linux-kernel@vger.kernel.org, Alexander Viro , =?utf-8?B?U3TDqXBoYW5l?= Graber , Linux Containers , Serge Hallyn , Aleksa Sarai Subject: Re: [PATCH] nsproxy: attach to namespaces via pidfds Message-ID: <20200427161147.6mtsweiw4nrq3cl6@wittgenstein> References: <20200427143646.619227-1-christian.brauner@ubuntu.com> <87sggpeyy4.fsf@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <87sggpeyy4.fsf@x220.int.ebiederm.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 27, 2020 at 10:21:55AM -0500, Eric W. Biederman wrote: > > I am still catching up on the what exists for pidfd. Do you have a way > to safely go from a pidfd to the corresponding proc directory? Yep, that's possible. The pidfd's fdinfo file contains the same format for the Pid: and NSpid: fields as /proc//status. Here's e.g. what systemd is doing currently: int pidfd_get_pid(int fd, pid_t *ret) { char path[STRLEN("/proc/self/fdinfo/") + DECIMAL_STR_MAX(int)]; _cleanup_free_ char *fdinfo = NULL; char *p; int r; if (fd < 0) return -EBADF; xsprintf(path, "/proc/self/fdinfo/%i", fd); r = read_full_file(path, &fdinfo, NULL); if (r == -ENOENT) /* if fdinfo doesn't exist we assume the process does not exist */ return -ESRCH; if (r < 0) return r; p = startswith(fdinfo, "Pid:"); if (!p) { p = strstr(fdinfo, "\nPid:"); if (!p) return -ENOTTY; /* not a pidfd? */ p += 5; } p += strspn(p, WHITESPACE); p[strcspn(p, WHITESPACE)] = 0; return parse_pid(p, ret); } > > That would make this setns work just an optimization. A nice one but > just an optimization. Hm, I tried to describe how it's not just a worthwhile optimization because it gets the number of syscalls down from 14 to a single syscall which is kinda excellent for something like attach/exec into a container which is a fairly common operation but it also gives us a couple of other nice properties such as atomic attach and appearing in all namespace at the same time similar to clone with all namespace flags set. Thanks! Christian