# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2019-2021 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} = @{bin}/f3fix
profile f3fix /{,usr/}{,s}bin/f3fix flags=(complain) {
  include <abstractions/base>
  include <abstractions/disks-write>

  # To remove the following errors:
  #  Error: Partition(s) * on /dev/sdb have been written, but we have been unable to inform the
  #  kernel of the change, probably because it/they are in use.  As a result, the old partition(s)
  #  will remain in use.  You should reboot now before making further changes.
  capability sys_admin,

  # Needed? (##FIXME##)
  capability sys_rawio,

  # Needed?
  ptrace (read),

  @{exec_path} mr,

  @{sh_path}         rix,

  @{bin}/dmidecode  rPx,

  @{bin}/udevadm     rCx -> udevadm,

  owner @{PROC}/@{pid}/mounts r,
        @{PROC}/swaps r,

  profile udevadm flags=(complain) {
    include <abstractions/base>

    ptrace (read),

    @{bin}/udevadm mr,

    /etc/udev/udev.conf r,

    owner @{PROC}/@{pid}/stat r,
    owner @{PROC}/@{pid}/cgroup r,
          @{PROC}/cmdline r,
          @{PROC}/1/sched r,
          @{PROC}/1/environ r,
          @{PROC}/sys/kernel/osrelease r,
          @{PROC}/sys/kernel/random/boot_id r,

    @{sys}/firmware/efi/efivars/SecureBoot-@{uuid} r,

    # file_inherit
    /dev/sd[a-z]* rw,

  }

  include if exists <local/f3fix>
}

