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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/parted
profile parted @{exec_path} {
  include <abstractions/base>
  include <abstractions/disks-write>

  # Needed to inform the system of newly created/removed partitions
  #  ioctl(3, BLKRRPART)              = -1 EACCES (Permission denied)
  #
  #  Error: Partition(s) * on /dev/sd* 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}/udevadm    rCx -> udevadm,

  @{bin}/dmidecode rPx,

  /etc/inputrc r,

  # Image files
  owner @{user_img_dirs}/{,**} rwk,

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

  /dev/mapper/ r,
  /dev/mapper/control rw,

  profile udevadm {
    include <abstractions/base>

    ptrace (read),

    @{bin}/udevadm mr,

    /etc/udev/udev.conf r,

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

    # file_inherit
    include <abstractions/disks-write>  # lots of files in this abstraction get inherited
    owner @{user_img_dirs}/{,**} rwk,

  }

  include if exists <local/parted>
}
