Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1120162pxb; Tue, 8 Feb 2022 09:40:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGgMO1L+KKP1+4tWK0ffEzK6cS0AEH+Q0U8bpnl01U0SMYGPPQ11rFI9LuuFh89d3aYTq4 X-Received: by 2002:a17:906:77c3:: with SMTP id m3mr1986300ejn.698.1644342059672; Tue, 08 Feb 2022 09:40:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644342059; cv=none; d=google.com; s=arc-20160816; b=wpiTeqoZ46Hq1zKL/Z/yHapJnKrg2McPv9kBUP68Cn+BYzReJrCMfAX+32N1rYwEAq T1yaXMOYuFmpDnWyyQ7RBjeS+MYx725+0zk0FvcHrXcHwJVsKI4WAkD8AgTNMOQxn7af lDjZruNz2DnkZigXElRpCBR7d5T6Y5aRns5VRRL3Tug8rSCIe0KTjsjGazDTVwy3j1pr R5jm5qhovQj1qo5pF6WmbBvx5u9jLRLHYN15+OBXP/0PuvPHftM4knn1+kbuI5p68zPM VwbPIHxflTTRHTnH/aQqcR1I6LzqCMnqXXTJY+LdG7WF/24dGWhi4IWu2w7/CsLVKiGQ c2eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=NQ+fFpYPtqQGn2yxA7jt9c9iXOBKxf0oaBcoQzdaBUQ=; b=pC+zVcWunRtA3QR+iQC/Wy3eZzr3xDGadInFcbHM4e/wmEVq3GqQ2vcRrHoGg5TA5v CYWVLADIXtvhI1F2Jqet1A+L8pDZ6AKa/+a6ApvhJEBSRE8MCEWJWghlGQTh1y6FUsbx TspWTJS6jbQTStuDs94FxXgHaoBtOFczQO2Sk8LZvydadW820RjoFpha746+36jG1k96 dKB41plfYyVMXaMZuyoTrZ/QPbN+5HiZ915Q6duiv17S4TND+4MuYyIl9d7XQDZOfBQR Ro/gMlmoP+WSfMRde4f5VmXcElCHvhQ74erE28jD6Ba4F2qCqDohmnYVBjsjPGN7EZBu yW7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@defensec.nl header.s=default header.b=hzs3WgiC; 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=NONE sp=NONE dis=NONE) header.from=defensec.nl Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd14si2989746ejc.438.2022.02.08.09.40.33; Tue, 08 Feb 2022 09:40:59 -0800 (PST) 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=@defensec.nl header.s=default header.b=hzs3WgiC; 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=NONE sp=NONE dis=NONE) header.from=defensec.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383598AbiBHQyu (ORCPT + 99 others); Tue, 8 Feb 2022 11:54:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383579AbiBHQyt (ORCPT ); Tue, 8 Feb 2022 11:54:49 -0500 X-Greylist: delayed 451 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 08 Feb 2022 08:54:45 PST Received: from markus.defensec.nl (markus.defensec.nl [IPv6:2a10:3781:2099::123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5DE2C061576; Tue, 8 Feb 2022 08:54:45 -0800 (PST) Received: from brutus (brutus.lan [IPv6:2a10:3781:2099::438]) by markus.defensec.nl (Postfix) with ESMTPSA id F3200FC07E3; Tue, 8 Feb 2022 17:47:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=defensec.nl; s=default; t=1644338827; bh=eRv74+XI594hq5dL4OGUblyk1lqPGFnb0U0Ww0ZWEfg=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=hzs3WgiC2LieAJ+kSe703/DKF1H9tljccbLnmkZ6Uh37e9nMp/3uEvz1r3sFtORQQ 6+M/k4iKUqWP+z5HHEWOcHpTzKfg9L/QwylHxC3Uz5fetMqiOLBE8hWuQM+zOENabp Dx73EyMBADClv8GDiZs25lvdx7Qu1FtiRIG/GqhA= From: Dominick Grift To: Chris PeBenito Cc: William Roberts , Paul Moore , Demi Marie Obenour , Stephen Smalley , Eric Paris , SElinux list , Linux kernel mailing list , selinux-refpolicy@vger.kernel.org Subject: Re: [PATCH] SELinux: Always allow FIOCLEX and FIONCLEX References: <4df50e95-6173-4ed1-9d08-3c1c4abab23f@gmail.com> <478e1651-a383-05ff-d011-6dda771b8ce8@linux.microsoft.com> <875ypt5zmz.fsf@defensec.nl> <4be3fef6-63ca-af97-7fc6-d93d85a9b706@linux.microsoft.com> Date: Tue, 08 Feb 2022 17:47:05 +0100 In-Reply-To: <4be3fef6-63ca-af97-7fc6-d93d85a9b706@linux.microsoft.com> (Chris PeBenito's message of "Tue, 8 Feb 2022 10:47:44 -0500") Message-ID: <87ee4dnw52.fsf@defensec.nl> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Chris PeBenito writes: > On 2/8/2022 09:17, 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 system, >>>> 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 similar >>>> problem there too. >>> >>> Excuse me if I am wrong but AFAIK adding a xperm rule does not turn 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. > > Just to clarify (Demi Marie also mentioned this earlier in the > thread), what I originally meant was how to emulate this patch by > using policy rules means you need a rule that allows the two ioctls on > all domains for all objects. That results in xperms checks enabled > everywhere. Thanks. That is clear now. I also learned that is pretty much what Android's sepolicy is doing. That is probably not something I would do (enable xperms globally). I would probably leverage it only for "devnode" chr and maybe blk files and only where they actually are accessed. I would not mind removing these two checks, but i am not a big user of xperms (i only filter TIOSCTI on terminal chr files and only for the entities that write or append them). > > >>> 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 later 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 >> allowed, but >> the equivalent FIONCLEX and FIOCLEX are checked. So if you wrote policy >> 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, which >> 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 are equivalent? >> I think they are. >> 2. Do we want the interfaces to behave the same? >> I think they should. > > If you can bypass FIONCLEX and FIOCLEX checks by F_SETFD and > FD_CLOEXEC, then I agree that the two FIO checks don't have value and > can be skipped as F_SETFD is. > >> 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. > > Reference policy does not have any xperm rules at this time. I looked > at the Fedora policy, and that doesn't have any. -- gpg --locate-keys dominick.grift@defensec.nl Key fingerprint = FCD2 3660 5D6B 9D27 7FC6 E0FF DA7E 521F 10F6 4098 Dominick Grift