]> git.ipfire.org Git - thirdparty/libvirt.git/commit
vircgroup: introduce virCgroupV2DevicesAttachProg
authorPavel Hrdina <phrdina@redhat.com>
Mon, 24 Jun 2019 12:15:31 +0000 (14:15 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 15 Nov 2019 11:58:05 +0000 (12:58 +0100)
commit48423a0b5d5a8591d5c46faabfc2b0071c152e8f
tree0614fac6c64e3f04c23b688535de63a986528af3
parent30b6ddc44cd46b9671af584f57c0e36f61145464
vircgroup: introduce virCgroupV2DevicesAttachProg

This function loads the BPF prog with prepared map into kernel and
attaches it into guest cgroup.  It can be also used to replace existing
program in the cgroup if we need to resize BPF map to store more rules
for devices. The old program will be closed and removed from kernel.

There are two possible ways how to create BPF program:

    - One way is to write simple C-like code which can by compiled into
      BPF object file which can be loaded into kernel using elfutils.

    - The second way is to define macros which look like assembler
      instructions and can be used directly to create BPF program that
      can be directly loaded into kernel.

Since the program is not too complex we can use the second option.

If there is no program, all devices are allowed, if there is some
program it is executed and based on the exit status the access is
denied for 0 and allowed for 1.

Our program will follow these rules:

    - first it will try to look for the specific key using major and
      minor to see if there is any rule for that specific device

    - if there is no specific rule it will try to look for any rule that
      matches only major of the device

    - if there is no match with major it will try the same but with
      minor of the device

    - as the last attempt it will try to look for rule for all devices
      and if there is no match it will return 0 to deny that access

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
po/POTFILES.in
src/libvirt_private.syms
src/util/vircgrouppriv.h
src/util/vircgroupv2devices.c
src/util/vircgroupv2devices.h