mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-12-17 16:07:08 +01:00
bpf: Introduce KF_ARG_PTR_TO_CONST_STR
Similar to ARG_PTR_TO_CONST_STR for BPF helpers, KF_ARG_PTR_TO_CONST_STR specifies kfunc args that point to const strings. Annotation "__str" is used to specify kfunc arg of type KF_ARG_PTR_TO_CONST_STR. Also, add documentation for the "__str" annotation. bpf_get_file_xattr() will be the first kfunc that uses this type. Signed-off-by: Song Liu <song@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Vadim Fedorenko <vadim.fedorenko@linux.dev> Link: https://lore.kernel.org/bpf/20231107045725.2278852-4-song@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
0b51940729
commit
045edee19d
|
|
@ -135,6 +135,30 @@ Either way, the returned buffer is either NULL, or of size buffer_szk. Without t
|
||||||
annotation, the verifier will reject the program if a null pointer is passed in with
|
annotation, the verifier will reject the program if a null pointer is passed in with
|
||||||
a nonzero size.
|
a nonzero size.
|
||||||
|
|
||||||
|
2.2.5 __str Annotation
|
||||||
|
----------------------------
|
||||||
|
This annotation is used to indicate that the argument is a constant string.
|
||||||
|
|
||||||
|
An example is given below::
|
||||||
|
|
||||||
|
__bpf_kfunc bpf_get_file_xattr(..., const char *name__str, ...)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
In this case, ``bpf_get_file_xattr()`` can be called as::
|
||||||
|
|
||||||
|
bpf_get_file_xattr(..., "xattr_name", ...);
|
||||||
|
|
||||||
|
Or::
|
||||||
|
|
||||||
|
const char name[] = "xattr_name"; /* This need to be global */
|
||||||
|
int BPF_PROG(...)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
bpf_get_file_xattr(..., name, ...);
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
.. _BPF_kfunc_nodef:
|
.. _BPF_kfunc_nodef:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10810,6 +10810,11 @@ static bool is_kfunc_arg_nullable(const struct btf *btf, const struct btf_param
|
||||||
return __kfunc_param_match_suffix(btf, arg, "__nullable");
|
return __kfunc_param_match_suffix(btf, arg, "__nullable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_kfunc_arg_const_str(const struct btf *btf, const struct btf_param *arg)
|
||||||
|
{
|
||||||
|
return __kfunc_param_match_suffix(btf, arg, "__str");
|
||||||
|
}
|
||||||
|
|
||||||
static bool is_kfunc_arg_scalar_with_name(const struct btf *btf,
|
static bool is_kfunc_arg_scalar_with_name(const struct btf *btf,
|
||||||
const struct btf_param *arg,
|
const struct btf_param *arg,
|
||||||
const char *name)
|
const char *name)
|
||||||
|
|
@ -10953,6 +10958,7 @@ enum kfunc_ptr_arg_type {
|
||||||
KF_ARG_PTR_TO_RB_ROOT,
|
KF_ARG_PTR_TO_RB_ROOT,
|
||||||
KF_ARG_PTR_TO_RB_NODE,
|
KF_ARG_PTR_TO_RB_NODE,
|
||||||
KF_ARG_PTR_TO_NULL,
|
KF_ARG_PTR_TO_NULL,
|
||||||
|
KF_ARG_PTR_TO_CONST_STR,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum special_kfunc_type {
|
enum special_kfunc_type {
|
||||||
|
|
@ -11103,6 +11109,9 @@ get_kfunc_ptr_arg_type(struct bpf_verifier_env *env,
|
||||||
if (is_kfunc_arg_rbtree_node(meta->btf, &args[argno]))
|
if (is_kfunc_arg_rbtree_node(meta->btf, &args[argno]))
|
||||||
return KF_ARG_PTR_TO_RB_NODE;
|
return KF_ARG_PTR_TO_RB_NODE;
|
||||||
|
|
||||||
|
if (is_kfunc_arg_const_str(meta->btf, &args[argno]))
|
||||||
|
return KF_ARG_PTR_TO_CONST_STR;
|
||||||
|
|
||||||
if ((base_type(reg->type) == PTR_TO_BTF_ID || reg2btf_ids[base_type(reg->type)])) {
|
if ((base_type(reg->type) == PTR_TO_BTF_ID || reg2btf_ids[base_type(reg->type)])) {
|
||||||
if (!btf_type_is_struct(ref_t)) {
|
if (!btf_type_is_struct(ref_t)) {
|
||||||
verbose(env, "kernel function %s args#%d pointer type %s %s is not supported\n",
|
verbose(env, "kernel function %s args#%d pointer type %s %s is not supported\n",
|
||||||
|
|
@ -11734,6 +11743,7 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
|
||||||
case KF_ARG_PTR_TO_MEM_SIZE:
|
case KF_ARG_PTR_TO_MEM_SIZE:
|
||||||
case KF_ARG_PTR_TO_CALLBACK:
|
case KF_ARG_PTR_TO_CALLBACK:
|
||||||
case KF_ARG_PTR_TO_REFCOUNTED_KPTR:
|
case KF_ARG_PTR_TO_REFCOUNTED_KPTR:
|
||||||
|
case KF_ARG_PTR_TO_CONST_STR:
|
||||||
/* Trusted by default */
|
/* Trusted by default */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -12005,6 +12015,15 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
|
||||||
meta->arg_btf = reg->btf;
|
meta->arg_btf = reg->btf;
|
||||||
meta->arg_btf_id = reg->btf_id;
|
meta->arg_btf_id = reg->btf_id;
|
||||||
break;
|
break;
|
||||||
|
case KF_ARG_PTR_TO_CONST_STR:
|
||||||
|
if (reg->type != PTR_TO_MAP_VALUE) {
|
||||||
|
verbose(env, "arg#%d doesn't point to a const string\n", i);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
ret = check_reg_const_str(env, reg, regno);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user