# 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/3.0>,

include <tunables/global>

@{exec_path} = @{lib}/systemd/system-generators/zram-generator
profile zram-generator @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/common/systemd>

  capability sys_module,

  @{exec_path} mr,

  @{bin}/kmod                    rix,
  @{bin}/systemd-detect-virt     rPx,
  @{lib}/systemd/systemd-makefs  rPx,

  /etc/systemd/zram-generator.conf r,
  /etc/modprobe.d/{,**} r,

  owner @{run}/systemd/generator/{,*/}var-cache-makepkg.mount rw,
  owner @{run}/systemd/generator/dev-zram@{int}.swap rw,
  owner @{run}/systemd/generator/swap.target.wants/{,dev-zram@{int}.swap} rw,
  owner @{run}/systemd/generator/systemd-zram-setup@zram@{int}.service.d/{,*.conf} rw,

  @{sys}/block/zram@{int}/{disksize,reset} rw,
  @{sys}/devices/virtual/block/zram@{int}/{disksize,reset,comp_algorithm} rw,
  @{sys}/module/compression r,

  @{PROC}/crypto r,

  owner /dev/pts/@{int} rw,

  include if exists <local/zram-generator>
}

# vim:syntax=apparmor
