]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Introduce bpf_sysctl_get_current_value helper
authorAndrey Ignatov <rdna@fb.com>
Fri, 1 Mar 2019 03:22:15 +0000 (19:22 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 12 Apr 2019 20:54:58 +0000 (13:54 -0700)
commit777140275c081204c1c60505ccf7a619669c346f
tree94057ffc15c6225b4106d9f5aafecb7b547a9172
parent14aa5228198c5e8999d243c0bfb64e108c5861bf
bpf: Introduce bpf_sysctl_get_current_value helper

Add bpf_sysctl_get_current_value() helper to copy current sysctl value
into provided by BPF_PROG_TYPE_CGROUP_SYSCTL program buffer.

It provides same string as user space can see by reading corresponding
file in /proc/sys/, including new line, etc.

Documentation for the new helper is provided in bpf.h UAPI.

Since current value is kept in ctl_table->data in a parsed form,
ctl_table->proc_handler() with write=0 is called to read that data and
convert it to a string. Such a string can later be parsed by a program
using helpers that will be introduced separately.

Unfortunately it's not trivial to provide API to access parsed data due to
variety of data representations (string, intvec, uintvec, ulongvec,
custom structures, even NULL, etc). Instead it's assumed that user know
how to handle specific sysctl they're interested in and appropriate
helpers can be used.

Since ctl_table->proc_handler() expects __user buffer, conversion to
__user happens for kernel allocated one where the value is stored.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/filter.h
include/uapi/linux/bpf.h
kernel/bpf/cgroup.c