Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp242994img; Tue, 19 Mar 2019 23:10:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqznb2dIngEXdnMsJz3wuDON/8HzEGOO9lo/JaHoyvH482dfl7KvkEWi2QGoQR+nZTOH3hkz X-Received: by 2002:a17:902:ab8f:: with SMTP id f15mr6106937plr.218.1553062207440; Tue, 19 Mar 2019 23:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553062207; cv=none; d=google.com; s=arc-20160816; b=a2SseuaZ4ZTs1J/I064vbKTxI9Wx+BQij2Xl0QGxoRKCfJKjoRHZndc+KCXCOjcKud YhO25TJMyounyeptlxGlSvQ2cBLd5evTOTQcqXvcfeK0CQAz1KBmTBe6xniMxLafSxYl LKcGzbVgAi3hQjGcVaCG2J7aoY/ksspxXTgW4NVI9vpsXGY63+Fzd56rhP2TtAzyg20K Qrm9UKvKl0hpwBQR960XZZaFnY2YKclogz2ZX3JC2YrFWmCml7KfpLc+kOehjnXfGqtd NHImadDSxmDkX2MTwuE9Lgt97xKAdyMd+ORTj8LtWl2bfa82mEV+TvWtVtqB6WE7Afko dEnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=aCmAr6euZN4AX+hXU5UkOblwfcl12csePzwJvFQgccg=; b=L++p2dOJztkgVIb8vTslwcE2OIEk9U3qtXiJ4sllVQvmVvKcucXrmqlKx1xcOr1e+O q0REU0oZBn00sIXnVeyGT6H0Rco/UJ4OIBKvv2bzFCZbrvhTFxZ4C89Z19tA8J4wLgEe EX/fRHtjJwhxuCpfZf8NohGaQ/t1idLKIE6sECDYcZQ6W+3o9xlky1CHZaZzqirI46A6 IjXBOumi1J6deFSMBYci/312XHXjUTXdNl2nz0P73B9O+tbbLH49kgoh8RQfJWMx+ijx 88WVKx5t2tVIGBC7qT2g3KJm8fqtgobWwVjWSJDFbLvfXHVXPnLmqz2PzhPWWMe8EgYK Q1tA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b37si1142965pla.155.2019.03.19.23.09.50; Tue, 19 Mar 2019 23:10:07 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726916AbfCTGJL (ORCPT + 99 others); Wed, 20 Mar 2019 02:09:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31937 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725300AbfCTGJL (ORCPT ); Wed, 20 Mar 2019 02:09:11 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB45883F40; Wed, 20 Mar 2019 06:09:09 +0000 (UTC) Received: from sky.random (ovpn-120-78.rdu2.redhat.com [10.10.120.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C5652E02F; Wed, 20 Mar 2019 06:09:03 +0000 (UTC) Date: Tue, 19 Mar 2019 14:07:29 -0400 From: Andrea Arcangeli To: Mike Rapoport Cc: Peter Xu , linux-kernel@vger.kernel.org, Paolo Bonzini , Hugh Dickins , Luis Chamberlain , Maxime Coquelin , Maya Gokhale , Jerome Glisse , Pavel Emelyanov , Johannes Weiner , Martin Cracauer , Denis Plotnikov , linux-mm@kvack.org, Marty McFadden , Mike Kravetz , Mike Rapoport , Kees Cook , Mel Gorman , "Kirill A . Shutemov" , linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Dr . David Alan Gilbert" , Andrew Morton Subject: Re: [PATCH v2 1/1] userfaultfd/sysctl: add vm.unprivileged_userfaultfd Message-ID: <20190319180729.GA27618@redhat.com> References: <20190319030722.12441-1-peterx@redhat.com> <20190319030722.12441-2-peterx@redhat.com> <20190319071104.GA6392@rapoport-lnx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190319071104.GA6392@rapoport-lnx> User-Agent: Mutt/1.11.4 (2019-03-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 20 Mar 2019 06:09:10 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Tue, Mar 19, 2019 at 09:11:04AM +0200, Mike Rapoport wrote: > Hi Peter, > > On Tue, Mar 19, 2019 at 11:07:22AM +0800, Peter Xu wrote: > > Add a global sysctl knob "vm.unprivileged_userfaultfd" to control > > whether userfaultfd is allowed by unprivileged users. When this is > > set to zero, only privileged users (root user, or users with the > > CAP_SYS_PTRACE capability) will be able to use the userfaultfd > > syscalls. > > > > Suggested-by: Andrea Arcangeli > > Suggested-by: Mike Rapoport > > Signed-off-by: Peter Xu > > Reviewed-by: Mike Rapoport > > Just one minor note below This looks fine with me too. > > + if (!sysctl_unprivileged_userfaultfd && !capable(CAP_SYS_PTRACE)) > > + return -EPERM; The only difference between the bpf sysctl and the userfaultfd sysctl this way is that the bpf sysctl adds the CAP_SYS_ADMIN capability requirement, while userfaultfd adds the CAP_SYS_PTRACE requirement, because the userfaultfd monitor is more likely to need CAP_SYS_PTRACE already if it's doing other kind of tracking on processes runtime, in addition of userfaultfd. In other words both syscalls works only for root, when the two sysctl are opt-in set to 1. Reviewed-by: Andrea Arcangeli