bpf: teach verifier actual bounds of bpf_get_smp_processor_id() result
authorAndrii Nakryiko <andrii@kernel.org>
Tue, 11 Jul 2023 23:23:59 +0000 (16:23 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 12 Jul 2023 14:57:18 +0000 (07:57 -0700)
commitf42bcd168d034aa8abd9178c430b407be8c98827
treead13ac40b7bcfa72d2dd10434f3937bb472489dd
parent87e098e62347ebb55ed775126580cfbdc42a3669
bpf: teach verifier actual bounds of bpf_get_smp_processor_id() result

bpf_get_smp_processor_id() helper returns current CPU on which BPF
program runs. It can't return value that is bigger than maximum allowed
number of CPUs (minus one, due to zero indexing). Teach BPF verifier to
recognize that. This makes it possible to use bpf_get_smp_processor_id()
result to index into arrays without extra checks, as demonstrated in
subsequent selftests/bpf patch.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20230711232400.1658562-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c