diff options
author | Matteo Croce <teknoraver@meta.com> | 2024-07-01 21:58:30 +0200 |
---|---|---|
committer | Matteo Croce <teknoraver@meta.com> | 2024-09-11 23:07:00 +0200 |
commit | 6d9ef22acdeac4b429efb75164341233955484af (patch) | |
tree | 16e3452e31120d66a6da0f871cb6135e7198e1f4 /src/network/networkd-manager.h | |
parent | store the sysctls set by networkd (diff) | |
download | systemd-6d9ef22acdeac4b429efb75164341233955484af.tar.xz systemd-6d9ef22acdeac4b429efb75164341233955484af.zip |
emit a warning in networkd if managed sysctls are changed
Monitor the sysctl set by networkd for writes, if a sysctl is
overwritten with a different value than the one we set, emit a warning.
Writes are detected with an eBPF program attached as BPF_CGROUP_SYSCTL
which reports the sysctl writes only in net/.
The eBPF program only reports sysctl writes from a different cgroup than networkd.
To do this, it uses the `bpf_current_task_under_cgroup_proto()` helper,
which will be available allowed in BPF_CGROUP_SYSCTL from kernel 6.12[1].
Loading a BPF_CGROUP_SYSCTL program requires the CAP_SYS_ADMIN capability,
so drop it just after the program load, whether it loads successfully or not.
Writes are logged but permitted, in future the functionality can be
extended to also deny writes to managed sysctls.
[1] https://lore.kernel.org/bpf/20240819162805.78235-3-technoboy85@gmail.com/
Diffstat (limited to 'src/network/networkd-manager.h')
-rw-r--r-- | src/network/networkd-manager.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index 076cf5e3d6..5a0decced2 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -123,6 +123,11 @@ struct Manager { /* sysctl */ int ip_forwarding[2]; Hashmap *sysctl_shadow; + sd_event_source *sysctl_event_source; + struct ring_buffer *sysctl_buffer; + struct sysctl_monitor_bpf *sysctl_skel; + struct bpf_link *sysctl_link; + int cgroup_fd; }; int manager_new(Manager **ret, bool test_mode); |