bpf: Allow helpers access trusted PTR_TO_BTF_ID.
authorAlexei Starovoitov <ast@kernel.org>
Mon, 13 Mar 2023 23:58:44 +0000 (16:58 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Tue, 14 Mar 2023 06:08:21 +0000 (23:08 -0700)
commit3e30be4288b31702d4898487a74e80ba14150a9f
tree252cdcdb69d17ef0043c7f59882393bdf689817a
parentc9267aa8b794c2188d49c7d7bd2990e98b2d6b84
bpf: Allow helpers access trusted PTR_TO_BTF_ID.

The verifier rejects the code:
  bpf_strncmp(task->comm, 16, "my_task");
with the message:
  16: (85) call bpf_strncmp#182
  R1 type=trusted_ptr_ expected=fp, pkt, pkt_meta, map_key, map_value, mem, ringbuf_mem, buf

Teach the verifier that such access pattern is safe.
Do not allow untrusted and legacy ptr_to_btf_id to be passed into helpers.

Reported-by: David Vernet <void@manifault.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: David Vernet <void@manifault.com>
Link: https://lore.kernel.org/r/20230313235845.61029-3-alexei.starovoitov@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
kernel/bpf/verifier.c