]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Fix verifier support for validation of async callbacks
authorKris Van Hees <kris.van.hees@oracle.com>
Wed, 5 Jan 2022 21:01:50 +0000 (16:01 -0500)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 5 Jan 2022 21:38:22 +0000 (13:38 -0800)
commit3ca66ca6ea22255bcaf8630f577b54e7e07d31e2
treef181ef8d0f48c0d045e245e445ba404113ee6cb3
parentae8e17b2f5d19ff8f6eaa461734e4b56d7631428
bpf: Fix verifier support for validation of async callbacks

Commit adc71a713ac8 ("bpf: Implement verifier support for validation of async callbacks.")
added support for BPF_FUNC_timer_set_callback to
the __check_func_call() function.  The test in __check_func_call() is
flaweed because it can mis-interpret a regular BPF-to-BPF pseudo-call
as a BPF_FUNC_timer_set_callback callback call.

Consider the conditional in the code:

if (insn->code == (BPF_JMP | BPF_CALL) &&
    insn->imm == BPF_FUNC_timer_set_callback) {

The BPF_FUNC_timer_set_callback has value 170.  This means that if you
have a BPF program that contains a pseudo-call with an instruction delta
of 170, this conditional will be found to be true by the verifier, and
it will interpret the pseudo-call as a callback.  This leads to a mess
with the verification of the program because it makes the wrong
assumptions about the nature of this call.

Solution: include an explicit check to ensure that insn->src_reg == 0.
This ensures that calls cannot be mis-interpreted as an async callback
call.

Fixes: adc71a713ac8 ("bpf: Implement verifier support for validation of async callbacks.")
Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220105210150.GH1559@oracle.com
kernel/bpf/verifier.c