# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2015-2022 Mikhail Morfikov
# Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{lib}/bluetooth/bluetoothd
@{att} = /att/bluetoothd/
profile bluetoothd /{,usr/}lib{,exec,32,64}/bluetooth/bluetoothd  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/bus-system>
  include <abstractions/bus/org.freedesktop.hostname1>
  include <abstractions/uinput>

  # Needed for configuring HCI interfaces
  capability net_admin,
  capability net_bind_service,

  network bluetooth raw,
  network bluetooth seqpacket,
  network bluetooth stream,
  network alg seqpacket, # kernel crypto API
  network netlink raw,

  include <abstractions/bus/system/own>

  dbus bind bus=system name=org.bluez{,.*},
  dbus receive bus=system path=/{,**}
       interface=org.bluez{,.*}
       peer=(name="@{busname}"),
  dbus send bus=system path=/{,**}
       interface=org.bluez{,.*}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  dbus (send receive) bus=system path=/{,**}
       interface=org.freedesktop.DBus.Properties
       member={Get,GetAll,Set,PropertiesChanged}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  dbus receive bus=system path=/{,**}
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name="@{busname}"),
  dbus receive bus=system path=/{,**}
       interface=org.freedesktop.DBus.ObjectManager
       member=GetManagedObjects
       peer=(name="{@{busname},org.bluez{,.*}}"),
  dbus send bus=system path=/{,**}
       interface=org.freedesktop.DBus.ObjectManager
       member={InterfacesAdded,InterfacesRemoved}
       peer=(name="{@{busname},org.freedesktop.DBus}"),

  @{exec_path} mr,

  @{lib}/@{multiarch}/bluetooth/plugins/*.so mr,

  /etc/bluetooth/{,*.conf} r,

  /var/lib/bluetooth/{,**} rw,

        @{run}/sdp rw,
  owner @{run}/systemd/notify w,

  @{run}/udev/data/+hid:* r,              # For Human Interface Device (mice, controllers, drawing tablets, scanners)

  @{sys}/devices/@{pci}/rfkill@{int}/name r,
  @{sys}/devices/@{pci}/**/{uevent,name} r,
  @{sys}/devices/platform/**/rfkill/**/name r,
  @{sys}/devices/virtual/dmi/id/chassis_type r,
  @{sys}/devices/virtual/misc/uhid/**/uevent r,

  @{PROC}/sys/kernel/hostname r,

  /dev/uhid rw,
  /dev/rfkill rw,
  /dev/hidraw@{int} rw,

  include if exists <local/bluetoothd>
}

# vim:syntax=apparmor
