Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp525692pja; Thu, 7 Nov 2019 00:56:39 -0800 (PST) X-Google-Smtp-Source: APXvYqyVnfSPl8HEOFIAH6XyVRUyz8uFDfBtl/QMFOTI28tE/L0hwU50VgPuu36GsNJkWuD6omII X-Received: by 2002:a17:906:73d4:: with SMTP id n20mr1914234ejl.45.1573116998898; Thu, 07 Nov 2019 00:56:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573116998; cv=none; d=google.com; s=arc-20160816; b=cFrYEgWKugk51Q3+VrdsmMefm/jL59RoEU6Y20ebompzzuasj5UMIUfiH9gwbp/l1I fINFrELoM9XHzUgL+m3m4/8KAbMVi8fFcnbvkkINNgasurrPptfuxf63ZBIJaBXH1IUO EAQQPWQIpqM+hnCTS7bYCa7CZNfIgEwAWMHPq4l5qmt+1bLy6IeAdXsC0uaCf7EJOLah oGmgZEIQJYmYFn0DEJ0FCyhA7/iJ0sjGZkteKyI7rsSxDnOEAQ1xQ2BFvpmTu3Ez5FWs KE7DWvdyKygpvr3cOsK5Dl6SA9jRkGkea6HJj+VTRkpWK+sHF1IpLGIRso6LssTsKdiq RCBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zWZb6GLCF2st+ZVn+OJmwleeG1odyNOnzVdWxMN71m4=; b=neJwQUrvaifARzsF0DuRSBJdpwOzS1aBiB9DbY47sYLq1JSHzoZEwlNj7p0d2EJHRj YmOfdpwik7CQwvt7T5bjuSY79B2A+9SMa+SwwzfkYlVu4UiaugtikWj6SrEzSxSZrVkN ZYOj6TknPY3s6XASVzCiC4IqjC+LbepDwPsokenRv+wafjmF5kXvoJx/iZS36p6YKBhg AGOdFuj+b4ahChdXVVLxT05zZHAT0MWKUCwXKpvQWZzQ5C+X0H+eUe8rHOH3ioxGKnab ky9eOElNx93VGcBYsFCn7ic8SfKbfc6iR+FnWVAIRyZj4oGLtE7uaq/2aWVTsPoOotz2 iByQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=k2Zi5ilU; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oj22si1075400ejb.230.2019.11.07.00.56.15; Thu, 07 Nov 2019 00:56:38 -0800 (PST) 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=@google.com header.s=20161025 header.b=k2Zi5ilU; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733228AbfKGIzi (ORCPT + 99 others); Thu, 7 Nov 2019 03:55:38 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:41385 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727300AbfKGIzh (ORCPT ); Thu, 7 Nov 2019 03:55:37 -0500 Received: by mail-lf1-f68.google.com with SMTP id j14so956100lfb.8 for ; Thu, 07 Nov 2019 00:55:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zWZb6GLCF2st+ZVn+OJmwleeG1odyNOnzVdWxMN71m4=; b=k2Zi5ilUpvfwvkE4Ppxa+x0nf4km4BOuvWm1ykPz7BHyrgqo9vEkTpio3e+6YeSAiA ksg0hvGFAxJJ5+A1qVHYbExIOTneSQo46Sclk8UiCKSz3NT2s4jWy4p2tAEvwQrmNNiU R1dMTOqkY/lBDgJo9yps5cz+dnI+fVkq6IK2r1jtC5lneKbhlws47UcUOwdRPKltMqm6 zij//x+VBfeyEyoCWdveF8tUyAQEZ/iEK//xFdiRYEFxUGp0LG7WkmOsphoK1smcLmLN NJv5g+5Rf59q8D3VZyo4H3tIiMq2sFCIea6ZVnCBi3GTqfgWNkPBXG3iEIDBsP1axhe2 e4hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zWZb6GLCF2st+ZVn+OJmwleeG1odyNOnzVdWxMN71m4=; b=kf9ejgmSM2vzcO1r6vIThB/yWtRTC9jQl1K2XcEeHm9WMUjj8uXoCnKx8/xYVMe1mb cf+uT6fWBMrbx2ZIOWCkwXmkhnfM8oYP/cUQOU0TDf2ysDmCJw5oFAoEBkpWo8/5JCix sTR6FNATBzY5DZZmW2pVF+HINyniTr3xCOrdIsCAHeIFlZVBTIe8CWmbna1BdbDSgVnv gpUV/Vd5ERTCn1vmlr93UGPZHHPck5yQ1xRvtUyNkVxZmSkV4f1MbOTBYEIQ92T/t2Hc mDLB34ILuKSlqk3Jyg78Js1W8OCo2eW9RlFt3S8Aj4Hhv8KVdnsGld3NlhGCybBGgfAX QV5Q== X-Gm-Message-State: APjAAAWfx7O0swUCjs3iV7KgNR7nlU1n/30AxHn2fJ+P4jX1VcDzKcpT /JkJ9WfXILetmNNsll5QX1YJlnq1Fi957IJ7qNy5Yw== X-Received: by 2002:a19:8582:: with SMTP id h124mr1571095lfd.64.1573116935696; Thu, 07 Nov 2019 00:55:35 -0800 (PST) MIME-Version: 1.0 References: <1572967777-8812-1-git-send-email-rppt@linux.ibm.com> <1572967777-8812-2-git-send-email-rppt@linux.ibm.com> <20191105162424.GH30717@redhat.com> <20191107083902.GB3247@linux.ibm.com> In-Reply-To: <20191107083902.GB3247@linux.ibm.com> From: Daniel Colascione Date: Thu, 7 Nov 2019 00:54:59 -0800 Message-ID: Subject: Re: [PATCH 1/1] userfaultfd: require CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK To: Mike Rapoport Cc: Andrea Arcangeli , Andy Lutomirski , linux-kernel , Andrew Morton , Jann Horn , Linus Torvalds , Lokesh Gidra , Nick Kralevich , Nosh Minwalla , Pavel Emelyanov , Tim Murray , Linux API , linux-mm Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 7, 2019 at 12:39 AM Mike Rapoport wrote: > On Tue, Nov 05, 2019 at 08:41:18AM -0800, Daniel Colascione wrote: > > On Tue, Nov 5, 2019 at 8:24 AM Andrea Arcangeli wrote: > > > The long term plan is to introduce UFFD_FEATURE_EVENT_FORK2 feature > > > flag that uses the ioctl to receive the child uffd, it'll consume more > > > CPU, but it wouldn't require the PTRACE privilege anymore. > > > > Why not just have callers retrieve FDs using recvmsg? This way, you > > retrieve the message packet and the file descriptor at the same time > > and you don't need any appreciable extra CPU use. > > I don't follow you here. Can you elaborate on how recvmsg would be used in > this case? Imagine an AF_UNIX SOCK_DGRAM socket. You call recvmsg(). You get a blob of regular data along with some ancillary data. The ancillary data may include some file descriptors or it may not. Isn't the UFFD message model the same thing? You'd call recvmsg() on a UFFD and get back a uffd_msg data structure. If that uffd_msg came with file descriptors, these descriptors would be in ancillary data. If you didn't reserve enough space for the message or enough space for its ancillary data, the recvmsg() call would fail cleanly with MSG_TRUNC or MSG_CTRUNC. The nice thing about using recvmsg() for this purpose is that there's tons of existing code for dealing with recvmsg()'s calling convention and its ancillary data. You can, for example, use recvmsg out of the box in a Python script. You could make an ioctl that also returned a data blob plus some optional file descriptors, but if recvmsg already does exactly that job and it's well-understood, why not just reuse the recvmsg interface? How practical is it to actually support recvmsg without being a socket? How hard would it be to just become a socket? I don't know. My point is only that *from a userspace API* point of view, recvmsg() seems ideal.