Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp823860pxb; Thu, 17 Feb 2022 15:51:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNBv+0F2S4BMULou9KNhDd2agy7j/4kDQv+pXKbmQE66E5eEmpwariOJZM9mKiIUZwTBv6 X-Received: by 2002:a17:90a:7486:b0:1b8:d61e:8bd4 with SMTP id p6-20020a17090a748600b001b8d61e8bd4mr5526825pjk.190.1645141902703; Thu, 17 Feb 2022 15:51:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645141902; cv=none; d=google.com; s=arc-20160816; b=wpvoIXkaAhIywAjO2+TF6snxYYb7mV4DneZcHQg47uCdSUb1NAPnXLNXispPpWHVBa PXWrN7ncHvr1Rl81Z07LOTVcTAFCMDcCqMksvLH6adZ9Kz0oHAR7tTHT3IBpKCyUNfcP OnYe8LuttJLcnWBTihIPw+Dbq97wmsYPipa0DkEUCFFdXvkwcMNFvGREi2hQ3wg9PF+b bKL387+IYHoewlTLkcp9BrWBuRQuTCxOPjRNlJne2GdzIbvqmhjZqQwHFuO6gzteQWbp IjE0/St3M/Ov+CsUWcYGurOzo+CwnzdXloy0/FHQNOPsaOHgbTPZ0zfk6G40AuDU4a5p 0YFg== 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=Hw18NUxIkws+pKv9BXQqVUxZL0gpw+nsSHJBAiFK+Tw=; b=m4pNsHUaAAeWBCStu6qVJrjif+OcE4oQdOIwuw/KVLrOe87bl4xf5qjUhKYp5fxvsl Gp+wn0sW8edMxJ/6mVGmNikOVHIIE8HRYs1K8VzCyqr1sT/XMEqs96fRfzA0LNUubw33 kGoPa+ghEGyeuxmR18X/QOql6LHlV0cMpoPdjtR+t3D/pJXFapn2bIO6AgWWqjGQlHdu VkZ9eS9wHoYVBBZsx1HUCIeEPDpRFk/LvAyo3orPqMqeo3Jy1L5cghmwZkFdBwMsb8kp xCKsDra2zFQ+1Txp+2ZwX5I6yjVN/SGiH3puiAO9+M3tgNvvOU6ziGTEHDu43h0q4oFu IryQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=TuxlNCMA; spf=pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=selinux-refpolicy-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o10si11310424plk.138.2022.02.17.15.51.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 15:51:42 -0800 (PST) Received-SPF: pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=TuxlNCMA; spf=pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=selinux-refpolicy-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 917F95007E; Thu, 17 Feb 2022 15:24:16 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343575AbiBQW0Z (ORCPT + 22 others); Thu, 17 Feb 2022 17:26:25 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241468AbiBQW0Z (ORCPT ); Thu, 17 Feb 2022 17:26:25 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB0BB1680B8 for ; Thu, 17 Feb 2022 14:26:08 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id p9so10564405ejd.6 for ; Thu, 17 Feb 2022 14:26:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Hw18NUxIkws+pKv9BXQqVUxZL0gpw+nsSHJBAiFK+Tw=; b=TuxlNCMAZu67yIZesw5qD2l9WluJYajpYSvf7ilkvdFkcII5B7zOSrrA1JUzqomlZ8 10Pki1W92fbUSBIJ10nS3MOH/QBtxY239+/IjpOoIKS/kh1J+Sn1bBO93h4HgD7QB4Yi k0PvxI8CuyRgNDmVscNQkrZcnvJZ0adyLP8lcudBKiUK2i9Z2LO18ySqzS/TX5RUgJmd 69ljAM3WDQb9KkbfS5Q1hJmapvZHsXtShA553HRBqz3h4t0dHfYtNLSfWKH5IGn9lQ0p AnJOcyId/KBm0DtJmumd+61FcdRtSK5dRbdlgCVFZOQy0Xa6G0i+gEdNLxvVhYaJCK0M 3s5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Hw18NUxIkws+pKv9BXQqVUxZL0gpw+nsSHJBAiFK+Tw=; b=ni26NPuv3KGESQq3dMA7FBC5X4sraTf+LDIhv/M+xV+PJg19BrCoDuuyDOTbU4g8Gu /ENqLJaq4Vriotpw5Q1TYxqrNAbp4rWNOlInXpHLK0kZySq3Xnh/+PTD/F6WZvm8k5ON 31PDf5tcx/kkLPt8L1/uWnYdI9MxAODitqjQdStKaLbpy4NjY8FTciEtol2+HKnIgzQr iq+MfgkMT08zmLkP97TwhWujeRMhf3rHwZSYboQHu60wbyGSlTddxSYOwQB03vgGUF4P 5fR+HITpaGCC2ntFt7d9iRJjIX5FrI3HyYt4yS8qPsGHfRO70LddA3E1F6OnlTMXPF7Y svow== X-Gm-Message-State: AOAM530H290cUL6O1npLcwCTGTyWFylYXcOpmMOty+xFMxkN+qz+3Rd3 Z7Q6PvMDxHMBK+Uy3lU+GHs1fHNbgfYXgLrB8vAq X-Received: by 2002:a17:906:4443:b0:6cf:6a7d:5f9b with SMTP id i3-20020a170906444300b006cf6a7d5f9bmr4072554ejp.12.1645136767084; Thu, 17 Feb 2022 14:26:07 -0800 (PST) MIME-Version: 1.0 References: <4df50e95-6173-4ed1-9d08-3c1c4abab23f@gmail.com> <478e1651-a383-05ff-d011-6dda771b8ce8@linux.microsoft.com> <875ypt5zmz.fsf@defensec.nl> In-Reply-To: From: Paul Moore Date: Thu, 17 Feb 2022 17:25:53 -0500 Message-ID: Subject: Re: [PATCH] SELinux: Always allow FIOCLEX and FIONCLEX To: =?UTF-8?Q?Christian_G=C3=B6ttsche?= Cc: Demi Marie Obenour , William Roberts , Dominick Grift , Chris PeBenito , Stephen Smalley , Eric Paris , SElinux list , Linux kernel mailing list , selinux-refpolicy@vger.kernel.org, Jeffrey Vander Stoep Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: selinux-refpolicy@vger.kernel.org On Thu, Feb 17, 2022 at 10:05 AM Christian G=C3=B6ttsche wrote: > On Tue, 15 Feb 2022 at 21:35, Paul Moore wrote: > > On Mon, Feb 14, 2022 at 2:11 AM Jeffrey Vander Stoep = wrote: > > > On Tue, Feb 8, 2022 at 3:18 PM William Roberts wrote: > > > > > > > > > > > > > > > > This is getting too long for me. > > > > > > > > > > > > > > > > I don't have a strong opinion either way. If one were to allow= this > > > > > > using a policy rule, it would result in a major policy breakage= . The > > > > > > rule would turn on extended perm checks across the entire syste= m, > > > > > > which the SELinux Reference Policy isn't written for. I can't = speak > > > > > > to the Android policy, but I would imagine it would be the simi= lar > > > > > > problem there too. > > > > > > > > > > Excuse me if I am wrong but AFAIK adding a xperm rule does not tu= rn on > > > > > xperm checks across the entire system. > > > > > > > > It doesn't as you state below its target + class. > > > > > > > > > > > > > > If i am not mistaken it will turn on xperm checks only for the > > > > > operations that have the same source and target/target class. > > > > > > > > That's correct. > > > > > > > > > > > > > > This is also why i don't (with the exception TIOSCTI for termdev > > > > > chr_file) use xperms by default. > > > > > > > > > > 1. it is really easy to selectively filter ioctls by adding xperm= rules > > > > > for end users (and since ioctls are often device/driver specific = they > > > > > know best what is needed and what not) > > > > > > > > > >>> and FIONCLEX can be trivially bypassed unless fcntl(F_SETFD) > > > > > > > > > > 2. if you filter ioctls in upstream policy for example like i do = with > > > > > TIOSCTI using for example (allowx foo bar (ioctl chr_file (not > > > > > (0xXXXX)))) then you cannot easily exclude additional ioctls late= r where source is > > > > > foo and target/tclass is bar/chr_file because there is already a = rule in > > > > > place allowing the ioctl (and you cannot add rules) > > > > > > > > Currently, fcntl flag F_SETFD is never checked, it's silently allow= ed, but > > > > the equivalent FIONCLEX and FIOCLEX are checked. So if you wrote po= licy > > > > to block the FIO*CLEX flags, it would be bypassable through F_SETFD= and > > > > FD_CLOEXEC. So the patch proposed makes the FIO flags behave like > > > > F_SETFD. Which means upstream policy users could drop this allow, w= hich > > > > could then remove the target/class rule and allow all icotls. Which= is easy > > > > to prevent and fix you could be a rule in to allowx 0 as documented= in the > > > > wiki: https://selinuxproject.org/page/XpermRules > > > > > > > > The questions I think we have here are: > > > > 1. Do we agree that the behavior between SETFD and the FIO flags ar= e equivalent? > > > > I think they are. > > > > 2. Do we want the interfaces to behave the same? > > > > I think they should. > > > > 3. Do upstream users of the policy construct care? > > > > The patch is backwards compat, but I don't want their to be cruft > > > > floating around with extra allowxperm rules. > > > > > > I think this proposed change is fine from Android's perspective. It > > > implements in the kernel what we've already already put in place in > > > our policy - that all domains are allowed to use these IOCLTs. > > > https://cs.android.com/android/platform/superproject/+/master:system/= sepolicy/public/domain.te;l=3D312 > > > > > > It'll be a few years before we can clean up our policy since we need > > > to support older kernels, but that's fine. > > > > Thanks for the discussion everyone, it sounds like everybody is okay > > with the change - that's good. However, as I said earlier in this > > thread I think we need to put this behind a policy capability, how > > does POLICYDB_CAPABILITY_IOCTL_CLOEXEC/"ioctl_skip_cloexec" sound to > > everyone? > > May I ask why? > To my understanding policy capabilities exist to retain backwards > compatibility for older > policies, e.g. if a new check is introduced or a new essential class > or permission, which > would break systems running an updated kernel with a non updated policy. > In this case no check or class/permission is added, the xperm checks > against FIO(N)CLEX > are just dropped. Old policies still defining related allow rules > continue to work. Existing > polices explicitly not allowing them and relying on SELinux to block chan= ges on > the close-on-exec flag are already broken due to the bypasses via > fnctl(2) and dup(2). Policy capabilities are a general tool that we can use when we make a change in the kernel that could potentially have an effect on the policy; it allows the policy to (typically) "opt-in" to the change. In this particular case we are talking about removing access controls, which is a Very Serious Thing, and protecting this behavior with an opt-in policy capability seems like a good way to not surprise anyone with the change. You are correct in that old policy would continue to load and work regardless, but I believe it is safer to create a new policy capability for this. --=20 paul-moore.com