Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp308080ybg; Tue, 22 Oct 2019 21:16:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzO8nzc3CftvBhVHff9ahfvdPHicx3F9kPogiXdr993Nr93gw7Dwe721A/3/1PB2VoHKEgG X-Received: by 2002:a17:906:1949:: with SMTP id b9mr2686969eje.277.1571804209582; Tue, 22 Oct 2019 21:16:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571804209; cv=none; d=google.com; s=arc-20160816; b=q1twPuktvUZsn4rhK6fuXXVBNKTuAyc2rqHsvDdWELs/HWcf5qDQGoA5IIFFi2LB3t h96MGqe3VDj3d9KUq4xSMzse7IUF5drmTLkV0A8bUcp7DH+T5GdG6pkBuONtZ9qo8CkT cG2wXFrnO+lAlLgibrr6r7Q887lzP08q3TuumQ9BEO1RcQ9mDNtyEKPn6F2eUOkpt59v Ao7I3LK06GjJ6Uqv3sOK9OTwplW+EmgpgTD7D8FFFHOOwh7Z0wNWDBUIypawwmzhnd0M e08d6WJksGlDVhfz6L87+W/1MyAOetavwUq/yyNl2Uxf4Gabv+R9QvkeNS3Ws2FKAk1M EI7Q== 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=bdCz7e3s94ewvrlzn2Ui9NQW7OFls81f8HLUzx+Y0B0=; b=C57htwY2XXJQe63eLHQefw8uFSvHA96bnGHRn9eU3ShsoIH/SLzfxqzn07WFRlUDSX nFA/9AvWVbBZYjypFLuggmxTx58UkzHt6dWiEBq2D0UbgjBZo2Sxn5jm6D+3lIEV8Y6V YHJEvmXl0pYFjaBF1XFnhregnlvE/hiDNkymm1Hhk0D/Q0SCwPN7+4PldEJ1nM2JqI1G LObmYAI++/JD51K+7QD2rTzDW+HaXEGNQz7zUxpWqtGUwbmteQQ+MzP+Lq5Z/RBptRiA Z8ibH0JwN15XRQHtkr4MPvNK/+5Yei5RVtIIaDiK6r6elE6FkLlXC7XDR9MP3REj4Xa3 gwYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yeiVt0pL; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y27si14466055edd.249.2019.10.22.21.16.25; Tue, 22 Oct 2019 21:16:49 -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; dkim=pass header.i=@kernel.org header.s=default header.b=yeiVt0pL; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728499AbfJWELT (ORCPT + 99 others); Wed, 23 Oct 2019 00:11:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:54484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727574AbfJWELT (ORCPT ); Wed, 23 Oct 2019 00:11:19 -0400 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 50D3221928 for ; Wed, 23 Oct 2019 04:11:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571803877; bh=Gibqdh2Co8u4JylpxSaH4/x76GwQHMi9FG9hIlKKtek=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=yeiVt0pL096iSqYCKZeiQ9dctzQYy574QUj8xgZboFtW5nXfqGi4XxllH/ec2+sxf pzqoE68RFnb2hXuFHcK4N1D9Vu6+gTeRBSBwSFOfft4GDWGdnKafzZeRdW8VEBywM7 05RhG1a8ayx+mQx1nleRif40EJxWMb56m+XcZzcQ= Received: by mail-wr1-f50.google.com with SMTP id p4so20360643wrm.8 for ; Tue, 22 Oct 2019 21:11:17 -0700 (PDT) X-Gm-Message-State: APjAAAU8Ri/zhUwg5VPoYdnYlsi/CrD0MpHXwpQPVLpCak6lC3PLWTMM j1wQlESLebgm6ViF+PF6PvelVWyr4SA9Rq2eFEkaRA== X-Received: by 2002:a05:6000:1288:: with SMTP id f8mr6102479wrx.111.1571803875660; Tue, 22 Oct 2019 21:11:15 -0700 (PDT) MIME-Version: 1.0 References: <20191012191602.45649-1-dancol@google.com> <20191012191602.45649-4-dancol@google.com> In-Reply-To: From: Andy Lutomirski Date: Tue, 22 Oct 2019 21:11:04 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 3/7] Add a UFFD_SECURE flag to the userfaultfd API. To: Andy Lutomirski , Pavel Emelyanov , Cyrill Gorcunov Cc: Daniel Colascione , Linus Torvalds , Jann Horn , Andrea Arcangeli , Linux API , LKML , Lokesh Gidra , Nick Kralevich , Nosh Minwalla , Tim Murray 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 Trying again. It looks like I used the wrong address for Pavel. On Sat, Oct 12, 2019 at 6:14 PM Andy Lutomirski wrote: > > [adding more people because this is going to be an ABI break, sigh] > > On Sat, Oct 12, 2019 at 5:52 PM Daniel Colascione wrote: > > > > On Sat, Oct 12, 2019 at 4:10 PM Andy Lutomirski wrote: > > > > > > On Sat, Oct 12, 2019 at 12:16 PM Daniel Colascione wrote: > > > > > > > > The new secure flag makes userfaultfd use a new "secure" anonymous > > > > file object instead of the default one, letting security modules > > > > supervise userfaultfd use. > > > > > > > > Requiring that users pass a new flag lets us avoid changing the > > > > semantics for existing callers. > > > > > > Is there any good reason not to make this be the default? > > > > > > > > > The only downside I can see is that it would increase the memory usage > > > of userfaultfd(), but that doesn't seem like such a big deal. A > > > lighter-weight alternative would be to have a single inode shared by > > > all userfaultfd instances, which would require a somewhat different > > > internal anon_inode API. > > > > I'd also prefer to just make SELinux use mandatory, but there's a > > nasty interaction with UFFD_EVENT_FORK. Adding a new UFFD_SECURE mode > > which blocks UFFD_EVENT_FORK sidesteps this problem. Maybe you know a > > better way to deal with it. > > ... > > > But maybe we can go further: let's separate authentication and > > authorization, as we do in other LSM hooks. Let's split my > > inode_init_security_anon into two hooks, inode_init_security_anon and > > inode_create_anon. We'd define the former to just initialize the file > > object's security information --- in the SELinux case, figuring out > > its class and SID --- and define the latter to answer the yes/no > > question of whether a particular anonymous inode creation should be > > allowed. Normally, anon_inode_getfile2() would just call both hooks. > > We'd add another anon_inode_getfd flag, ANON_INODE_SKIP_AUTHORIZATION > > or something, that would tell anon_inode_getfile2() to skip calling > > the authorization hook, effectively making the creation always > > succeed. We can then make the UFFD code pass > > ANON_INODE_SKIP_AUTHORIZATION when it's creating a file object in the > > fork child while creating UFFD_EVENT_FORK messages. > > That sounds like an improvement. Or maybe just teach SELinux that > this particular fd creation is actually making an anon_inode that is a > child of an existing anon inode and that the context should be copied > or whatever SELinux wants to do. Like this, maybe: > > static int resolve_userfault_fork(struct userfaultfd_ctx *ctx, > struct userfaultfd_ctx *new, > struct uffd_msg *msg) > { > int fd; > > Change this: > > fd = anon_inode_getfd("[userfaultfd]", &userfaultfd_fops, new, > O_RDWR | (new->flags & UFFD_SHARED_FCNTL_FLAGS)); > > to something like: > > fd = anon_inode_make_child_fd(..., ctx->inode, ...); > > where ctx->inode is the one context's inode. > > *** HOWEVER *** !!! > > Now that you've pointed this mechanism out, it is utterly and > completely broken and should be removed from the kernel outright or at > least severely restricted. A .read implementation MUST NOT ACT ON THE > CALLING TASK. Ever. Just imagine the effect of passing a userfaultfd > as stdin to a setuid program. > > So I think the right solution might be to attempt to *remove* > UFFD_EVENT_FORK. Maybe the solution is to say that, unless the > creator of a userfaultfd() has global CAP_SYS_ADMIN, then it cannot > use UFFD_FEATURE_EVENT_FORK) and print a warning (once) when > UFFD_FEATURE_EVENT_FORK is allowed. And, after some suitable > deprecation period, just remove it. If it's genuinely useful, it > needs an entirely new API based on ioctl() or a syscall. Or even > recvmsg() :) > > And UFFD_SECURE should just become automatic, since you don't have a > problem any more. :-p > > --Andy