bpf: add socket-bind BPF program code sources
authorJulia Kartseva <hex@fb.com>
Sat, 14 Nov 2020 01:40:17 +0000 (17:40 -0800)
committerJulia Kartseva <hex@fb.com>
Mon, 26 Apr 2021 23:07:41 +0000 (16:07 -0700)
commit58a33faf8081e3b6126b49817a0b5cee54e8770b
treef0c9d6e8e5977c161b98c8bf6a1ca8f0d020b32f
parentea1036e253ed3712f43ddd7a22e7957cd2c48ee2
bpf: add socket-bind BPF program code sources

Introduce BPF program compiled from BPF source code in
restricted C - socket-bind.
It addresses feature request [0].

The goal is to allow systemd services to bind(2) only to a predefined set
of ports. This prevents assigning socket address with unallowed port
to a socket and creating servers listening on that port.

This compliments firewalling feature presenting in systemd:
whereas cgroup/{egress|ingress} hooks act on packets, this doesn't
protect from untrusted service or payload hijacking an important port.

While ports in 0-1023 range are restricted to root only, 1024-65535
range is not protected by any mean.

Performance is another aspect of socket_bind feature since per-packet
cost can be eliminated for some port-based filtering policies.

The feature is implemented with cgroup/bind{4|6} hooks [1].
In contrast to the present systemd approach using raw bpf instructions,
this program is compiled from sources. Stretch goal is to
make bpf ecosystem in systemd more friendly for developer and to clear
path for more BPF programs.

[0] https://github.com/systemd/systemd/pull/13496#issuecomment-570573085
[1] https://www.spinics.net/lists/netdev/msg489054.html
src/core/bpf/socket_bind/socket-bind-api.bpf.h [new file with mode: 0644]
src/core/bpf/socket_bind/socket-bind.bpf.c [new file with mode: 0644]