Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1794313ybi; Thu, 20 Jun 2019 04:01:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpHYH0waE3MtsYP3XZxgt3STkpEWAuI3GtT6Ua0xmJ98GblBF7Crb9Bz+j9SnTkQWuDcwg X-Received: by 2002:a17:902:4c88:: with SMTP id b8mr13814368ple.29.1561028463097; Thu, 20 Jun 2019 04:01:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561028463; cv=none; d=google.com; s=arc-20160816; b=uyhywaBabKa0s8CAMmwGBDolRlfEjzElNIU4aZhLbw/G1ytJoWnKphBcKlZGjQ8a2a +Zv3SWzGn9T++GY7Nk2C2SVRRDauryA9NHJdZsFW0WWzF1X5/0zEjKtOyTZKAlRGoLdU /EgnP+b4P2xhePhnT6jJF9/GnoHPhvJ+L2IbHkTnxZEvbSZuBSJwaPTmYWYNzNrJ04dQ 1Y/FBbdWFhOP5SPZAKLGwozDvZy2zFL98iXKvye18dkYy7MozQh/fPTQyJQuafgcLQ6S cgzqQRAnf4/we6G0dgM5MivFcXVMtlbfQNUtltDjrqfcF/F+ZEcjQBPoykfOxGmJqzkF 0guw== 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:message-id:subject:cc:to:from:date; bh=l/jfa91L1z0bg0s/Cqq5RluDiG5/kxOdio3v4JJBJa0=; b=Ous+r5wQ/562X18GcxIC5bGXzov/Nz/oW+s+1LYBZsEJgRzK+CoBDhoeb+IjTSGOkr ZRfH58nB2thYLy+3lPekVmYLKr14xBSZbhOl40ZYGJTkrf3agZF/YasUJCgwOPA58K+R gSArWqhqg2EkPpdA9uLexX3DRcmOLVgAl8lx7DGqLXVPmTqylu3ThlCaJqzaGxQT4upp /Wqq5esxaN1XoFH7xNe1wRFLAgPb3eQfHzcPSyq8U7+W05dkVW1UUCjsOkIV/Dtd2gqc gI/8weKFEHTgYS+1pjW2H/JzkCXg11/PJFmfcke5BJMjCm9RCPg5dCfhVdtxcieJtdAX yLfw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n1si3864476pjc.42.2019.06.20.04.00.45; Thu, 20 Jun 2019 04:01:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726874AbfFTLAk (ORCPT + 99 others); Thu, 20 Jun 2019 07:00:40 -0400 Received: from vmicros1.altlinux.org ([194.107.17.57]:55894 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfFTLAk (ORCPT ); Thu, 20 Jun 2019 07:00:40 -0400 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 72B2472CC6C; Thu, 20 Jun 2019 14:00:37 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 5CE157CCE2E; Thu, 20 Jun 2019 14:00:37 +0300 (MSK) Date: Thu, 20 Jun 2019 14:00:37 +0300 From: "Dmitry V. Levin" To: Christian Brauner Cc: Jann Horn , Oleg Nesterov , Arnd Bergmann , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] samples: make pidfd-metadata fail gracefully on older kernels Message-ID: <20190620110037.GA4998@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190620103105.cdxgqfelzlnkmblv@brauner.io> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cc'ed more people as the issue is not just with the example but with the interface itself. On Thu, Jun 20, 2019 at 12:31:06PM +0200, Christian Brauner wrote: > On Thu, Jun 20, 2019 at 06:11:44AM +0300, Dmitry V. Levin wrote: > > Initialize pidfd to an invalid descriptor, to fail gracefully on > > those kernels that do not implement CLONE_PIDFD and leave pidfd > > unchanged. > > > > Signed-off-by: Dmitry V. Levin > > --- > > samples/pidfd/pidfd-metadata.c | 8 ++++++-- > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > diff --git a/samples/pidfd/pidfd-metadata.c b/samples/pidfd/pidfd-metadata.c > > index 14b454448429..ff109fdac3a5 100644 > > --- a/samples/pidfd/pidfd-metadata.c > > +++ b/samples/pidfd/pidfd-metadata.c > > @@ -83,7 +83,7 @@ static int pidfd_metadata_fd(pid_t pid, int pidfd) > > > > int main(int argc, char *argv[]) > > { > > - int pidfd = 0, ret = EXIT_FAILURE; > > + int pidfd = -1, ret = EXIT_FAILURE; > > Hm, that currently won't work since we added a check in fork.c for > pidfd == 0. If it isn't you'll get EINVAL. Sorry, I must've missed that check. But this makes things even worse. > This was done to ensure that > we can potentially extend CLONE_PIDFD by passing in flags through the > return argument. > However, I find this increasingly unlikely. Especially since the > interface would be horrendous and an absolute last resort. > If clone3() gets merged for 5.3 (currently in linux-next) we also have > no real need anymore to extend legacy clone() this way. So either wait > until (if) we merge clone3() where the check I mentioned is gone anyway, > or remove the pidfd == 0 check from fork.c in a preliminary patch. > Thoughts? Userspace needs a reliable way to tell whether CLONE_PIDFD is supported by the kernel or not. If CLONE_PIDFD is not supported, then pidfd remains unchanged. If CLONE_PIDFD is supported and fd 0 is closed, then mandatory pidfd == 0 also remains unchanged, which effectively means that userspace must ensure that fd 0 is not closed when invoking CLONE_PIDFD. This is ugly. If we can assume that clone(CLONE_PIDFD) is not going to be extended, then I'm for removing the pidfd == 0 check along with recommending userspace to initialize pidfd with -1. -- ldv