OSDN Git Service

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)
commiteb596b0905584a9389585b0f437cf8a2faeb14d0
treec37add125d6a94e671c1acc58ab2e91b61c6b08e
parent0d7fefebea552771b17682a12330ea47e369a5df
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