Skip to content

Commit 7430708

Browse files
name2965Alexei Starovoitov
authored andcommitted
selftests/bpf: Add a selftest to check for incorrect names
Add selftest for cases where btf_name_valid_section() does not properly check for certain types of names. Suggested-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Jeongjun Park <aha310510@gmail.com> Link: https://lore.kernel.org/r/20240831054742.364585-1-aha310510@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Eduard Zingerman <eddyz87@gmail.com>
1 parent bb6705c commit 7430708

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

  • tools/testing/selftests/bpf/prog_tests

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,6 +3550,40 @@ static struct btf_raw_test raw_tests[] = {
35503550
},
35513551
BTF_STR_SEC("\0x\0?.foo bar:buz"),
35523552
},
3553+
{
3554+
.descr = "datasec: name with non-printable first char not is ok",
3555+
.raw_types = {
3556+
/* int */
3557+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3558+
/* VAR x */ /* [2] */
3559+
BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
3560+
BTF_VAR_STATIC,
3561+
/* DATASEC ?.data */ /* [3] */
3562+
BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
3563+
BTF_VAR_SECINFO_ENC(2, 0, 4),
3564+
BTF_END_RAW,
3565+
},
3566+
BTF_STR_SEC("\0x\0\7foo"),
3567+
.err_str = "Invalid name",
3568+
.btf_load_err = true,
3569+
},
3570+
{
3571+
.descr = "datasec: name '\\0' is not ok",
3572+
.raw_types = {
3573+
/* int */
3574+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3575+
/* VAR x */ /* [2] */
3576+
BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
3577+
BTF_VAR_STATIC,
3578+
/* DATASEC \0 */ /* [3] */
3579+
BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
3580+
BTF_VAR_SECINFO_ENC(2, 0, 4),
3581+
BTF_END_RAW,
3582+
},
3583+
BTF_STR_SEC("\0x\0"),
3584+
.err_str = "Invalid name",
3585+
.btf_load_err = true,
3586+
},
35533587
{
35543588
.descr = "type name '?foo' is not ok",
35553589
.raw_types = {

0 commit comments

Comments
 (0)