Skip to content

Commit 5208930

Browse files
eddyz87anakryiko
authored andcommitted
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: Eduard Zingerman <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent bd70a8f commit 5208930

File tree

1 file changed

+29
-0
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+29
-0
lines changed

tools/testing/selftests/bpf/prog_tests/btf.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,6 +3535,32 @@ static struct btf_raw_test raw_tests[] = {
35353535
.value_type_id = 1,
35363536
.max_entries = 1,
35373537
},
3538+
{
3539+
.descr = "datasec: name '?.foo bar:buz' is ok",
3540+
.raw_types = {
3541+
/* int */
3542+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3543+
/* VAR x */ /* [2] */
3544+
BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
3545+
BTF_VAR_STATIC,
3546+
/* DATASEC ?.data */ /* [3] */
3547+
BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
3548+
BTF_VAR_SECINFO_ENC(2, 0, 4),
3549+
BTF_END_RAW,
3550+
},
3551+
BTF_STR_SEC("\0x\0?.foo bar:buz"),
3552+
},
3553+
{
3554+
.descr = "type name '?foo' is not ok",
3555+
.raw_types = {
3556+
/* union ?foo; */
3557+
BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_FWD, 1, 0), 0), /* [1] */
3558+
BTF_END_RAW,
3559+
},
3560+
BTF_STR_SEC("\0?foo"),
3561+
.err_str = "Invalid name",
3562+
.btf_load_err = true,
3563+
},
35383564

35393565
{
35403566
.descr = "float test #1, well-formed",
@@ -4363,6 +4389,9 @@ static void do_test_raw(unsigned int test_num)
43634389
if (err || btf_fd < 0)
43644390
goto done;
43654391

4392+
if (!test->map_type)
4393+
goto done;
4394+
43664395
opts.btf_fd = btf_fd;
43674396
opts.btf_key_type_id = test->key_type_id;
43684397
opts.btf_value_type_id = test->value_type_id;

0 commit comments

Comments
 (0)