github.com/ethanhsieh/snapd@v0.0.0-20210615102523-3db9b8e4edc5/interfaces/builtin/raw_usb.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 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 rawusbSummary = `allows raw access to all USB devices`
    23  
    24  const rawusbBaseDeclarationSlots = `
    25    raw-usb:
    26      allow-installation:
    27        slot-snap-type:
    28          - core
    29      deny-auto-connection: true
    30  `
    31  
    32  const rawusbConnectedPlugAppArmor = `
    33  # Description: Allow raw access to all connected USB devices.
    34  # This gives privileged access to the system.
    35  /dev/bus/usb/[0-9][0-9][0-9]/[0-9][0-9][0-9] rw,
    36  
    37  # Allow access to all ttyUSB devices too
    38  /dev/tty{USB,ACM}[0-9]* rwk,
    39  @{PROC}/tty/drivers r,
    40  
    41  # Allow raw access to USB printers (i.e. for receipt printers in POS systems).
    42  /dev/usb/lp[0-9]* rwk,
    43  
    44  # Allow detection of usb devices. Leaks plugged in USB device info
    45  /sys/bus/usb/devices/ r,
    46  /sys/devices/pci**/usb[0-9]** r,
    47  /sys/devices/platform/{sbc,soc}/*.usb/usb[0-9]** r,
    48  
    49  /run/udev/data/c16[67]:[0-9] r, # ACM USB modems
    50  /run/udev/data/b180:*    r, # various USB block devices
    51  /run/udev/data/c18[089]:* r, # various USB character devices: USB serial converters, etc.
    52  /run/udev/data/+usb:* r,
    53  `
    54  
    55  const rawusbConnectedPlugSecComp = `
    56  # Description: Allow raw access to all connected USB devices.
    57  # This gives privileged access to the system.
    58  
    59  # kernel uevents
    60  socket AF_NETLINK - NETLINK_KOBJECT_UEVENT
    61  `
    62  
    63  var rawusbConnectedPlugUDev = []string{
    64  	`SUBSYSTEM=="usb"`,
    65  	`SUBSYSTEM=="usbmisc"`,
    66  	`SUBSYSTEM=="tty", ENV{ID_BUS}=="usb"`,
    67  }
    68  
    69  func init() {
    70  	registerIface(&commonInterface{
    71  		name:                  "raw-usb",
    72  		summary:               rawusbSummary,
    73  		implicitOnCore:        true,
    74  		implicitOnClassic:     true,
    75  		baseDeclarationSlots:  rawusbBaseDeclarationSlots,
    76  		connectedPlugAppArmor: rawusbConnectedPlugAppArmor,
    77  		connectedPlugSecComp:  rawusbConnectedPlugSecComp,
    78  		connectedPlugUDev:     rawusbConnectedPlugUDev,
    79  	})
    80  }