github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/interfaces/builtin/kernel_module_control.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016-2017 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package builtin
    21  
    22  const kernelModuleControlSummary = `allows insertion, removal and querying of kernel modules`
    23  
    24  const kernelModuleControlBaseDeclarationPlugs = `
    25    kernel-module-control:
    26      allow-installation: false
    27      deny-auto-connection: true
    28  `
    29  
    30  const kernelModuleControlBaseDeclarationSlots = `
    31    kernel-module-control:
    32      allow-installation:
    33        slot-snap-type:
    34          - core
    35      deny-auto-connection: true
    36  `
    37  
    38  const kernelModuleControlConnectedPlugAppArmor = `
    39  # Description: Allow insertion, removal and querying of modules.
    40  
    41  capability sys_module,
    42  @{PROC}/modules r,
    43  /{,usr/}bin/kmod ixr,
    44  
    45  # FIXME: moved to physical-memory-observe (will be removed when using different
    46  # policies for different bases)
    47  /dev/mem r,
    48  
    49  # Required to use SYSLOG_ACTION_READ_ALL and SYSLOG_ACTION_SIZE_BUFFER when
    50  # /proc/sys/kernel/dmesg_restrict is '1' (syslog(2)). These operations are
    51  # required to verify kernel modules that are loaded. This also exposes kernel
    52  # pointer addresses via %pK format specifiers for processes running with this
    53  # capability when accessing /proc/kallsyms, etc when kptr_restrict=1.
    54  capability syslog,
    55  
    56  # Allow reading information about loaded kernel modules
    57  /sys/module/{,**} r,
    58  /etc/modprobe.d/{,**} r,
    59  /lib/modprobe.d/{,**} r,
    60  `
    61  
    62  const kernelModuleControlConnectedPlugSecComp = `
    63  # Description: Allow insertion, removal and querying of modules.
    64  
    65  init_module
    66  finit_module
    67  delete_module
    68  `
    69  
    70  var kernelModuleControlConnectedPlugUDev = []string{`KERNEL=="mem"`}
    71  
    72  func init() {
    73  	registerIface(&commonInterface{
    74  		name:                  "kernel-module-control",
    75  		summary:               kernelModuleControlSummary,
    76  		implicitOnCore:        true,
    77  		implicitOnClassic:     true,
    78  		baseDeclarationPlugs:  kernelModuleControlBaseDeclarationPlugs,
    79  		baseDeclarationSlots:  kernelModuleControlBaseDeclarationSlots,
    80  		connectedPlugAppArmor: kernelModuleControlConnectedPlugAppArmor,
    81  		connectedPlugSecComp:  kernelModuleControlConnectedPlugSecComp,
    82  		connectedPlugUDev:     kernelModuleControlConnectedPlugUDev,
    83  	})
    84  }