bpf-devices: fix order of removing and adding BPF programs
authorPavel Hrdina <phrdina@redhat.com>
Mon, 12 Nov 2018 09:53:47 +0000 (10:53 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 13 Nov 2018 13:03:01 +0000 (14:03 +0100)
commit2af3eed1aa4a4bcbb1f8eed3736c82dd9d731295
treeb166f396323daf676d1c55c9aba2f0c34101da7c
parent0b82cd2502bd9df61cc7cd283409226035e3b77c
bpf-devices: fix order of removing and adding BPF programs

The current code has multiple issues and it should never be done like
that.  If someone updates list of allowed devices we should attach new
program before we remove the old one for two reasons:

1. It takes some time to attach new program so there is a period of time
when all devices are allowed.

2. BPF programs have limit for number of instructions (4096) and if user
adds a lot of devices we might hit the instruction limit and the new
program will not be accepted which will result in allow all devices
because the old program was already removed.

In order to attach the new program before we remove the old one we need
to use BPF_F_ALLOW_MULTI flag every time.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/core/bpf-devices.c