Remove duplicated BTF parsing logic when it comes to subprog call check. Instead, use (potentially cached) results of btf_prepare_func_args() to abstract away expectations of each subprog argument in generic terms (e.g., "this is pointer to context", or "this is a pointer to memory of size X"), and then use those simple high-level argument type expectations to validate actual register states to check if they match expectations. Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20231215011334.2307144-6-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
34 lines
657 B
C
34 lines
657 B
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/* Copyright (c) 2020 Facebook */
|
|
#include <stddef.h>
|
|
#include <linux/bpf.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
#include "bpf_misc.h"
|
|
|
|
__attribute__ ((noinline))
|
|
int f1(struct __sk_buff *skb)
|
|
{
|
|
return skb->len;
|
|
}
|
|
|
|
int f3(int, struct __sk_buff *skb);
|
|
|
|
__attribute__ ((noinline))
|
|
int f2(int val, struct __sk_buff *skb)
|
|
{
|
|
return f1(skb) + f3(val, (void *)&val); /* type mismatch */
|
|
}
|
|
|
|
__attribute__ ((noinline))
|
|
int f3(int val, struct __sk_buff *skb)
|
|
{
|
|
return skb->ifindex * val;
|
|
}
|
|
|
|
SEC("tc")
|
|
__failure __msg("expects pointer to ctx")
|
|
int global_func5(struct __sk_buff *skb)
|
|
{
|
|
return f1(skb) + f2(2, skb) + f3(3, skb);
|
|
}
|