Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp512717ybt; Wed, 24 Jun 2020 04:57:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwukg+DvJ2TMMRPqOhz/D8eDHalJ1YmO//AdSXHaNgzsZADFdc8mgapRgSuJb6kt7mHI2ky X-Received: by 2002:a05:6402:7d4:: with SMTP id u20mr25876768edy.30.1592999849233; Wed, 24 Jun 2020 04:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592999849; cv=none; d=google.com; s=arc-20160816; b=lT4fYQ8XJ+q8zObZ3K/bBzQBvzcPTcsff0yl8Soxk7kJe7DT+/3F2/f4CHomdt8wcp biXQm+kNZgjRfRlj3daLbnEBfTZoeJqXKYfjgeDEEBknJlOxlP/rGKLzppfLozuGtFPs x89dUGUVA2qJNFmMRIgppGPteVGILX4irBATiS3BK4f4DlMhyfN9mDCFAozD5XC7ORKg Vbam6NPtLZ8Zf8V8MziijADHgFoWHJwb5A4z8yF29tI9LF2+vGkCZ4oMi27rC1rCTnuG /7HPhTmGGW/f+QZR9+hcQ3veVCzcxarsP7Hl6IzoDDQdJ3eI3A7oUtrkLy3vUyTcOYyF CQyg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ll5d/wMRlo+kn7OGjoKRZumq7pH8bu9fx+7npkxaktw=; b=dfBsYYMzkWo4rmFxqtn9wx0qSILcpxW4cDCerwlZA9qnwlqXs7Q3Y3A4bk+jd9Ye5X CN7DXLTwl0vrPCjCWp5cFHbSPi6MM7Rzr4RAeSWTAMUinCU5HoDdydhGUoEK4unSw8Yn laej6FL/EXvIyXL4JPpJTIX0T4d9jSfRGfm/q9Tbk4M502a+iXqi7hQHqe+d6Nw6+4cc zp93kixrcS84c7+hpekAyHtGqLZfJ+bUoiUx00TDBdoUSLOEsdvFOfOnDHlOjmY5Y/hr +rFDwo+wA0ZsW/vRQZciLkKfbJf1fxEcHH/Dfdlq5CfKzi3Ens4l9wRT3HLuU/mY8gW0 uKNw== 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 l12si13794508ejn.435.2020.06.24.04.57.05; Wed, 24 Jun 2020 04:57:29 -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 S2403828AbgFXLzC (ORCPT + 99 others); Wed, 24 Jun 2020 07:55:02 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:59042 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403776AbgFXLzB (ORCPT ); Wed, 24 Jun 2020 07:55:01 -0400 Received: from ip5f5af08c.dynamic.kabel-deutschland.de ([95.90.240.140] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jo3zV-0001JU-Me; Wed, 24 Jun 2020 11:54:57 +0000 Date: Wed, 24 Jun 2020 13:54:56 +0200 From: Christian Brauner To: Michal =?utf-8?Q?Koutn=C3=BD?= Cc: linux-kernel@vger.kernel.org, Alexander Viro , =?utf-8?B?U3TDqXBoYW5l?= Graber , Linux Containers , "Eric W . Biederman" , Serge Hallyn , Jann Horn , Michael Kerrisk , Aleksa Sarai , linux-api@vger.kernel.org, systemd-devel@lists.freedesktop.org Subject: Re: [PATCH v4 2/3] nsproxy: attach to namespaces via pidfds Message-ID: <20200624115456.rvzlgn77jol2a2oc@wittgenstein> References: <20200505140432.181565-1-christian.brauner@ubuntu.com> <20200505140432.181565-3-christian.brauner@ubuntu.com> <20200624114437.GA117125@blackbook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200624114437.GA117125@blackbook> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 24, 2020 at 01:44:37PM +0200, Michal Koutný wrote: > Hi. > > On Tue, May 05, 2020 at 04:04:31PM +0200, Christian Brauner wrote: > > -SYSCALL_DEFINE2(setns, int, fd, int, nstype) > > +SYSCALL_DEFINE2(setns, int, fd, int, flags) > > [...] > > - file = proc_ns_fget(fd); > > - if (IS_ERR(file)) > > - return PTR_ERR(file); > > + int err = 0; > > > > - err = -EINVAL; > > - ns = get_proc_ns(file_inode(file)); > > - if (nstype && (ns->ops->type != nstype)) > > + file = fget(fd); > > + if (!file) > > + return -EBADF; > > + > > + if (proc_ns_file(file)) { > > + ns = get_proc_ns(file_inode(file)); > > + if (flags && (ns->ops->type != flags)) > > + err = -EINVAL; > > + flags = ns->ops->type; > > + } else if (pidfd_pid(file)) { > > + err = check_setns_flags(flags); > > + } else { > > + err = -EBADF; > > + } > > + if (err) > > goto out; > > > > - err = prepare_nsset(ns->ops->type, &nsset); > > + err = prepare_nsset(flags, &nsset); > > if (err) > > goto out; > This modification changed the returned error when a valid file > descriptor is passed but it doesn't represent a namespace (nor pidfd). > The error is now EBADF although originally and per man page it > was/should be EINVAL. > > A change like below would restore it, however, I see it may be less > consistent with other pidfd calls(?), then I'd suggest updating the > manpage to capture this. > > --- a/kernel/nsproxy.c > +++ b/kernel/nsproxy.c > @@ -531,7 +531,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags) > } else if (!IS_ERR(pidfd_pid(file))) { > err = check_setns_flags(flags); > } else { > - err = -EBADF; > + err = -EINVAL; > } > if (err) > goto out; > > I noticed this breaks systemd self tests [1]. Yep, I already have a fix for this in my tree based on a previous report from LTP. It's sitting in linux-next: https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=fixes&id=e571d4ee334719727f22cce30c4c74471d4ef68a with selftests: https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=fixes&id=86f56395feb2b106b125c47e72192e37da5dd088 I'll send it to Linus this week. Thanks! Christian