# apparmor.d - Full set of apparmor profiles
# 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} = @{bin}/gnome-system-monitor
profile gnome-system-monitor @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/bus-session>
  include <abstractions/dconf-write>
  include <abstractions/gnome-strict>
  include <abstractions/graphics>
  include <abstractions/nameservice-strict>

  capability sys_ptrace,

  network inet dgram,
  network inet6 dgram,
  network netlink raw,

  ptrace (read),

  signal (send) set=(kill term cont stop),

  #aa:dbus own bus=session name=org.gnome.SystemMonitor

  @{exec_path} mr,

  @{sh_path}    rix,
  @{bin}/lsblk  rPx,
  @{bin}/pkexec rCx -> pkexec,
  @{bin}/sed    rix,
  @{bin}/tr     rix,

  /usr/share/gnome-system-monitor/{,**} r,
  /usr/share/firefox-esr/browser/chrome/icons/default/*.png r,

  / r,

  owner @{tmp}/gdkpixbuf-xpm-tmp.@{rand6} rw,

  owner @{run}/user/@{uid}/doc/ rw,
  owner @{run}/user/@{uid}/gnome-shell-disable-extensions w,

  @{run}/systemd/sessions/*     r,
  @{run}/systemd/sessions/*.ref r,
  @{run}/mount/utab r,

  @{sys}/devices/@{pci}/net/*/statistics/collisions r,
  @{sys}/devices/@{pci}/net/*/statistics/rx_{bytes,errors,packets} r,
  @{sys}/devices/@{pci}/net/*/statistics/tx_{bytes,errors,packets} r,
  @{sys}/devices/@{pci}/usb@{int}/**/net/*/statistics/collisions r,
  @{sys}/devices/@{pci}/usb@{int}/**/net/*/statistics/rx_{bytes,errors,packets} r,
  @{sys}/devices/@{pci}/usb@{int}/**/net/*/statistics/tx_{bytes,errors,packets} r,
  @{sys}/devices/@{pci}/virtio@{int}/**/stat r,
  @{sys}/devices/virtual/net/*/statistics/collisions r,
  @{sys}/devices/virtual/net/*/statistics/rx_{bytes,errors,packets} r,
  @{sys}/devices/virtual/net/*/statistics/tx_{bytes,errors,packets} r,

  @{PROC}/ r,
  @{PROC}/@{pids}/attr/current r,
  @{PROC}/@{pids}/cgroup r,
  @{PROC}/@{pids}/cmdline r,
  @{PROC}/@{pids}/fd/ r,
  @{PROC}/@{pids}/io r,
  @{PROC}/@{pids}/mountinfo r,
  @{PROC}/@{pids}/mounts r,
  @{PROC}/@{pids}/net/dev r,
  @{PROC}/@{pids}/net/tcp{,6} r,
  @{PROC}/@{pids}/net/unix r,
  @{PROC}/@{pids}/smaps r,
  @{PROC}/@{pids}/stat r,
  @{PROC}/@{pids}/statm r,
  @{PROC}/@{pids}/wchan r,
  @{PROC}/diskstats r,
  @{PROC}/vmstat r,

  owner @{PROC}/@{pid}/task/@{tid}/comm rw,

  deny owner @{user_share_dirs}/gvfs-metadata/{,*} r,

  /dev/tty rw,

  profile pkexec {
    include <abstractions/base>
    include <abstractions/app/pkexec>

    include if exists <local/gnome-system-monitor_pkexec>
  }

  include if exists <local/gnome-system-monitor>
}

# vim:syntax=apparmor
