OSDN Git Service

bpf: Wrap register invalidation with a helper
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Tue, 21 Feb 2023 20:06:45 +0000 (21:06 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 22 Feb 2023 20:50:34 +0000 (12:50 -0800)
commitdbd8d22863e83ee2834642e4cfd3bdacb8a1c975
tree8f8bcab2c6fed6580e386b346c2d727154327947
parentda03e43a8c500fcfb11ac5eeb03c1b4a9c1dd958
bpf: Wrap register invalidation with a helper

Typically, verifier should use env->allow_ptr_leaks when invaliding
registers for users that don't have CAP_PERFMON or CAP_SYS_ADMIN to
avoid leaking the pointer value. This is similar in spirit to
c67cae551f0d ("bpf: Tighten ptr_to_btf_id checks."). In a lot of the
existing checks, we know the capabilities are present, hence we don't do
the check.

Instead of being inconsistent in the application of the check, wrap the
action of invalidating a register into a helper named 'mark_invalid_reg'
and use it in a uniform fashion to replace open coded invalidation
operations, so that the check is always made regardless of the call site
and we don't have to remember whether it needs to be done or not for
each case.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20230221200646.2500777-7-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c