From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1D7CC433B4 for ; Mon, 26 Apr 2021 16:01:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 31A106044F for ; Mon, 26 Apr 2021 16:01:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31A106044F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 942E36B0036; Mon, 26 Apr 2021 12:00:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CC066B006E; Mon, 26 Apr 2021 12:00:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 745AB8D0001; Mon, 26 Apr 2021 12:00:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id 457F46B0036 for ; Mon, 26 Apr 2021 12:00:59 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id F2FDF1802DDF2 for ; Mon, 26 Apr 2021 16:00:58 +0000 (UTC) X-FDA: 78074981796.19.E477073 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 91735A00371F for ; Mon, 26 Apr 2021 16:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619452852; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+7Z91EmdEzGViA9uS6BhSNuizWMtWDUbKP0zpEO7eLo=; b=S+y6hzfq9pGYhid+o2qu7O78Bz9iSluXEXvCflkVMFEEi99ppK6NAIVnEyYqzlGI9v7oEP PCzM3tD9FHoAFeMb5bPese7gIDRvdAx5okGHfIBxmSpke4DWOCxX34sBdBnAf+FSH4hDKB pkqsg76TZqzg72uYZEUwZAZzGf7c8Vo= Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-407-bpisBBoENAWv7Yj4AuVl1g-1; Mon, 26 Apr 2021 12:00:50 -0400 X-MC-Unique: bpisBBoENAWv7Yj4AuVl1g-1 Received: by mail-yb1-f199.google.com with SMTP id z8-20020a2566480000b02904e0f6f67f42so34530192ybm.15 for ; Mon, 26 Apr 2021 09:00:50 -0700 (PDT) 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=+7Z91EmdEzGViA9uS6BhSNuizWMtWDUbKP0zpEO7eLo=; b=Imb9nfUFOiKxfJfldR2ToMsrgLBEZzYiYLtpE4tXdxyJynZ9CrzmfR/XhLdmX/c3wB csl9YVGD5PsPGcb5v7kcoYlMRENBxGGbkrBKOCv94BAEIr+wIae84Po9MwlABSut/7jM zUz1FM/awYxqn7o8cKZYlCN2fQbvduh5Mk4ddYJ5BRb9UUUXawgIlsgnSHht3k5a7NE8 fs/UwCCmutZ8/ieL6Gm2JrVEysgtEbRvfWys/PFYQfaDvCwOfj0wXRp5SiZBmpckVmX1 WZUNWWWaX1a11U2Pjsny35rta41RT2IjzHkcfH70uMAZz/hxTfTnCvMJz6uJ0gSDdl0F v8nw== X-Gm-Message-State: AOAM531e+mzo5ZIYZ23+s9LPp4XNEqdw94zFNr+altRIHaK2ibn0gJfQ cvN4A9+S8jJDGkkOKeWgRaQFaxVU9LnmVfnTsA/5Vzf+Yqro3HTso9SsSSBqQbc6Y2MNX1RfA1G SxrEruZG9rc8zqEFoCZYMjhFm/ns= X-Received: by 2002:a25:af41:: with SMTP id c1mr26458178ybj.340.1619452850311; Mon, 26 Apr 2021 09:00:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUra5CjghINxqaBt+Aqv4z7MU09/1zLmWqUX2ioLdVS800IQO7MQIvcbIxp2gk/KA53g3Qe+2woXFunX2cjSM= X-Received: by 2002:a25:af41:: with SMTP id c1mr26458131ybj.340.1619452849989; Mon, 26 Apr 2021 09:00:49 -0700 (PDT) MIME-Version: 1.0 References: <20210421171446.785507-1-omosnace@redhat.com> <20210421171446.785507-3-omosnace@redhat.com> In-Reply-To: From: Ondrej Mosnacek Date: Mon, 26 Apr 2021 18:00:38 +0200 Message-ID: Subject: Re: [RFC PATCH 2/2] selinux: add capability to map anon inode types to separate classes To: Stephen Smalley Cc: SElinux list , Paul Moore , LSM List , "open list:MEMORY MANAGEMENT" , Linux FS Devel , linux-kernel , Lokesh Gidra Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=omosnace@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: w4b7bimu8rqfcg9atrzoa98u6f6h7ta4 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 91735A00371F Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619452848-289303 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Apr 23, 2021 at 5:20 PM Stephen Smalley wrote: > On Fri, Apr 23, 2021 at 10:22 AM Stephen Smalley > wrote: > > > > On Fri, Apr 23, 2021 at 9:41 AM Ondrej Mosnacek wrote: > > > > > > On Thu, Apr 22, 2021 at 3:21 PM Stephen Smalley > > > wrote: > > > > On Wed, Apr 21, 2021 at 1:14 PM Ondrej Mosnacek wrote: > > > > > > > > > > Unfortunately, the approach chosen in commit 29cd6591ab6f ("selinux: > > > > > teach SELinux about anonymous inodes") to use a single class for all > > > > > anon inodes and let the policy distinguish between them using named > > > > > transitions turned out to have a rather unfortunate drawback. > > > > > > > > > > For example, suppose we have two types of anon inodes, "A" and "B", and > > > > > we want to allow a set of domains (represented by an attribute "attr_x") > > > > > certain set of permissions on anon inodes of type "A" that were created > > > > > by the same domain, but at the same time disallow this set to access > > > > > anon inodes of type "B" entirely. Since all inodes share the same class > > > > > and we want to distinguish both the inode types and the domains that > > > > > created them, we have no choice than to create separate types for the > > > > > cartesian product of (domains that belong to attr_x) x ("A", "B") and > > > > > add all the necessary allow and transition rules for each domain > > > > > individually. > > > > > > > > > > This makes it very impractical to write sane policies for anon inodes in > > > > > the future, as more anon inode types are added. Therefore, this patch > > > > > implements an alternative approach that assigns a separate class to each > > > > > type of anon inode. This allows the example above to be implemented > > > > > without any transition rules and with just a single allow rule: > > > > > > > > > > allow attr_x self:A { ... }; > > > > > > > > > > In order to not break possible existing users of the already merged > > > > > original approach, this patch also adds a new policy capability > > > > > "extended_anon_inode_class" that needs to be set by the policy to enable > > > > > the new behavior. > > > > > > > > > > I decided to keep the named transition mechanism in the new variant, > > > > > since there might eventually be some extra information in the anon inode > > > > > name that could be used in transitions. > > > > > > > > > > One minor annoyance is that the kernel still expects the policy to > > > > > provide both classes (anon_inode and userfaultfd) regardless of the > > > > > capability setting and if one of them is not defined in the policy, the > > > > > kernel will print a warning when loading the policy. However, it doesn't > > > > > seem worth to work around that in the kernel, as the policy can provide > > > > > just the definition of the unused class(es) (and permissions) to avoid > > > > > this warning. Keeping the legacy anon_inode class with some fallback > > > > > rules may also be desirable to keep the policy compatible with kernels > > > > > that only support anon_inode. > > > > > > > > > > Signed-off-by: Ondrej Mosnacek > > > > > > > > NAK. We do not want to introduce a new security class for every user > > > > of anon inodes - that isn't what security classes are for. > > > > For things like kvm device inodes, those should ultimately use the > > > > inherited context from the related inode (the /dev/kvm inode itself). > > > > That was the original intent of supporting the related inode. > > > > > > Hmm, so are you implying that anon inodes should be thought of the > > > same as control /dev nodes? I.e. that even though there may be many > > > one-time actual inodes created by different processes, they should be > > > thought of as a single "static interface" to the respective kernel > > > functionality? That would justify having a common type/label for all > > > of them, but I'm not sure if it doesn't open some gap due to the > > > possibility to pass the associated file descriptors between processes > > > (as AFAIK, these can hold some context)... > > > > That was the original design (and the original patchset that we posted > > in parallel with Google's independently developed one). We even had > > example policy/controls for /dev/kvm ioctls. > > Imagine trying to write policy over /dev/kvm ioctls where you have to > > deal with N different classes and/or types and remember which ioctl > > commands are exercised on which class or type even though from the > > users' perspective they all occurred through the /dev/kvm interface. > > It seemed super fragile and difficult to maintain/analyze that way. > > Versus writing a single allow rule for all /dev/kvm ioctls. So I went back and read the conversations on the original patches and after thinking a bit more about it I'm getting more comfortable with the idea to treat anonymous inodes as a kind of opened device node file (which can be either an "imaginary" one as in the userfaultfd(2) case or an existing real device node as in the KVM example), which has just one type regardless of what process has created it. I suppose if there are any properties of an open anonymous inode that would be interesting from SELinux POV, they could be checked via a separate class with an appropriate permission. For example, if we wanted to control which domains can create & use usefaultfds without vs. with the UFFD_USER_MODE_ONLY flag, we could introduce a new hook, which would allow us to check an access vector like (current_sid, current_sid, userfaultfd, kernel_mode) on any attempt to create or inherit/receive an uffd without the UFFD_USER_MODE_ONLY flag. (In fact, this might actually be a useful enhancement...) So I'm retracting these patches for now. > > > > I guess we could discuss the alternatives but please have a look at > > those original patches and examples. If we go down this road, we need > > some way to deal with scaling because we only have a limited number of > > discrete classes available to us and potentially unbounded set of > > distinct anon inode users (although hopefully in practice only a few > > that we care about distinguishing). > > Actually, on second thought, we shouldn't be in any danger of running > out of classes so nevermind on that point. > > > > > > I thought this was supposed to resemble more the way BPF, perf_event, > > > etc. support was implemented - the BPF and perf_event fds are also > > > anon inodes under the hood, BTW - where each file descriptor is > > > considered a separate object that inherits the label of its creator > > > and there is some class separation (e.g. bpf vs. perf_event). -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc.