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.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 CF8E0C282CE for ; Tue, 9 Apr 2019 12:02:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 94B4E20833 for ; Tue, 9 Apr 2019 12:02:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ieee.org header.i=@ieee.org header.b="J8ggdyDC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726387AbfDIMC0 (ORCPT ); Tue, 9 Apr 2019 08:02:26 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:41513 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726001AbfDIMC0 (ORCPT ); Tue, 9 Apr 2019 08:02:26 -0400 Received: by mail-qt1-f193.google.com with SMTP id w30so19315161qta.8 for ; Tue, 09 Apr 2019 05:02:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ieee.org; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=c02lyeod90t4JFhkbWIYoiC6teFP8862tcEx7v9xjaU=; b=J8ggdyDCbqgDqVzNhxN0zw2v0yzlT8fFtc0zs4C34RpkYGM8c2Q4DRGifJOoOWlscS HNgS/UuCaNAS+56TreUot8h1aFcK8ZJtUYohMU0f7piRrdgzlyJR+6Kf6md7t1EPGJFe +ZIE2G76XHL41cwVuWaxnyrkPZgCb2UD1+ez4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=c02lyeod90t4JFhkbWIYoiC6teFP8862tcEx7v9xjaU=; b=D/QzezMDi/5042CjfwERabp97Hxnya6ZsOYKHDRSUq0dviZ52N/KXdGtCa49cl4oTQ ziEhnS9mRXlA4R2mjDXRfN0po70fmyNUXsdnC+rEfNj1hQ+c7SPnidwCcbOU52cHfn7s w4HrYKOf40xVCPEzPY1kKRW2Jf9N6GJvCJ9KpwGNOvyz56ERj/JY5/4/LQQ6rj6xHaRk VlsJeSoXXtmVhISjmVKdfXhkZNOi7crvMEVUJeyuA/iMLtmgzsmjcAZuKl8OkqqwXWTr NFWmcr9nxz7JDDysD7TK2cL+b00uWgoqEccTmhjK05B6YP+OXTTnMJ30qglwgCx0UgUq RlCg== X-Gm-Message-State: APjAAAXMwc/cMwaYhu+N23Egt3hQ0aSaaCbjlO5luEIchgIFBAxmrI6W ivZIesGNYNqqmbB0PpnPnNqquOPttTg= X-Google-Smtp-Source: APXvYqxxfe4p4qZ32CU8+lYLDh40eddUdQdheLDkiUEhUrkZXnw4kInW7R/U3jb5ujOqSOTXlnF6zQ== X-Received: by 2002:ac8:38b6:: with SMTP id f51mr30088583qtc.33.1554811344636; Tue, 09 Apr 2019 05:02:24 -0700 (PDT) Received: from [192.168.1.190] (pool-108-15-23-247.bltmmd.fios.verizon.net. [108.15.23.247]) by smtp.gmail.com with ESMTPSA id v129sm17945022qka.77.2019.04.09.05.02.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Apr 2019 05:02:24 -0700 (PDT) Subject: Re: [PATCH] Label /sys/kernel/ns_last_pid as sysctl_kernel_ns_last_pid_t To: Lukas Vrabec , selinux-refpolicy@vger.kernel.org References: <20190408161907.10322-1-lvrabec@redhat.com> From: Chris PeBenito Message-ID: <42a81b2d-115e-4202-832d-190ae1da46e6@ieee.org> Date: Tue, 9 Apr 2019 07:54:44 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <20190408161907.10322-1-lvrabec@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: selinux-refpolicy-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux-refpolicy@vger.kernel.org On 4/8/19 12:19 PM, Lukas Vrabec wrote: > 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) Is this associate really necessary? It's not used for any other sysctls. > +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 > -- Chris PeBenito