bpf: add restrict_fs BPF program
authorIago López Galeiras <iagol@microsoft.com>
Fri, 11 Dec 2020 11:40:33 +0000 (12:40 +0100)
committerIago Lopez Galeiras <iagol@microsoft.com>
Wed, 6 Oct 2021 08:52:14 +0000 (10:52 +0200)
commit021d1e96123289182565f0b3ce5a705b0e84fe48
treec662af69f8b6befb0f1f4ae728bbe6729bd978ea
parent659d19243c9229caec5521ef9c6a5a1fd32235d4
bpf: add restrict_fs BPF program

It hooks into the file_open LSM hook and allows only when the filesystem
where the open will take place is present in a BPF map for a particular
cgroup.

The BPF map used is a hash of maps with the following structure:

    cgroupID -> (s_magic -> uint32)

The inner map is effectively a set.

The entry at key 0 in the inner map encodes whether the program behaves
as an allow list or a deny list: if its value is 0 it is a deny list,
otherwise it is an allow list.

When the cgroupID is present in the map, the program checks the inner
map for the magic number of the filesystem associated with the file
that's being opened. When the program behaves as an allow list, if that
magic number is present it allows the open to succeed, when the program
behaves as a deny list, it only allows access if the that magic number
is NOT present. When access is denied the program returns -EPERM.

The BPF program uses CO-RE (Compile-Once Run-Everywhere) to access
internal kernel structures without needing kernel headers present at
runtime.
src/core/bpf/restrict_fs/meson.build [new file with mode: 0644]
src/core/bpf/restrict_fs/restrict-fs.bpf.c [new file with mode: 0644]
src/core/meson.build