gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/qualcomm_ipc_router.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2021 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 import ( 23 "fmt" 24 25 "gitee.com/mysnapcore/mysnapd/interfaces" 26 apparmor_sandbox "gitee.com/mysnapcore/mysnapd/sandbox/apparmor" 27 "gitee.com/mysnapcore/mysnapd/strutil" 28 ) 29 30 /* 31 * The AF_QIPCRTR (42) is defined in linux kernel include/linux/socket.h[1] 32 * The implementation of this protocol is in net/qrtr[2] 33 * 34 * [1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/linux/socket.h 35 * [2] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/net/qrtr 36 */ 37 const qipcrtrSummary = `allows access to the Qualcomm IPC Router sockets` 38 39 const qipcrtrBaseDeclarationSlots = ` 40 qualcomm-ipc-router: 41 allow-installation: 42 slot-snap-type: 43 - core 44 deny-auto-connection: true 45 ` 46 47 const qipcrtrConnectedPlugAppArmor = ` 48 # Description: allows access to the Qualcomm IPC Router sockets 49 # and limits to sock_dgram only 50 network qipcrtr, 51 52 # CAP_NET_ADMIN required for port number smaller QRTR_MIN_EPH_SOCKET per 'https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/net/qrtr/qrtr.c' 53 capability net_admin, 54 ` 55 56 const qipcrtrConnectedPlugSecComp = ` 57 # Description: allows access to the Qualcomm IPC Router sockets 58 bind 59 60 # We allow AF_QIPCRTR in the default template since it is mediated via the AppArmor rule 61 #socket AF_QIPCRTR 62 ` 63 64 type qualcomIPCRouterInterface struct { 65 commonInterface 66 } 67 68 func (iface *qualcomIPCRouterInterface) BeforeConnectPlug(plug *interfaces.ConnectedPlug) error { 69 if apparmor_sandbox.ProbedLevel() == apparmor_sandbox.Unsupported { 70 // no apparmor means we don't have to deal with parser features 71 return nil 72 } 73 features, err := apparmor_sandbox.ParserFeatures() 74 if err != nil { 75 return err 76 } 77 78 if !strutil.ListContains(features, "qipcrtr-socket") { 79 // then the host system doesn't have the required feature to compile the 80 // policy, the qipcrtr socket is a new addition not present in i.e. 81 // xenial 82 return fmt.Errorf("cannot connect plug on system without qipcrtr socket support") 83 } 84 85 return nil 86 } 87 88 func init() { 89 registerIface(&qualcomIPCRouterInterface{ 90 commonInterface{ 91 name: "qualcomm-ipc-router", 92 summary: qipcrtrSummary, 93 implicitOnCore: true, 94 implicitOnClassic: true, 95 connectedPlugAppArmor: qipcrtrConnectedPlugAppArmor, 96 baseDeclarationSlots: qipcrtrBaseDeclarationSlots, 97 connectedPlugSecComp: qipcrtrConnectedPlugSecComp, 98 }, 99 }) 100 }