Skip to content

Commit

Permalink
Merge branch 'typedef-func_proto'
Browse files Browse the repository at this point in the history
Yonghong Song says:

====================
The current btf implementation disallows the typedef of
a func_proto type. This actually is allowed per C standard.
This patch fixed btf verification to permit such types.
Patch #1 fixed the kernel side and Patch #2 fixed
the tools test_btf test.
====================

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Alexei Starovoitov committed Jan 30, 2019
2 parents 2fa53f8 + 32b750b commit 9d90436
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
3 changes: 2 additions & 1 deletion kernel/bpf/btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,8 @@ static int btf_modifier_resolve(struct btf_verifier_env *env,

/* "typedef void new_void", "const void"...etc */
if (!btf_type_is_void(next_type) &&
!btf_type_is_fwd(next_type)) {
!btf_type_is_fwd(next_type) &&
!btf_type_is_func_proto(next_type)) {
btf_verifier_log_type(env, v->t, "Invalid type_id");
return -EINVAL;
}
Expand Down
9 changes: 3 additions & 6 deletions tools/testing/selftests/bpf/test_btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1881,13 +1881,12 @@ static struct btf_raw_test raw_tests[] = {
},

{
.descr = "func proto (CONST=>TYPEDEF=>FUNC_PROTO)",
.descr = "func proto (TYPEDEF=>FUNC_PROTO)",
.raw_types = {
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
BTF_CONST_ENC(4), /* [3] */
BTF_TYPEDEF_ENC(NAME_TBD, 5), /* [4] */
BTF_FUNC_PROTO_ENC(0, 2), /* [5] */
BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
BTF_FUNC_PROTO_ENC(0, 2), /* [4] */
BTF_FUNC_PROTO_ARG_ENC(0, 1),
BTF_FUNC_PROTO_ARG_ENC(0, 2),
BTF_END_RAW,
Expand All @@ -1901,8 +1900,6 @@ static struct btf_raw_test raw_tests[] = {
.key_type_id = 1,
.value_type_id = 1,
.max_entries = 4,
.btf_load_err = true,
.err_str = "Invalid type_id",
},

{
Expand Down

0 comments on commit 9d90436

Please sign in to comment.