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 ADF76C10F0E for ; Fri, 12 Apr 2019 11:57:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6079C2082E for ; Fri, 12 Apr 2019 11:57:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ieee.org header.i=@ieee.org header.b="KrPj6Yt8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726682AbfDLL5S (ORCPT ); Fri, 12 Apr 2019 07:57:18 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:37692 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726327AbfDLL5S (ORCPT ); Fri, 12 Apr 2019 07:57:18 -0400 Received: by mail-qt1-f194.google.com with SMTP id z16so10840659qtn.4 for ; Fri, 12 Apr 2019 04:57:17 -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=4fAbykJ1jnQXPb+5VK+AIgVQy0yAqZ6Oz0txISnx0rY=; b=KrPj6Yt8iHjkHSwPwYzvuqGhpo2Pfe+cRL1Wq0vpwJi/nz90vk886KxoXFZWHbNzEc w+4ewJ7iudTFT8PTICMx3lLaYhVjh+z33SYTmJjE5F1D9+UdPNQHE0Bg/YA5Q5Tctd/h 3rJT7uT359SG/WnS4S6m/dgDND1R17NcE+FEU= 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=4fAbykJ1jnQXPb+5VK+AIgVQy0yAqZ6Oz0txISnx0rY=; b=G0PCXjVuR5jQw/jqM0wyizZEOm+QShBeSyfCWLX0H4uFJxhxyojnGt6Jqy7avPV4xH G4oRP96hQUArk6C2AExOcTeDfUlMcSRID+jFVo9wcamEbpjy/TYqnC56Vkf5cXxfxHfn UwnMu7NbUCFit0pOUMgkJABpMp9B8LPvq+a2RN8hHNMzIqgp+lmeMzD375sqt604coWS 6yHr9Mn39o7ZxTV+8z+0L67gqW26k8XRSx5m4LHMCrz2ZVh5fs+OV9mcGSE3hd3SMBRb ulRr0o4avsVxVrJXeic7AO5lWRvTD8Jl5bF/ayFFZWkKMDmbsamtwRXj7fMVHowWdqoz RVqw== X-Gm-Message-State: APjAAAW6sXm3WV+urjFVHhgb/kZ+dhfhN2qWS9VouOq8/cJGarisnARc n/HXthIAWWN6vEIDt7qZTKRSAMHqNQI= X-Google-Smtp-Source: APXvYqyaKwueAgrZk2eKlnxVyYczjvEX+5rKKxvMLYkF55rTtUcn4DK992uYimtDyUauP7AK/mwNRw== X-Received: by 2002:ac8:74d5:: with SMTP id j21mr48180813qtr.232.1555070236592; Fri, 12 Apr 2019 04:57:16 -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 n188sm22732531qkb.40.2019.04.12.04.57.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Apr 2019 04:57:16 -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: <20190410151832.8189-1-lvrabec@redhat.com> From: Chris PeBenito Message-ID: Date: Fri, 12 Apr 2019 07:52:43 -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: <20190410151832.8189-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/10/19 11:18 AM, 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 | 6 ++++ > 2 files changed, 66 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..f9486216 100644 > --- a/policy/modules/kernel/kernel.te > +++ b/policy/modules/kernel/kernel.te > @@ -132,6 +132,10 @@ 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; > +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 +236,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 Merged. -- Chris PeBenito