Merge branch 'fix-bpf_loop-syzbot-report'

Kumar Kartikeya Dwivedi says:

====================
Fix bpf_loop syzbot report

Needs Eduard's ack. Fix for the report in
https://lore.kernel.org/bpf/6a9ad24c.b5d4176b.238c3e.0001.GAE@google.com.
====================

Link: https://patch.msgid.link/20260905014735.1452988-1-memxor@gmail.com
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
This commit is contained in:
Eduard Zingerman 2026-09-05 20:50:13 -07:00
commit fd5348b434
4 changed files with 20 additions and 1 deletions

View File

@ -894,6 +894,7 @@ enum bpf_arg_type {
ARG_PTR_TO_CTX, /* pointer to context */
ARG_ANYTHING, /* any (initialized) argument is ok */
ARG_SCALAR, /* scalar argument */
ARG_PTR_TO_SPIN_LOCK, /* pointer to bpf_spin_lock */
ARG_PTR_TO_SOCK_COMMON, /* pointer to sock_common */
ARG_PTR_TO_SOCKET, /* pointer to bpf_sock (fullsock) */

View File

@ -754,7 +754,7 @@ const struct bpf_func_proto bpf_loop_proto = {
.func = bpf_loop,
.gpl_only = false,
.ret_type = RET_INTEGER,
.arg1_type = ARG_ANYTHING,
.arg1_type = ARG_SCALAR,
.arg2_type = ARG_PTR_TO_FUNC,
.arg3_type = ARG_PTR_TO_STACK_OR_NULL,
.arg4_type = ARG_ANYTHING,

View File

@ -8211,6 +8211,7 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {
[ARG_MEM_SIZE] = &scalar_types,
[ARG_MEM_SIZE_OR_ZERO] = &scalar_types,
[ARG_CONST_ALLOC_SIZE_OR_ZERO] = &scalar_types,
[ARG_SCALAR] = &scalar_types,
[ARG_CONST_MAP_PTR] = &const_map_ptr_types,
[ARG_PTR_TO_CTX] = &context_types,
[ARG_PTR_TO_SOCK_COMMON] = &sock_types,

View File

@ -168,6 +168,23 @@ static int iter_limit_cb(__u32 idx, struct num_context *ctx)
return 0;
}
SEC("?raw_tp")
__failure __msg("R1 type=ctx expected=scalar")
__naked void bpf_loop_reject_pointer(void)
{
asm volatile (
"r2 = %[iter_limit_cb];"
"r3 = 0;"
"r4 = 0;"
"call %[bpf_loop];"
"exit;"
:
: __imm_ptr(iter_limit_cb),
__imm(bpf_loop)
: __clobber_common
);
}
SEC("?raw_tp")
__success
int bpf_loop_iter_limit_ok(void *unused)