Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 683976 - sys-apps/apparmor-2.13.2 - Apparmor denies /usr/libexec/virt-aa-helper access to ovmf files even when profiles allows it
Summary: sys-apps/apparmor-2.13.2 - Apparmor denies /usr/libexec/virt-aa-helper access...
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: The Gentoo Linux Hardened Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-21 14:56 UTC by José Pekkarinen
Modified: 2024-02-14 09:48 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description José Pekkarinen 2019-04-21 14:56:29 UTC
Hi,

I'm hitting issues starting ovmf based domain, and it looks like a bug
in apparmor itself, as I provide an override for those files, and still
the vms fails to spin.

# virsh start os-1
error: Failed to start domain os-1
error: internal error: cannot load AppArmor profile 'libvirt-34c41008-ab91-483b-959c-81a7a12ae9be'

os section of the domain:

  <os>
    <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type>
    <loader readonly='yes' type='pflash'>/usr/share/edk2-ovmf/OVMF_CODE.fd</loader>
    <nvram>/var/lib/libvirt/qemu/nvram/os-1_VARS.fd</nvram>
    <boot dev='network'/>
    <boot dev='hd'/>
  </os>

# ls /usr/share/edk2-ovmf/
OVMF_CODE.fd  OVMF.fd  OVMF_VARS.fd

# ls /var/lib/libvirt/qemu/nvram/os-1_VARS.fd
/var/lib/libvirt/qemu/nvram/os-1_VARS.fd

From libvirt.log:

2019-04-21 14:51:09.481+0000: 9347: error : virCommandWait:2636 : internal error: Child process (LIBVIRT_LOG_OUTPUTS=3:stderr /usr/libexec/virt-aa-helper -c -u libvirt-34c41008-ab91-483b-959c-81a7a12ae9be) unexpected exit status 1: 2019-04-21 14:51:09.480+0000: 27054: info : libvirt version: 5.2.0
2019-04-21 14:51:09.480+0000: 27054: info : hostname: mole
2019-04-21 14:51:09.480+0000: 27054: error : virStorageFileBackendFileRead:129 : Failed to open file '/dev/mole-vg0/os-1-vda': Permission denied
2019-04-21 14:51:09.480+0000: 27054: error : virStorageFileBackendFileRead:129 : Failed to open file '/dev/mole-vg0/os-1-vdb': Permission denied
virt-aa-helper: error: /usr/share/edk2-ovmf/OVMF_CODE.fd
virt-aa-helper: error: skipped restricted file
virt-aa-helper: error: invalid VM definition

2019-04-21 14:51:09.481+0000: 9347: error : AppArmorGenSecurityLabel:469 : internal error: cannot load AppArmor profile 'libvirt-34c41008-ab91-483b-959c-81a7a12ae9be'

# apparmor_parser -d usr.libexec.virt-aa-helper | grep ovmf
Mode:   r:r     Name:   (/usr/share/edk2-ovmf/OVMF_{CODE,VARS}.fd)

