Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp412871pxm; Fri, 25 Feb 2022 10:23:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyMsRJVqMWp0h8bPXA9GPtMpDGaMS8apo6882M1XWkduoLiUTnVmWnJVUihk3QUHfamWNS X-Received: by 2002:a63:2a45:0:b0:373:1850:d5b with SMTP id q66-20020a632a45000000b0037318500d5bmr6905454pgq.563.1645813414765; Fri, 25 Feb 2022 10:23:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645813414; cv=none; d=google.com; s=arc-20160816; b=XSpk0b6WVknq/I681wF3ap9CjiiJJpY0wKX/eM/SZKKa4YjkHEehrnP8SndHgb9xeh 0IPFmszWhl5qPm0/6vR6Qb5htVoiACKBMBd0vYVRVKg163T1uISQCOzAQlFMl5jVpA2c BGEttp9u6UwZAu/imaVoJW8WtEZXJpV7kxvVfnYyclpaNhcpOTXeDrbRBZExSJrzP73Y W9o34xV0Tvf/Me/1lksup9KZO2PhL6KjgsLfFIB8+/c+5nU1bBNx2kKgD7W6ztPo9YVK eCP+ex25ppFferLQQAAXJUdHm6MqAGLMCxvNRUUbt3HdX6HP7pXG1INEDEYLqFBUQQ+T T4rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=39nmR0dbbIAChSn6/FB5eq6Ny9952x+7sRkKsOS0TK8=; b=MxSc9Mwwd3zYd8kZ2Kyvg2y/QbD1P47pLnnVufC+8PHLW51TqIaVJffGXF4K55XSWV bjSciDaV8uyRF2wsZ5oumCMUCGjkkoflYVnvlg/WmXsvlggNOj6/nRX8BGPJpmcMKnf2 GOf9my5VJKY+p8EPfun8tXUgmkBzXYwol/VLSGpWAmdipbcSeK3JKhqL8YwBwdn82VXP 4sOVHQynkPLm6l2cx+++fk9XkQWHrfX0trfpP5lLPsTifS/zchn5ld23ykiV6RnmwmlB VQX7r8DAK9bAgiQ+fSbrNi5QpsfgmLw3YwVqFOv4oy+MXxwDYuXDs3EAAph2wmts4xnB w3lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@btinternet.com header.s=btmx201904 header.b=C2ioAWuY; 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=REJECT sp=REJECT dis=NONE) header.from=btinternet.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i16-20020a17090332d000b0014ff4aa2319si2611758plr.115.2022.02.25.10.23.27; Fri, 25 Feb 2022 10:23:34 -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=@btinternet.com header.s=btmx201904 header.b=C2ioAWuY; 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=REJECT sp=REJECT dis=NONE) header.from=btinternet.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230062AbiBYRz1 (ORCPT + 22 others); Fri, 25 Feb 2022 12:55:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229967AbiBYRz1 (ORCPT ); Fri, 25 Feb 2022 12:55:27 -0500 Received: from re-prd-fep-043.btinternet.com (mailomta8-re.btinternet.com [213.120.69.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 241661EDA2D; Fri, 25 Feb 2022 09:54:52 -0800 (PST) Received: from re-prd-rgout-001.btmx-prd.synchronoss.net ([10.2.54.4]) by re-prd-fep-043.btinternet.com with ESMTP id <20220225175451.URVU390.re-prd-fep-043.btinternet.com@re-prd-rgout-001.btmx-prd.synchronoss.net>; Fri, 25 Feb 2022 17:54:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com; s=btmx201904; t=1645811691; bh=39nmR0dbbIAChSn6/FB5eq6Ny9952x+7sRkKsOS0TK8=; h=From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version; b=C2ioAWuYtUSD7VxUoI2WnqpxCdBK2rQ/jtM6DqIdbQLnuxyxs/Jvg+MsckKYTjc+G/cCy43R3Qgky9/R8+YY40dOItlJELwKtFNWnHKWiLySRFOIhI1909O+b8iTsoAsAYpgkcb5Tj9VbopbDQb5cRJXBwJMA+Yvl4YVWLOiHDhkgs4CQTFQ6IMfcshMVhlfg2SyXLf0N77HjKTBg0DZNSfuxS7b4MfXdGVzmIi4LJG9zFeHBEIm8SxK86nY3MJPy1fz38VJ8CoCbOAoC06DKvLiSBExiblZgPpcmSLNRr1Dh9eeaEW58+7ItdSeFNaS5cD+DidxCdTCJuM/ZgQnQQ== Authentication-Results: btinternet.com; auth=pass (PLAIN) smtp.auth=richard_c_haines@btinternet.com; bimi=skipped X-SNCR-Rigid: 613A8CC316349824 X-Originating-IP: [217.43.180.152] X-OWM-Source-IP: 217.43.180.152 (GB) X-OWM-Env-Sender: richard_c_haines@btinternet.com X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvvddrleeggddutdeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeftihgthhgrrhguucfjrghinhgvshcuoehrihgthhgrrhgupggtpghhrghinhgvshessghtihhnthgvrhhnvghtrdgtohhmqeenucggtffrrghtthgvrhhnpeelteffgeevveejheevhfetgfeuveduteetuddtffdvjeekieetgeehveefjedtfeenucfkphepvddujedrgeefrddukedtrdduhedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplhhotggrlhhhohhsthdrlhhotggrlhguohhmrghinhdpihhnvghtpedvudejrdegfedrudektddrudehvddpmhgrihhlfhhrohhmpehrihgthhgrrhgupggtpghhrghinhgvshessghtihhnthgvrhhnvghtrdgtohhmpdhnsggprhgtphhtthhopeelpdhrtghpthhtohepuggvmhhiohgsvghnohhurhesghhmrghilhdrtghomhdprhgtphhtthhopegvphgrrhhishesphgrrhhishhplhgrtggvrdhorhhgpdhrtghpthhtohepjhgvfhhfvhesghhoohhglhgvrdgtohhmpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgruhhlsehprghulhdqmhhoohhrvgdrtghomhdprhgt phhtthhopehrihgthhgrrhgupggtpghhrghinhgvshessghtihhnthgvrhhnvghtrdgtohhmpdhrtghpthhtohepshgvlhhinhhugidqrhgvfhhpohhlihgthiesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehsvghlihhnuhigsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhtvghphhgvnhdrshhmrghllhgvhidrfihorhhksehgmhgrihhlrdgtohhm X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean X-SNCR-hdrdom: btinternet.com Received: from localhost.localdomain (217.43.180.152) by re-prd-rgout-001.btmx-prd.synchronoss.net (5.8.716.04) (authenticated as richard_c_haines@btinternet.com) id 613A8CC316349824; Fri, 25 Feb 2022 17:54:51 +0000 From: Richard Haines To: paul@paul-moore.com, stephen.smalley.work@gmail.com, eparis@parisplace.org, demiobenour@gmail.com Cc: selinux@vger.kernel.org, linux-kernel@vger.kernel.org, selinux-refpolicy@vger.kernel.org, jeffv@google.com, Richard Haines Subject: [PATCH V4] security/selinux: Always allow FIOCLEX and FIONCLEX Date: Fri, 25 Feb 2022 17:54:38 +0000 Message-Id: <20220225175438.302365-1-richard_c_haines@btinternet.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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: selinux-refpolicy@vger.kernel.org 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. As this patch removes access controls, a policy capability needs to be enabled in policy to always allow these ioctls. Based-on-patch-by: Demi Marie Obenour Signed-off-by: Richard Haines --- V2 Change: Control via a policy capability. V3 Change: Update switch check. V4 Change: Use POLICYDB_CAPABILITY_IOCTL_SKIP_CLOEXEC security/selinux/hooks.c | 6 ++++++ security/selinux/include/policycap.h | 1 + security/selinux/include/policycap_names.h | 3 ++- security/selinux/include/security.h | 7 +++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 5b6895e4f..d369c2d82 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3745,6 +3745,12 @@ static int selinux_file_ioctl(struct file *file, unsigned int cmd, CAP_OPT_NONE, true); break; + case FIOCLEX: + case FIONCLEX: + if (!selinux_policycap_ioctl_skip_cloexec()) + error = ioctl_has_perm(cred, file, FILE__IOCTL, (u16) cmd); + break; + /* default case assumes that the command will go * to the file's ioctl() function. */ diff --git a/security/selinux/include/policycap.h b/security/selinux/include/policycap.h index 2ec038efb..a9e572ca4 100644 --- a/security/selinux/include/policycap.h +++ b/security/selinux/include/policycap.h @@ -11,6 +11,7 @@ enum { POLICYDB_CAPABILITY_CGROUPSECLABEL, POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION, POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS, + POLICYDB_CAPABILITY_IOCTL_SKIP_CLOEXEC, __POLICYDB_CAPABILITY_MAX }; #define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1) diff --git a/security/selinux/include/policycap_names.h b/security/selinux/include/policycap_names.h index b89289f09..ebd64afe1 100644 --- a/security/selinux/include/policycap_names.h +++ b/security/selinux/include/policycap_names.h @@ -12,7 +12,8 @@ const char *selinux_policycap_names[__POLICYDB_CAPABILITY_MAX] = { "always_check_network", "cgroup_seclabel", "nnp_nosuid_transition", - "genfs_seclabel_symlinks" + "genfs_seclabel_symlinks", + "ioctl_skip_cloexec" }; #endif /* _SELINUX_POLICYCAP_NAMES_H_ */ diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h index ac0ece013..c0d966020 100644 --- a/security/selinux/include/security.h +++ b/security/selinux/include/security.h @@ -219,6 +219,13 @@ static inline bool selinux_policycap_genfs_seclabel_symlinks(void) return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS]); } +static inline bool selinux_policycap_ioctl_skip_cloexec(void) +{ + struct selinux_state *state = &selinux_state; + + return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_IOCTL_SKIP_CLOEXEC]); +} + struct selinux_policy_convert_data; struct selinux_load_state { -- 2.35.1