Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp315856pxb; Mon, 7 Feb 2022 12:03:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwq+Ll8TSWKsHqmoXQK15huEzQ52nMdbPSyy+tNoF/nNbtwJz9hQETilINRkkkzG9TDyQJE X-Received: by 2002:a63:d650:: with SMTP id d16mr797428pgj.137.1644264203735; Mon, 07 Feb 2022 12:03:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644264203; cv=none; d=google.com; s=arc-20160816; b=Kd697I1wMteKM0Ncn3gf7TwtQ1zDnnN4usZx0kUXWxB67ttHae6DAi0tt/VpaUAFqH QGpy1Tjsr+N87P5CrMmp+Ty/mkjzNNBRehbjUayUUFo3Ag7EIur/4igq6mDzBYCtUMr+ 3kuAHuuCSmN3XdldDF6T31oHVnkYmKUNtJbqPc31h46YiulclU2zHFoXrqGI1+kMgqoZ HJDC1Wu1YEETAwXmLEdYouvBoQkOTToUwE12IpOFr6b7jMtEDI2NFDG4BWwDvoL4I/bA R9xElNbmFbiOvSB+7Sn2I7VTBLCK7wFnWLG3DAyOrLUGDrVnnt75XnV8iPbEnv0W8yNs 4jZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-filter; bh=ktb8h9R2FuGUyuu9vO9Aa8piTeN/08pchayZa5eu6lk=; b=L+3ZaqI0VXsRhklHY8h70xgUszIl9gHa5PvyN9MppjD0cfwKr1cVDAPY/CUJVYtZa7 Am0P1RZ4Pl6vFTkrlK6cn29d6Hi50+XyW/Pd0gB/TxG0sNXjdR0ccSL6OkGj6WtS1ljH 5SzY02YrgIGwVyh2QfwiIHLQu9yGD0xzzKkISxs1l6bRztIPELbxERjTRht58OXehLGF kB7BuFDCh5iQRb30zcz6GVZ3GidvLmcpK0/cMIl9ClhAJ3t81djwXmyuThfDhjUjPSqW 6ZneLj+EMU0S8OH9proaNg72tJeSKoHXsd3VH/oaPky7sBIk3hpzkaM5OdxrKlL4xck2 szdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=p3Fr5MwT; spf=pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=selinux-refpolicy-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v10si13602693pgt.845.2022.02.07.12.02.54; Mon, 07 Feb 2022 12:03:23 -0800 (PST) Received-SPF: pass (google.com: domain of selinux-refpolicy-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=@linux.microsoft.com header.s=default header.b=p3Fr5MwT; spf=pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=selinux-refpolicy-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358976AbiBDNs3 (ORCPT + 22 others); Fri, 4 Feb 2022 08:48:29 -0500 Received: from linux.microsoft.com ([13.77.154.182]:35442 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358974AbiBDNs3 (ORCPT ); Fri, 4 Feb 2022 08:48:29 -0500 Received: from [192.168.254.13] (unknown [72.85.44.115]) by linux.microsoft.com (Postfix) with ESMTPSA id 61BF620B6C61; Fri, 4 Feb 2022 05:48:28 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 61BF620B6C61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1643982509; bh=ktb8h9R2FuGUyuu9vO9Aa8piTeN/08pchayZa5eu6lk=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=p3Fr5MwT84Q/eBBwJnd/CQVTLGRVSKlAHI0GEQ+5PJBai5jjczGYSBhPEDE0hMMT+ iGik3TOfzFt6UYY7Po5phyFVVMRww2etepcYC0/L87Au2iSUW+ZiZX1I+O26yfJCU/ UpG5IDqdt89rfFtbXHxI/wkwjmpvDmDYmdjgnVvU= Message-ID: <478e1651-a383-05ff-d011-6dda771b8ce8@linux.microsoft.com> Date: Fri, 4 Feb 2022 08:48:27 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: [PATCH] SELinux: Always allow FIOCLEX and FIONCLEX Content-Language: en-US To: Paul Moore , Demi Marie Obenour Cc: Stephen Smalley , Eric Paris , selinux@vger.kernel.org, linux-kernel@vger.kernel.org, selinux-refpolicy@vger.kernel.org References: <4df50e95-6173-4ed1-9d08-3c1c4abab23f@gmail.com> From: Chris PeBenito In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: selinux-refpolicy@vger.kernel.org On 2/3/2022 18:44, Paul Moore wrote: > On Wed, Feb 2, 2022 at 5:13 AM Demi Marie Obenour wrote: >> On 2/1/22 12:26, Paul Moore wrote: >>> On Sat, Jan 29, 2022 at 10:40 PM Demi Marie Obenour >>> wrote: >>>> On 1/26/22 17:41, Paul Moore wrote: >>>>> On Tue, Jan 25, 2022 at 5:50 PM Demi Marie Obenour >>>>> wrote: >>>>>> On 1/25/22 17:27, Paul Moore wrote: >>>>>>> On Tue, Jan 25, 2022 at 4:34 PM Demi Marie Obenour >>>>>>> wrote: >>>>>>>> >>>>>>>> These ioctls are equivalent to fcntl(fd, F_SETFD, flags), which SELinux >>>>>>>> always allows too. Furthermore, a failed FIOCLEX could result in a file >>>>>>>> descriptor being leaked to a process that should not have access to it. >>>>>>>> >>>>>>>> Signed-off-by: Demi Marie Obenour >>>>>>>> --- >>>>>>>> security/selinux/hooks.c | 5 +++++ >>>>>>>> 1 file changed, 5 insertions(+) >>>>>>> >>>>>>> I'm not convinced that these two ioctls should be exempt from SELinux >>>>>>> policy control, can you explain why allowing these ioctls with the >>>>>>> file:ioctl permission is not sufficient for your use case? Is it a >>>>>>> matter of granularity? >>>>>> >>>>>> FIOCLEX and FIONCLEX are applicable to *all* file descriptors, not just >>>>>> files. If I want to allow them with SELinux policy, I have to grant >>>>>> *:ioctl to all processes and use xperm rules to determine what ioctls >>>>>> are actually allowed. That is incompatible with existing policies and >>>>>> needs frequent maintenance when new ioctls are added. >>>>>> >>>>>> Furthermore, these ioctls do not allow one to do anything that cannot >>>>>> already be done by fcntl(F_SETFD), and (unless I have missed something) >>>>>> SELinux unconditionally allows that. Therefore, blocking these ioctls >>>>>> does not improve security, but does risk breaking userspace programs. >>>>>> The risk is especially great because in the absence of SELinux, I >>>>>> believe FIOCLEX and FIONCLEX *will* always succeed, and userspace >>>>>> programs may rely on this. Worse, if a failure of FIOCLEX is ignored, >>>>>> a file descriptor can be leaked to a child process that should not have >>>>>> access to it, but which SELinux allows access to. Userspace >>>>>> SELinux-naive sandboxes are one way this could happen. Therefore, >>>>>> blocking FIOCLEX may *create* a security issue, and it cannot solve one. >>>>> >>>>> I can see you are frustrated with my initial take on this, but please >>>>> understand that excluding an operation from the security policy is not >>>>> something to take lightly and needs discussion. I've added the >>>>> SELinux refpolicy list to this thread as I believe their input would >>>>> be helpful here. >>>> >>>> Absolutely it is not something that should be taken lightly, though I >>>> strongly believe it is correct in this case. Is one of my assumptions >>>> mistaken? >>> >>> My concern is that there is a distro/admin somewhere which is relying >>> on their SELinux policy enforcing access controls on these ioctls and >>> removing these controls would cause them a regression. >> >> I obviously do not have visibility into all systems, but I suspect that >> nobody is actually relying on this. Setting and clearing CLOEXEC via >> fcntl is not subject to SELinux restrictions, so blocking FIOCLEX >> and FIONCLEX can be trivially bypassed unless fcntl(F_SETFD) is >> blocked by seccomp or another LSM. Clearing close-on-exec can also be >> implemented with dup2(), and setting it can be implemented with dup3() >> and F_DUPFD_CLOEXEC (which SELinux also allows). In short, I believe >> that unconditionally allowing FIOCLEX and FIONCLEX may fix real-world >> problems, and that it is highly unlikely that anyone is relying on the >> current behavior. > > I understand your point, but I remain concerned about making a kernel > change for something that can be addressed via policy. I'm also > concerned that in the nine days this thread has been on both the mail > SELinux developers and refpolicy lists no one other than you and I > have commented on this patch. In order to consider this patch > further, I'm going to need to see comments from others, preferably > those with a background in supporting SELinux policy. > > Also, while I'm sure you are already well aware of this, I think it is > worth mentioning that SELinux does apply access controls when file > descriptors are inherited across an exec() boundary. 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. -- Chris PeBenito