]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Ensure type tags precede modifiers in BTF
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Tue, 19 Apr 2022 16:46:07 +0000 (22:16 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 19 Apr 2022 21:02:49 +0000 (14:02 -0700)
commit4547906e3d6e56fe71418ae3955f8c8ba723d4d4
treec37add125d6a94e671c1acc58ab2e91b61c6b08e
parentd447b91b76844de6e891d581121d236a2bb19419
bpf: Ensure type tags precede modifiers in BTF

It is guaranteed that for modifiers, clang always places type tags
before other modifiers, and then the base type. We would like to rely on
this guarantee inside the kernel to make it simple to parse type tags
from BTF.

However, a user would be allowed to construct a BTF without such
guarantees. Hence, add a pass to check that in modifier chains, type
tags only occur at the head of the chain, and then don't occur later in
the chain.

If we see a type tag, we can have one or more type tags preceding other
modifiers that then never have another type tag. If we see other
modifiers, all modifiers following them should never be a type tag.

Instead of having to walk chains we verified previously, we can remember
the last good modifier type ID which headed a good chain. At that point,
we must have verified all other chains headed by type IDs less than it.
This makes the verification process less costly, and it becomes a simple
O(n) pass.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20220419164608.1990559-2-memxor@gmail.com
kernel/bpf/btf.c