| From: |
| Florent Revest <revest-AT-chromium.org> |
| To: |
| bpf-AT-vger.kernel.org |
| Subject: |
| [PATCH bpf-next 0/5] Add a snprintf eBPF helper |
| Date: |
| Wed, 10 Mar 2021 23:02:06 +0100 |
| Message-ID: |
| <20210310220211.1454516-1-revest@chromium.org> |
| Cc: |
| ast-AT-kernel.org, daniel-AT-iogearbox.net, andrii-AT-kernel.org, yhs-AT-fb.com, kpsingh-AT-kernel.org, jackmanb-AT-chromium.org, linux-kernel-AT-vger.kernel.org, Florent Revest <revest-AT-chromium.org> |
| Archive-link: |
| Article |
We have a usecase where we want to audit symbol names (if available) in
callback registration hooks. (ex: fentry/nf_register_net_hook)
A few months back, I proposed a bpf_kallsyms_lookup series but it was
decided in the reviews that a more generic helper, bpf_snprintf, would
be more useful.
This series implements the helper according to the feedback received in
https://lore.kernel.org/bpf/20201126165748.1748417-1-reve...
- A new arg type guarantees the NULL-termination of string arguments and
lets us pass format strings in only one arg
- A new helper is implemented using that guarantee. Because the format
string is known at verification time, the format string validation is
done by the verifier
- To implement a series of tests for bpf_snprintf, the logic for
marshalling variadic args in a fixed-size array is reworked as per:
https://lore.kernel.org/bpf/20210310015455.1095207-1-reve...
Florent Revest (5):
bpf: Add a ARG_PTR_TO_CONST_STR argument type
bpf: Add a bpf_snprintf helper
libbpf: Initialize the bpf_seq_printf parameters array field by field
libbpf: Introduce a BPF_SNPRINTF helper macro
selftests/bpf: Add a series of tests for bpf_snprintf
include/linux/bpf.h | 5 +
include/uapi/linux/bpf.h | 28 +++
kernel/bpf/verifier.c | 178 ++++++++++++++++++
kernel/trace/bpf_trace.c | 110 +++++++++++
tools/include/uapi/linux/bpf.h | 28 +++
tools/lib/bpf/bpf_tracing.h | 45 ++++-
.../selftests/bpf/prog_tests/snprintf.c | 71 +++++++
.../selftests/bpf/progs/test_snprintf.c | 71 +++++++
8 files changed, 535 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/snprintf.c
create mode 100644 tools/testing/selftests/bpf/progs/test_snprintf.c
--
2.30.1.766.gb4fecdf3b7-goog