Commit 5208930a authored by Eduard Zingerman's avatar Eduard Zingerman Committed by Andrii Nakryiko

selftests/bpf: Test cases for '?' in BTF names

Two test cases to verify that '?' and other printable characters are
allowed in BTF DATASEC names:
- DATASEC with name "?.foo bar:buz" should be accepted;
- type with name "?foo" should be rejected.
Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240306104529.6453-16-eddyz87@gmail.com
parent bd70a8fb
...@@ -3535,6 +3535,32 @@ static struct btf_raw_test raw_tests[] = { ...@@ -3535,6 +3535,32 @@ static struct btf_raw_test raw_tests[] = {
.value_type_id = 1, .value_type_id = 1,
.max_entries = 1, .max_entries = 1,
}, },
{
.descr = "datasec: name '?.foo bar:buz' is ok",
.raw_types = {
/* int */
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
/* VAR x */ /* [2] */
BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
BTF_VAR_STATIC,
/* DATASEC ?.data */ /* [3] */
BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
BTF_VAR_SECINFO_ENC(2, 0, 4),
BTF_END_RAW,
},
BTF_STR_SEC("\0x\0?.foo bar:buz"),
},
{
.descr = "type name '?foo' is not ok",
.raw_types = {
/* union ?foo; */
BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_FWD, 1, 0), 0), /* [1] */
BTF_END_RAW,
},
BTF_STR_SEC("\0?foo"),
.err_str = "Invalid name",
.btf_load_err = true,
},
{ {
.descr = "float test #1, well-formed", .descr = "float test #1, well-formed",
...@@ -4363,6 +4389,9 @@ static void do_test_raw(unsigned int test_num) ...@@ -4363,6 +4389,9 @@ static void do_test_raw(unsigned int test_num)
if (err || btf_fd < 0) if (err || btf_fd < 0)
goto done; goto done;
if (!test->map_type)
goto done;
opts.btf_fd = btf_fd; opts.btf_fd = btf_fd;
opts.btf_key_type_id = test->key_type_id; opts.btf_key_type_id = test->key_type_id;
opts.btf_value_type_id = test->value_type_id; opts.btf_value_type_id = test->value_type_id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment