Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1890054ybg; Thu, 24 Oct 2019 01:31:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgMS6Cz/feDcb5JVAKAIU6OCsyFBaMDKEuCNlcbSVFKMbHc15p+kKgTepk0s9NfqMaBTdS X-Received: by 2002:a17:906:6dd3:: with SMTP id j19mr35685465ejt.144.1571905895490; Thu, 24 Oct 2019 01:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571905895; cv=none; d=google.com; s=arc-20160816; b=w3MRIaLUuaG6QiCCCDuEEsZ/xZH4AGUlL+PgRHImkUw/QiCyrmL+UarjuUty04KDDh DsTJbPJDCF9dEl7v5q3TUfruJI1vAYDzzkECVWLMV8v79BN0rxv5a+VnlTClT9Y17UYM pyqIC5jnE4WHbKGU7llDjadwbcYscWOPaCYGRCKz3g0bcytvVy5y4IV+x+IH4DxwqTKz CMPP42nVgyvOjabu/zgQYFPBUfykNWDi/C4zZiXeEB5Zs5ApDmYoK+XsbVtXKIAja/qu L/C2Q4g3XPHb8pU2yBm23xFpVHqIrdYN+nzHisz670d6ZuIYCzBo3MA9NedHndqvVKxg LSRA== 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=CuxyypILbTWpcfkhKL8aKWoVpslg9ixBV9lC0+lf9b4=; b=GGbqwrZ18q3RnhD2dSiDZVmWHc4PvO40+R+QqRB7TUCUEsM0pN+izpvLtZ1OXvvBXh 4493QF3gZ6k624EGNjuskK5ziOhBQpknw9U2QHoIi7WhI+SdlFUDNggQ+IbpTQFUcFog N/rBDKDeX2GYJIpp7RT0rN6HQQVemG+pqcg3Tdxlhx8bn3aeLoifhlGcSaxaPF5NK/AV NcySr66AWnaW/lYHm20iTOstosjO8WSfXs/IYJG/MiLAhNrSYfXMY4XFLnjKCwgaWEAk RlZZm2ZxAW5tl4peQYtVlbdf0otXzUZmlVZnAeUwXw07kaA91a6F6Kap+5uqTddxuYip NIqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0n4i35i1; 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 a11si5786143eju.31.2019.10.24.01.31.10; Thu, 24 Oct 2019 01:31:35 -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=0n4i35i1; 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 S1728137AbfJWRN5 (ORCPT + 99 others); Wed, 23 Oct 2019 13:13:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:39568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727648AbfJWRN5 (ORCPT ); Wed, 23 Oct 2019 13:13:57 -0400 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 50B41222BE for ; Wed, 23 Oct 2019 17:13:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571850835; bh=84V+tC14Q0AwxCc6Q4KhvS7f0XqOV27JoEx/anQWRjY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=0n4i35i1MJSHTwgpmmVzVFAkdzTs7CLNPpufO07X7oRw1t/7XhHy9SFJ7i6Se1aqL BtOiOEJZSHa6m4BPkGB6tgGJisZTb0vIxa1eiXlxgsZT6G2VlmXtvNsPPstMfQjIwu pMXRda+2kbAlq5ZmhAjXURxrzA6DlieJ/QVZpFUY= Received: by mail-wm1-f48.google.com with SMTP id r19so22143052wmh.2 for ; Wed, 23 Oct 2019 10:13:55 -0700 (PDT) X-Gm-Message-State: APjAAAXVcfeHkUqKcHjZ4BMCgQ8Q+IqL37bbtJrWRgTJwWdFvHRNm6Fr SdHG8aCnuRdXb7oM1/kjpqhy8frX3w1E/T2P9Sk+kw== X-Received: by 2002:a7b:cf28:: with SMTP id m8mr925998wmg.161.1571850833619; Wed, 23 Oct 2019 10:13:53 -0700 (PDT) MIME-Version: 1.0 References: <20191012191602.45649-1-dancol@google.com> <20191012191602.45649-4-dancol@google.com> <20191023072920.GF12121@uranus.lan> <20191023124358.GA2109@linux.ibm.com> In-Reply-To: <20191023124358.GA2109@linux.ibm.com> From: Andy Lutomirski Date: Wed, 23 Oct 2019 10:13:41 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 3/7] Add a UFFD_SECURE flag to the userfaultfd API. To: Mike Rapoport Cc: Cyrill Gorcunov , Andy Lutomirski , Pavel Emelyanov , Daniel Colascione , Linus Torvalds , Jann Horn , Andrea Arcangeli , Linux API , LKML , Lokesh Gidra , Nick Kralevich , Nosh Minwalla , Tim Murray , Mike Rapoport , Radostin Stoyanov , Andrey Vagin 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 Wed, Oct 23, 2019 at 5:44 AM Mike Rapoport wrote: > > On Wed, Oct 23, 2019 at 10:29:20AM +0300, Cyrill Gorcunov wrote: > > On Tue, Oct 22, 2019 at 09:11:04PM -0700, Andy Lutomirski wrote: > > > Trying again. It looks like I used the wrong address for Pavel. > > > > Thanks for CC Andy! I must confess I didn't dive into userfaultfd engine > > personally but let me CC more people involved from criu side. (overquoting > > left untouched for their sake). > > Thanks for CC Cyrill! > > > > > 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. > > > > > > > > > > Right now, when a process with a UFFD-managed VMA using > > > > > UFFD_EVENT_FORK forks, we make a new userfaultfd_ctx out of thin air > > > > > and enqueue it on the message queue for the parent process. When we > > > > > dequeue that context, we get to resolve_userfault_fork, which makes up > > > > > a new UFFD file object out of thin air in the context of the reading > > > > > process. Following normal SELinux rules, the SID attached to that new > > > > > file object would be the task SID of the process *reading* the fork > > > > > event, not the SID of the new fork child. That seems wrong, because > > > > > the label we give to the UFFD should correspond to the label of the > > > > > process that UFFD controls. > > I must admit I have no idea about how SELinux works, but what's wrong with > making the new UFFD object to inherit the properties of the "original" one? > > The new file object is created in the context of the same task that owns > the initial userfault file descriptor and it is used by the same task. So > if you have a process that registers some of its VMAs with userfaultfd > and enables UFFD_EVENT_FORK, the same process controls UFFD of itself and > its children. I'm not actually convinced this is a problem. What *is* a problem is touching the file descriptor table at all from read(2). That's a big no-no. --Andy