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=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_PASS autolearn=ham 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 8C28EC10F13 for ; Mon, 8 Apr 2019 16:19:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 64E0921473 for ; Mon, 8 Apr 2019 16:19:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727263AbfDHQTO (ORCPT ); Mon, 8 Apr 2019 12:19:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57818 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726228AbfDHQTN (ORCPT ); Mon, 8 Apr 2019 12:19:13 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68E4AC0B615A for ; Mon, 8 Apr 2019 16:19:13 +0000 (UTC) Received: from lvrabec-workstation.brq.redhat.com (unknown [10.43.12.151]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B972B5DA35; Mon, 8 Apr 2019 16:19:12 +0000 (UTC) From: Lukas Vrabec To: selinux-refpolicy@vger.kernel.org Cc: Lukas Vrabec Subject: [PATCH] Label /sys/kernel/ns_last_pid as sysctl_kernel_ns_last_pid_t Date: Mon, 8 Apr 2019 18:19:07 +0200 Message-Id: <20190408161907.10322-1-lvrabec@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 08 Apr 2019 16:19:13 +0000 (UTC) Sender: selinux-refpolicy-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux-refpolicy@vger.kernel.org CRIU can influence the PID of the threads it wants to create. CRIU uses /proc/sys/kernel/ns_last_pidto tell the kernel which PID it wants for the next clone(). So it has to write to that file. This feels like a problematic as it opens up the container writing to all sysctl_kernel_t. Using new label container_t will just write to sysctl_kernel_ns_last_pid_t instad writing to more generic sysctl_kernel_t files. --- policy/modules/kernel/kernel.if | 60 +++++++++++++++++++++++++++++++++ policy/modules/kernel/kernel.te | 7 ++++ 2 files changed, 67 insertions(+) diff --git a/policy/modules/kernel/kernel.if b/policy/modules/kernel/kernel.if index 1ad282aa..3f0a2dbe 100644 --- a/policy/modules/kernel/kernel.if +++ b/policy/modules/kernel/kernel.if @@ -2150,6 +2150,66 @@ interface(`kernel_mounton_kernel_sysctl_files',` allow $1 sysctl_kernel_t:file { getattr mounton }; ') +######################################## +## +## Read kernel ns lastpid sysctls. +## +## +## +## Domain allowed access. +## +## +## +# +interface(`kernel_read_kernel_ns_lastpid_sysctls',` + gen_require(` + type proc_t, sysctl_t, sysctl_kernel_ns_last_pid_t; + ') + + read_files_pattern($1, { proc_t sysctl_t sysctl_kernel_ns_last_pid_t }, sysctl_kernel_ns_last_pid_t) + + list_dirs_pattern($1, { proc_t sysctl_t }, sysctl_kernel_ns_last_pid_t) +') + +######################################## +## +## Do not audit attempts to write kernel ns lastpid sysctls. +## +## +## +## Domain to not audit. +## +## +# +interface(`kernel_dontaudit_write_kernel_ns_lastpid_sysctl',` + gen_require(` + type sysctl_kernel_ns_last_pid_t; + ') + + dontaudit $1 sysctl_kernel_ns_last_pid_t:file write; +') + +######################################## +## +## Read and write kernel ns lastpid sysctls. +## +## +## +## Domain allowed access. +## +## +## +# +interface(`kernel_rw_kernel_ns_lastpid_sysctl',` + gen_require(` + type proc_t, sysctl_t, sysctl_kernel_ns_last_pid_t; + ') + + rw_files_pattern($1, { proc_t sysctl_t sysctl_kernel_ns_last_pid_t }, sysctl_kernel_ns_last_pid_t) + + list_dirs_pattern($1, { proc_t sysctl_t }, sysctl_kernel_ns_last_pid_t) +') + ######################################## ## ## Search filesystem sysctl directories. diff --git a/policy/modules/kernel/kernel.te b/policy/modules/kernel/kernel.te index 8e958074..f5ec1c22 100644 --- a/policy/modules/kernel/kernel.te +++ b/policy/modules/kernel/kernel.te @@ -132,6 +132,11 @@ genfscon proc /sys/fs gen_context(system_u:object_r:sysctl_fs_t,s0) type sysctl_kernel_t, sysctl_type; genfscon proc /sys/kernel gen_context(system_u:object_r:sysctl_kernel_t,s0) +# /sys/kernel/ns_last_pid file +type sysctl_kernel_ns_last_pid_t, sysctl_type; +fs_associate(sysctl_kernel_ns_last_pid_t) +genfscon proc /sys/kernel/ns_last_pid gen_context(system_u:object_r:sysctl_kernel_ns_last_pid_t,s0) + # /proc/sys/kernel/modprobe file type sysctl_modprobe_t, sysctl_type; genfscon proc /sys/kernel/modprobe gen_context(system_u:object_r:sysctl_modprobe_t,s0) @@ -232,6 +237,8 @@ allow kernel_t sysctl_kernel_t:dir list_dir_perms; allow kernel_t sysctl_kernel_t:file read_file_perms; allow kernel_t sysctl_t:dir list_dir_perms; +allow kernel_t sysctl_kernel_ns_last_pid_t:file read_file_perms; + # Other possible mount points for the root fs are in files allow kernel_t unlabeled_t:dir mounton; # Kernel-generated traffic e.g., TCP resets on -- 2.20.1