]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Sysctl hook
authorAndrey Ignatov <rdna@fb.com>
Wed, 27 Feb 2019 20:59:24 +0000 (12:59 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 12 Apr 2019 20:54:58 +0000 (13:54 -0700)
commit376f5918bd7aaa8a51559794472956cfb8fa6d85
tree11dbbeb42b32557d345e6dac2baf2881cbe5adb5
parent7d1b85e242a120f86994bb984e5509908af132f9
bpf: Sysctl hook

Containerized applications may run as root and it may create problems
for whole host. Specifically such applications may change a sysctl and
affect applications in other containers.

Furthermore in existing infrastructure it may not be possible to just
completely disable writing to sysctl, instead such a process should be
gradual with ability to log what sysctl are being changed by a
container, investigate, limit the set of writable sysctl to currently
used ones (so that new ones can not be changed) and eventually reduce
this set to zero.

The patch introduces new program type BPF_PROG_TYPE_CGROUP_SYSCTL and
attach type BPF_CGROUP_SYSCTL to solve these problems on cgroup basis.

New program type has access to following minimal context:
struct bpf_sysctl {
__u32 write;
};

Where @write indicates whether sysctl is being read (= 0) or written (=
1).

Helpers to access sysctl name and value will be introduced separately.

BPF_CGROUP_SYSCTL attach point is added to sysctl code right before
passing control to ctl_table->proc_handler so that BPF program can
either allow or deny access to sysctl.

Suggested-by: Roman Gushchin <guro@fb.com>
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
fs/proc/proc_sysctl.c
include/linux/bpf-cgroup.h
include/linux/bpf_types.h
include/linux/filter.h
include/uapi/linux/bpf.h
kernel/bpf/cgroup.c
kernel/bpf/syscall.c
kernel/bpf/verifier.c