0

I'm writing an apparmor profile for php (specifically 8.1), and I'm having some trouble with my particular config of php (this is for a webserver running dokuwiki).

I've gotten all the functionality whitelisted, but the one last bit is php wanting rw access to "/". Obviously this isn't good behavior, and I am unsure why it needs this? I didn't write any of the php scripts used by dokuwiki, so is this a problem with their php code or something I can fix with configs?

Apr 02 11:52:31 wiki audit[203102]: AVC apparmor="DENIED" operation="file_mmap" profile="/usr/sbin/php-fpm8.1" name="/" pid=203102 comm="php-fpm8.1" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0
Apr 02 11:52:31 wiki kernel: audit: type=1400 audit(1680450751.151:3038): apparmor="DENIED" operation="file_mmap" profile="/usr/sbin/php-fpm8.1" name="/" pid=203102 comm="php-fpm8.1" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0

My profile:

include <tunables/global>

/usr/sbin/php-fpm8.1 flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/nameservice>
  include <abstractions/openssl>
  include <abstractions/php>
  include <abstractions/user-tmp>

  capability net_admin,
  capability dac_override,
  capability kill,
  capability chown,
  capability setgid,
  capability setuid,

  /usr/sbin/php-fpm8.1 mr,
  owner /proc/sys/kernel/random/boot_id r,
  owner /run/systemd/userdb/ r,
  owner /var/log/php* w,

  # Data Directory
  owner /var/www/dokuwiki/** rw,
}

php abstraction:

  # shared snippets for config files
  /etc/php/{7??,8??}/** r,

  # Xlibs
  /usr/X11R6/lib{,32,64}/lib*.so* mr,
  # php extensions
  /usr/lib{64,}/php{,7*,8*}/*/*.so mr,

  # ICU (unicode support) data tables
  /usr/share/icu/*/*.dat r,

  # php sock and pid files
  /run/php/** rw,

  # php session mmap socket
  /var/lib/php{,7*,8*}/session_mm_* rwlk,
  # file based session handler
  /var/lib/php{,7*,8*}/sess_* rwlk,
  /var/lib/php{,7*,8*}/sessions/* rwlk,

  # php libraries
  /usr/share/php{,7*,8*}/ r,
  /usr/share/php{,7*,8*}/** mr,

  # MySQL extension
  /usr/share/mysql/** r,

  # Zend opcache
  /tmp/.ZendSem.* rwlk,

Side note: I can set this option: owner / rw, and that satisfies php. But still makes me uncomfortable, is there anyway to give this access safely, or is owner just as bad?

3
  • No PHP anything should need access to / for any reason. You may want to ask the people who made Dokuwiki whether this is a bug on their end, where the application root is being confused with actual root 🤔
    – matigo
    Apr 2, 2023 at 23:12
  • Will do. Its interesting that '/ rw,' alone satisfies it. As I understand it, that would only allow php to read and write into root directory, but not any directories under that. Plus regular permissions still apply. It definitely seems like a mistake on dokuwiki side, as it doesn't try and do anything else in / (as far as I know)
    – user1148214
    Apr 3, 2023 at 1:28
  • @matigo I was just applying a php profile to another server - nextcloud with php8.2 - and it has the exact same deny rw /. So I guess its a commonly overlooked issue when devs are writing these php scripts?
    – user1148214
    Apr 8, 2023 at 16:06

0

You must log in to answer this question.