Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2079098imn; Mon, 1 Aug 2022 10:19:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tS6C178szAaBzMeQtQETTuFVAZYunnFB0Irt2BGtVFleKpZ0iY+D3OZ1l9yR/DKTSa/RXl X-Received: by 2002:a65:6494:0:b0:419:9527:2a69 with SMTP id e20-20020a656494000000b0041995272a69mr14016129pgv.80.1659374384411; Mon, 01 Aug 2022 10:19:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659374384; cv=none; d=google.com; s=arc-20160816; b=Tqnl9NpYxOuUlYbU2debw3mHxDY3mTAMl/8ak2Twa/+i3rDgD/5avCXZ+5y2FxW2CH SoZjwYbU77wcUZrYdhIJKpk4ZVAb7M11QNicYOqm4hBFsrgqI3Y4tGBUr/WtFibykPVw vdR00lqdngEQz0lrqIbdjOF5aJBs5tXSQHtAEWAIvjwSF/stemGxvTddIBAdmMFUb1yo bvvuiNhESlWU7Hezl5QuBPBLsKgIHw0n7WvQJfD8ZFyEwwJLg06T7FCHBJxVlbbNCD3q L75eL2AELZMiS13LDNe13H1YMJ5hxU0SXKtAIq9ELF8QQi+UiPeOmse9uSLLuKPRhjn3 BCAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=RMpq00zmLmRyLkH3ymS8AD8nFPc9nuPS5SpA8DGRQjc=; b=kfUK9conHX4+1FsZhde7+lZcO5Lv+lAupxbq3rORAQ/SNjs3ar1D/l3hbYrhA5UDka gDvKOM8oKZwKQciq8KJQR7EVyGjelXa20jRH3AXzpezD6xSNSrpj327es30qQsH/zLeC 4q8G4TqerzJFd52JgnqUX0OsFKNJYrZXhrofgIFYQ5CAobxvyPPzlx3JLcrxS0jCbFSL 67Cg0Pj6LTSHPejCJhBCa8CwrhupiMLfVxggGByf9WaYZ6GBbjQHIwDh2yloPtk9e8Ca e0ENnB7aATN846GpaJg+ShS2An0jNPMB6pCFeM65HJZNrsYKXKDFpIZ/DpZH/duOP4ka WbiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CzbG8jn3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h18-20020a170902f55200b0016d5629a668si8965251plf.258.2022.08.01.10.19.29; Mon, 01 Aug 2022 10:19:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CzbG8jn3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232579AbiHARNx (ORCPT + 99 others); Mon, 1 Aug 2022 13:13:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbiHARNv (ORCPT ); Mon, 1 Aug 2022 13:13:51 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 980362A250 for ; Mon, 1 Aug 2022 10:13:49 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id h145so8861826iof.9 for ; Mon, 01 Aug 2022 10:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=RMpq00zmLmRyLkH3ymS8AD8nFPc9nuPS5SpA8DGRQjc=; b=CzbG8jn3lmpWwZNf2DkfRaHkYPFhpnngD3tqdI3rzFaOFYHZNMm6okjhZb6FbHgpBV MvAiCTK6W4xcrO1x5Yjhl019C5+KjcritcRqSFhQaKoMajPDUHQeWFPDkHYMGeRgY8Vu Vlq+9AkYHWni1BvEapZhFKQ5KeDvskzMF4zzTqigIUCnuDP933nMxj/APjQzuu+RArVP gqfUWjMDhjWL2VnCff9414QnqJgVQzUNvnp9EqGeJ9Iz8m8BDzpuJNlFQ+ROha+Bnafo tluUwY6NGaRCfpXGufNKvA0sFeRiZ78FJK3XduIgR/UnkVscDBe9pPntr4MQx346BtAD SBjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=RMpq00zmLmRyLkH3ymS8AD8nFPc9nuPS5SpA8DGRQjc=; b=DF8yRNOO4T3j1t47Z+bDs8p8EMg5eTv4djjXYBJyzZmqrpuuo/RqKhJWGQcgLx8pBV zgD+kHwYvHDGci+rsMXVMN2AQWxjTwY5QwXLo6zcMpBSj+3qeEmBerck60mfWNInsydP zZ12vQHsroDtvD2pE5x3JHD2NlRW+oYh1cRfH4tqlEr5yAhm8rWjRyXYGOs3fyiLfjTP HB6pZVpBlb1mWsIJQc5NlB1AHF3+fyn4X5cXxCiC4Ywe8VQ34SPGV5OVYq3AyuqP9Lbt /6YfZCA+E1FbIrJg/zDu9OyAv49vy9xRALi7d5fFMLGK6DlacOY3+/6ifqogFrbIgDPg C5jQ== X-Gm-Message-State: AJIora9tVZnfKpmT8AdP+7AUMeiY3PYRZDp0Gi3BCcp9HjQTBHv078VF UZrVaLGLL1bDIeWnbT1q2gNbX3V+iLGzad6ocaBfhg== X-Received: by 2002:a05:6602:2f03:b0:678:9c7c:97a5 with SMTP id q3-20020a0566022f0300b006789c7c97a5mr5833295iow.32.1659374028847; Mon, 01 Aug 2022 10:13:48 -0700 (PDT) MIME-Version: 1.0 References: <20220719195628.3415852-1-axelrasmussen@google.com> <7EF50BE4-84EA-4D57-B58C-6697F1B74904@vmware.com> In-Reply-To: <7EF50BE4-84EA-4D57-B58C-6697F1B74904@vmware.com> From: Axel Rasmussen Date: Mon, 1 Aug 2022 10:13:12 -0700 Message-ID: Subject: Re: [PATCH v4 0/5] userfaultfd: add /dev/userfaultfd for fine grained access control To: Nadav Amit Cc: "Schaufler, Casey" , Alexander Viro , Andrew Morton , Dave Hansen , "Dmitry V . Levin" , Gleb Fotengauer-Malinovskiy , Hugh Dickins , Jan Kara , Jonathan Corbet , Mel Gorman , Mike Kravetz , Mike Rapoport , Peter Xu , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , zhangyi , "linux-doc@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-kselftest@vger.kernel.org" , Andrea Arcangeli Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I finished up some other work and got around to writing a v5 today, but I ran into a problem with /proc/[pid]/userfaultfd. Files in /proc/[pid]/* are owned by the user/group which started the process, and they don't support being chmod'ed. For the userfaultfd device, I think we want the following semantics: - For UFFDs created via the device, we want to always allow handling kernel mode faults - For security, the device should be owned by root:root by default, so unprivileged users don't have default access to handle kernel faults - But, the system administrator should be able to chown/chmod it, to grant access to handling kernel faults for this process more widely. It could be made to work like that but I think it would involve at least: - Special casing userfaultfd in proc_pid_make_inode - Updating setattr/getattr for /proc/[pid] to meaningfully store and then retrieve uid/gid different from the task's, again probably special cased for userfautlfd since we don't want this behavior for other files It seems to me such a change might raise eyebrows among procfs folks. Before I spend the time to write this up, does this seem like something that would obviously be nack'ed? On Wed, Jul 20, 2022 at 4:21 PM Nadav Amit wrote: > > On Jul 20, 2022, at 4:04 PM, Axel Rasmussen wr= ote: > > > =E2=9A=A0 External Email > > > > On Wed, Jul 20, 2022 at 3:16 PM Schaufler, Casey > > wrote: > >>> -----Original Message----- > >>> From: Axel Rasmussen > >>> Sent: Tuesday, July 19, 2022 12:56 PM > >>> To: Alexander Viro ; Andrew Morton > >>> ; Dave Hansen > >>> ; Dmitry V . Levin ; G= leb > >>> Fotengauer-Malinovskiy ; Hugh Dickins > >>> ; Jan Kara ; Jonathan Corbet > >>> ; Mel Gorman ; Mike > >>> Kravetz ; Mike Rapoport ; > >>> Amit, Nadav ; Peter Xu ; > >>> Shuah Khan ; Suren Baghdasaryan > >>> ; Vlastimil Babka ; zhangyi > >>> > >>> Cc: Axel Rasmussen ; linux- > >>> doc@vger.kernel.org; linux-fsdevel@vger.kernel.org; linux- > >>> kernel@vger.kernel.org; linux-mm@kvack.org; linux- > >>> kselftest@vger.kernel.org > >>> Subject: [PATCH v4 0/5] userfaultfd: add /dev/userfaultfd for fine gr= ained > >>> access control > >> > >> I assume that leaving the LSM mailing list off of the CC is purely > >> accidental. Please, please include us in the next round. > > > > Honestly it just hadn't occurred to me, but I'm more than happy to CC > > it on future revisions. > > > >>> This series is based on torvalds/master. > >>> > >>> The series is split up like so: > >>> - Patch 1 is a simple fixup which we should take in any case (even by= itself). > >>> - Patches 2-6 add the feature, configurable selftest support, and doc= s. > >>> > >>> Why not ...? > >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > >>> > >>> - Why not /proc/[pid]/userfaultfd? The proposed use case for this is = for one > >>> process to open a userfaultfd which can intercept another process' pa= ge > >>> faults. This seems to me like exactly what CAP_SYS_PTRACE is for, tho= ugh, > >>> so I > >>> think this use case can simply use a syscall without the powers > >>> CAP_SYS_PTRACE > >>> grants being "too much". > >>> > >>> - Why not use a syscall? Access to syscalls is generally controlled b= y > >>> capabilities. We don't have a capability which is used for userfaultf= d access > >>> without also granting more / other permissions as well, and adding a = new > >>> capability was rejected [1]. > >>> > >>> - It's possible a LSM could be used to control access instead. I susp= ect > >>> adding a brand new one just for this would be rejected, > >> > >> You won't know if you don't ask. > > > > Fair enough - I wonder if MM folks (Andrew, Peter, Nadav especially) > > would find that approach more palatable than /proc/[pid]/userfaultfd? > > Would it make sense from our perspective to propose a userfaultfd- or > > MM-specific LSM for controlling access to certain features? > > > > I remember +Andrea saying Red Hat was also interested in some kind of > > access control mechanism like this. Would one or the other approach be > > more convenient for you? > > To reiterate my position - I think that /proc/[pid]/userfaultfd is very > natural and can be easily extended to support cross-process access of > userfaultfd. The necessary access controls are simple in any case. For > cross-process access, they are similar to those that are used for other > /proc/[pid]/X such as pagemap. > > I have little experience with LSM and I do not know how real deployments = use > them. If they are easier to deploy and people prefer them over some > pseudo-file, I cannot argue against them. > >