Thread (31 messages) read the whole thread 31 messages, 7 authors, 2020-01-15

Re: [PATCH bpf-next 3/6] bpf: Introduce function-by-function verification

From: Andrii Nakryiko <hidden>
Date: 2020-01-14 23:56:37
Also in: bpf

On Tue, Jan 14, 2020 at 3:39 PM Stanislav Fomichev [off-list ref] wrote:
On 01/07, Alexei Starovoitov wrote:
quoted
New llvm and old llvm with libbpf help produce BTF that distinguish global and
static functions. Unlike arguments of static function the arguments of global
functions cannot be removed or optimized away by llvm. The compiler has to use
exactly the arguments specified in a function prototype. The argument type
information allows the verifier validate each global function independently.
For now only supported argument types are pointer to context and scalars. In
the future pointers to structures, sizes, pointer to packet data can be
supported as well. Consider the following example:
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -2621,8 +2621,8 @@ static s32 btf_func_check_meta(struct btf_verifier_env *env,
              return -EINVAL;
      }

-     if (btf_type_vlen(t)) {
-             btf_verifier_log_type(env, t, "vlen != 0");
+     if (btf_type_vlen(t) > BTF_FUNC_EXTERN) {
+             btf_verifier_log_type(env, t, "invalid func linkage");
              return -EINVAL;
Sorry for bringing it up after the review:

This effectively teaches kernel about BTF_KIND_FUNC scope argument,
right? Which means, if I take clang from the tip
(https://github.com/llvm/llvm-project/commit/fbb64aa69835c8e3e9efe0afc8a73058b5a0fb3c#diff-f191c05d1eb0a6ca0e89d7e7938d73d4)
and take 5.4 kernel, it will reject BTF because it now has a
BTF_KIND_FUNC with global scope (any 'main' function is global and has
non-zero vlen).

What's the general guidance on the situation where clang starts
spitting out some BTF and released kernels reject it? Is there some list of
flags I can pass to clang to not emit some of the BTF features?
Or am I missing something?
Isn't that the issue that 2d3eb67f64ec ("libbpf: Sanitize global
functions") addresses by sanitizing those BTF_KIND_FUNC as static
functions (with vlen=0)?

The general guidance is to have libbpf sanitize such BTF to make it
compatible with old kernels.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help