# apparmor_parser -d usr.libexec.virt-aa-helper
----- Debugging built structures -----
Name:           virt-aa-helper
Profile Mode:   Enforce
Capabilities: dac_override dac_read_search
Network: inet inet6 
--- Entries ---
Mode:   r:r     Name:   (/**.[iI][sS][oO])
Mode:   r:r     Name:   (/**.img)
Mode:   r:r     Name:   (/**.qcow{,2})
Mode:   r:r     Name:   (/**.qed)
Mode:   r:r     Name:   (/**.raw)
Mode:   r:r     Name:   (/**.vmdk)
Mode:   r:r     Name:   (/**/disk{,.*})
Mode:   r:r     Name:   (/dev/dri/{,*})
Mode:   rwa:rwa Name:   (/dev/full)
Mode:   wa:wa   Name:   (/dev/log)
Mode:   rwa:rwa Name:   (/dev/null)
Mode:   r:r     Name:   (/dev/random)
Mode:   r:r     Name:   (/dev/urandom)
Mode:   rwa:rwa Name:   (/dev/zero)
Mode:   r:r     Name:   (/etc/apparmor.d/libvirt/*)
Mode:   rwa:rwa Name:   (/etc/apparmor.d/libvirt/libvirt-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*)
Mode:   r:r     Name:   (/etc/bindresvport.blacklist)
Mode:   rm:rm   Name:   (/etc/ld.so.cache)
Mode:   r:r     Name:   (/etc/ld.so.conf)
Mode:   r:r     Name:   (/etc/ld.so.conf.d/{,*.conf})
Mode:   r:r     Name:   (/etc/ld.so.preload)
Mode:   r:r     Name:   (/etc/libnl-3/classid)
Mode:   r:r     Name:   (/etc/locale.alias)
Mode:   r:r     Name:   (/etc/locale/**)
Mode:   r:r     Name:   (/etc/localtime)
Mode:   rwalkmx:        Name:   (/home//.ecryptfs/*/.Private/**)
        link:   (/**)
Mode:   rm:rm   Name:   (/opt/*-linux-uclibc/lib/ld-uClibc*so*)
Mode:   r:r     Name:   (/proc//[0-9]*/net/psched)
Mode:   r:      Name:   (/proc//[0-9]*/status)
Mode:   r:r     Name:   (/proc//cpuinfo)
Mode:   r:r     Name:   (/proc//filesystems)
Mode:   r:r     Name:   (/proc//meminfo)
Mode:   r:r     Name:   (/proc//stat)
Mode:   r:r     Name:   (/proc//sys/crypto/*)
Mode:   r:r     Name:   (/proc//sys/kernel/cap_last_cap)
Mode:   r:r     Name:   (/proc//sys/kernel/ngroups_max)
Mode:   r:r     Name:   (/proc//sys/kernel/version)
Mode:   r:r     Name:   (/proc//sys/vm/overcommit_memory)
Mode:   r:r     Name:   (/proc//{[1-9],[1-9][0-9],[1-9][0-9][0-9],[1-9][0-9][0-9][0-9],[1-9][0-9][0-9][0-9][0-9],[1-9][0-9][0-9][0-9][0-9][0-9],[1-4][0-9][0-9][0-9][0-9][0-9][0-9]}/{maps,auxv,status})
Mode:   wa:wa   Name:   (/run/systemd/journal/dev-log)
Mode:   wa:wa   Name:   (/run/systemd/journal/socket)
Mode:   rwa:rwa Name:   (/run/systemd/journal/stdout)
Mode:   r:r     Name:   (/sys//devices/system/cpu/)
Mode:   r:r     Name:   (/sys//devices/system/cpu/online)
Mode:   r:r     Name:   (/sys/bus/usb/devices/)
Mode:   r:r     Name:   (/sys/devices/)
Mode:   r:r     Name:   (/sys/devices/**)
Mode:   rm:rm   Name:   (/usr/lib/*-linux-gnu*/gconv/*.so)
Mode:   rm:rm   Name:   (/usr/lib/*-linux-gnu*/gconv/gconv-modules*)
Mode:   rm:rm   Name:   (/usr/libexec/virt-aa-helper)
Mode:   rm:rm   Name:   (/usr/lib{,32,64}/gconv/*.so)
Mode:   rm:rm   Name:   (/usr/lib{,32,64}/gconv/gconv-modules*)
Mode:   rm:rm   Name:   (/usr/lib{,32,64}/locale/**)
Mode:   r:r     Name:   (/usr/share/**/locale/**)
Mode:   r:r     Name:   (/usr/share/X11/locale/**)
Mode:   r:r     Name:   (/usr/share/common-licenses/**)
Mode:   r:r     Name:   (/usr/share/edk2-ovmf/OVMF_{CODE,VARS}.fd)
Mode:   r:r     Name:   (/usr/share/locale-bundle/**)
Mode:   r:r     Name:   (/usr/share/locale-langpack/**)
Mode:   r:r     Name:   (/usr/share/locale/**)
Mode:   r:r     Name:   (/usr/share/zoneinfo/)
Mode:   r:r     Name:   (/usr/share/zoneinfo/**)
Mode:   r:r     Name:   (/var/lib/libvirt/images/)
Mode:   r:r     Name:   (/var/lib/libvirt/images/**)
Mode:   r:r     Name:   (/var/lib/nova/instances/_base/*)
Mode:   r:r     Name:   (/{,var/}run/libvirt/**/[sv]d[a-z])
Mode:   r:r     Name:   (/{media,mnt,opt,srv}/**)
Mode:   r:r     Name:   (/{usr/,}lib/*-linux-gnu*/**)
Mode:   rm:rm   Name:   (/{usr/,}lib/*-linux-gnu*/**/lib*.so*)
Mode:   rm:rm   Name:   (/{usr/,}lib/*-linux-gnu*/ld{,32,64}-*.so)
Mode:   rm:rm   Name:   (/{usr/,}lib/*-linux-gnu*/lib*.so*)
Mode:   rm:rm   Name:   (/{usr/,}lib/i386-linux-gnu/tls/i686/{cmov,nosegneg}/ld-*.so)
Mode:   rm:rm   Name:   (/{usr/,}lib/i386-linux-gnu/tls/i686/{cmov,nosegneg}/lib*.so*)
Mode:   rm:rm   Name:   (/{usr/,}lib/tls/i686/{cmov,nosegneg}/ld-*.so)
Mode:   rm:rm   Name:   (/{usr/,}lib/tls/i686/{cmov,nosegneg}/lib*.so*)
Mode:   r:r     Name:   (/{usr/,}lib{,32,64}/**)
Mode:   rm:rm   Name:   (/{usr/,}lib{,32,64}/**/lib*.so*)
Mode:   rm:rm   Name:   (/{usr/,}lib{,32,64}/ld{,32,64}-*.so)
Mode:   rm:rm   Name:   (/{usr/,}lib{,32,64}/lib*.so*)
Mode:   x:x     Name:   (/{usr/,}sbin/apparmor_parser)
Mode:   r:r     Name:   ({/home//*,/root}/)
Mode:   r:r     Name:   ({/home//*,/root}/**)
Mode:   rwalkmx:        Name:   ({/home//*,/root}/.Private/**)
        link:   (/**)
Mode:   r:r     Name:   (/dev/dasd*)
Mode:   r:r     Name:   (/dev/dm-*)
Mode:   r:r     Name:   (/dev/drbd[0-9]*)
Mode:   r:r     Name:   (/dev/mapper/)
Mode:   r:r     Name:   (/dev/mapper/*)
Mode:   r:r     Name:   (/dev/nvme*)
Mode:   r:r     Name:   (/dev/sd*)
Mode:   r:r     Name:   (/dev/vd*)
Mode:   r:r     Name:   (/dev/zd[0-9]*)
Mode:   r:r     Name:   (/proc//[0-9]*/mounts)
Mode:   rwalkm:rwalkm   Name:   ({/home//*,/root}/.*)
        link:   (/**)
Mode:   rwa:rwa Name:   ({/home//*,/root}/.*/)
Mode:   rwalkm:rwalkm   Name:   ({/home//*,/root}/.*/**)
        link:   (/**)
Mode:   rwa:rwa Name:   ({/home//*,/root}/bin/)
Mode:   rwalkm:rwalkm   Name:   ({/home//*,/root}/bin/**)
        link:   (/**)
ptrace (readby ),
ptrace (tracedby ),
ptrace (read ) virt-aa-helper,
signal (receive ) unconfined,
signal virt-aa-helper,
signal set=(exists),
unix () peer=( label="virt-aa-helper"),
unix () peer=( label="unconfined"),
unix (),
unix (),

Thanks!

José.
Comment 1 José Pekkarinen 2019-04-21 15:15:11 UTC
# emerge --info
Portage 2.3.62 (python 3.6.5-final-0, default/linux/amd64/17.0, gcc-8.2.0, glibc-2.28-r6, 5.0.8 x86_64)
=================================================================
System uname: Linux-5.0.8-x86_64-AMD_EPYC_7401P_24-Core_Processor-with-gentoo-2.6
KiB Mem:   131656932 total,   9412856 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Sat, 20 Apr 2019 15:30:01 +0000
Head commit of repository gentoo: 56312573763e794982d7a7284e7e7d1a8a9f8eaa
sh bash 4.4_p23-r1
ld GNU ld (Gentoo 2.31.1 p5) 2.31.1
distcc 3.3.2 x86_64-pc-linux-gnu [disabled]
app-shells/bash:          4.4_p23-r1::gentoo
dev-lang/perl:            5.26.2::gentoo
dev-lang/python:          2.7.15::gentoo, 3.6.5::gentoo
dev-util/cmake:           3.9.6::gentoo
dev-util/pkgconfig:       0.29.2::gentoo
sys-apps/baselayout:      2.6-r1::gentoo
sys-apps/openrc:          0.38.3-r1::gentoo
sys-apps/sandbox:         2.13::gentoo
sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r4::gentoo
sys-devel/automake:       1.16.1-r1::gentoo
sys-devel/binutils:       2.31.1-r4::gentoo
sys-devel/gcc:            7.3.0-r6::gentoo, 8.2.0-r6::gentoo
sys-devel/gcc-config:     2.0::gentoo
sys-devel/libtool:        2.4.6-r3::gentoo
sys-devel/make:           4.2.1-r4::gentoo
sys-kernel/linux-headers: 4.14-r1::gentoo (virtual/os-headers)
sys-libs/glibc:           2.28-r6::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000
    sync-rsync-verify-metamanifest: no
    sync-rsync-extra-opts: 
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-jobs: 1

foxiverlay
    location: /var/lib/layman/foxiverlay
    masters: gentoo
    priority: 50

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=znver1 -mtune=znver1 -O2 -fomit-frame-pointer -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-march=znver1 -mtune=znver1 -O2 -fomit-frame-pointer -pipe"
DISTDIR="/usr/portage/distfiles"
ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_GB.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j 48"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="acl amd64 apparmor berkdb bzip2 cli crypt cxx dbus dri elogind fortran gdbm iconv ipv6 libtirpc multilib ncurses nls nptl openmp pam pcre readline seccomp ssl tcpd unicode xattr zlib" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx mmxext sse sse2" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" NETBEANS_MODULES="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-6 php7-1" POSTGRES_TARGETS="postgres9_5 postgres10" PYTHON_SINGLE_TARGET="python3_6" PYTHON_TARGETS="python2_7 python3_6" RUBY_TARGETS="ruby24" USERLAND="GNU" VIDEO_CARDS="radeonsi amdgpu" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 2 Jeroen Roovers (RETIRED) gentoo-dev 2019-04-21 15:37:16 UTC
What's with the brackets?
Comment 3 José Pekkarinen 2019-04-21 18:34:23 UTC
(In reply to Jeroen Roovers from comment #2)
> What's with the brackets?

Nothing special, just forgot to read some other bugs to remember the
format in advance, sorry about that! :)
Comment 4 José Pekkarinen 2019-04-21 19:12:45 UTC
some rare point during examination:

# aa-complain usr.libexec.virt-aa-helper
Setting /etc/apparmor.d/usr.libexec.virt-aa-helper to complain mode.
# aa-complain usr.libexec.virt-aa-helper
----- Debugging built structures -----
Name:           virt-aa-helper
Profile Mode:   Complain
Capabilities: dac_override dac_read_search
Network: inet inet6
...
# virsh start os-1
error: Failed to start domain os-1
error: internal error: cannot load AppArmor profile 'libvirt-34c41008-ab91-483b-959c-81a7a12ae9be'

And the error in the libvirtd.log:

2019-04-21 19:09:41.910+0000: 9349: error : virCommandWait:2636 : internal error: Child process (LIBVIRT_LOG_OUTPUTS=3:stderr /usr/libexec/virt-aa-helper -c -u libvirt-34c41008-ab91-483b-959c-81a7a12ae9be) unexpected exit status 1: 2019-04-21 19:09:41.909+0000: 41822: info : libvirt version: 5.2.0
2019-04-21 19:09:41.909+0000: 41822: info : hostname: mole
2019-04-21 19:09:41.909+0000: 41822: error : virStorageFileBackendFileRead:129 : Failed to open file '/dev/mole-vg0/os-1-vda': Permission denied
2019-04-21 19:09:41.909+0000: 41822: error : virStorageFileBackendFileRead:129 : Failed to open file '/dev/mole-vg0/os-1-vdb': Permission denied
virt-aa-helper: error: /usr/share/edk2-ovmf/OVMF_CODE.fd
virt-aa-helper: error: skipped restricted file
virt-aa-helper: error: invalid VM definition

Setting it in complain mode shouldn't actually restrict it's access as
far as I know.
Comment 5 José Pekkarinen 2019-04-21 19:15:11 UTC
(In reply to José Pekkarinen from comment #4)
> some rare point during examination:
> 
> # aa-complain usr.libexec.virt-aa-helper
> Setting /etc/apparmor.d/usr.libexec.virt-aa-helper to complain mode.
> # aa-complain usr.libexec.virt-aa-helper
> ----- Debugging built structures -----
> Name:           virt-aa-helper
> Profile Mode:   Complain
> Capabilities: dac_override dac_read_search
> Network: inet inet6
> ...

Sorry here, I copied the wrong command, it was this:

# apparmor_parser -d /etc/apparmor.d/usr.libexec.virt-aa-helper
Comment 6 José Pekkarinen 2019-04-21 19:37:33 UTC
Upstream bug reported to follow up:

https://bugs.launchpad.net/apparmor/+bug/1825745
Comment 7 Thomas Schneider 2021-11-29 14:31:26 UTC
As pointed out in the upstream AppArmor bug, this is in fact an issue with libvirt.  /usr/libexec/virt-aa-helper has a hardcoded list of paths a VM may want, and if a path does not match, it errors out, the profile isn’t created in the first place and the VM thus fails to start.

A patch that will probably fix it (still compiling, so I can’t confirm it yet):

```
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -475,6 +475,8 @@ valid_path(const char *path, const bool
         "/vmlinuz",
         "/initrd",
         "/initrd.img",
+        "/usr/share/qemu/",              /* Gentoo firmware path */
+        "/usr/share/edk2-ovmf/",         /* Gentoo firmware path */
         "/usr/share/edk2/",
         "/usr/share/OVMF/",              /* for OVMF images */
         "/usr/share/ovmf/",              /* for OVMF images */
```

This should likely be reported with libvirt, maybe a runtime configuration knob would make sense.  But even if not, they should be aware of it.