]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftests/bpf: Add a selftest to check for incorrect names
authorJeongjun Park <aha310510@gmail.com>
Sat, 31 Aug 2024 05:47:42 +0000 (14:47 +0900)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 4 Sep 2024 19:34:19 +0000 (12:34 -0700)
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>
tools/testing/selftests/bpf/prog_tests/btf.c

index 00965a6e83bb252f3ee109b6c6b0f4d655a42c87..61de88cf4ad001f190a7cb6c7522caa75d6f0d2a 100644 (file)
@@ -3550,6 +3550,40 @@ static struct btf_raw_test raw_tests[] = {
        },
        BTF_STR_SEC("\0x\0?.foo bar:buz"),
 },
+{
+       .descr = "datasec: name with non-printable first char not 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\7foo"),
+       .err_str = "Invalid name",
+       .btf_load_err = true,
+},
+{
+       .descr = "datasec: name '\\0' is not 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 \0 */                                /* [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"),
+       .err_str = "Invalid name",
+       .btf_load_err = true,
+},
 {
        .descr = "type name '?foo' is not ok",
        .raw_types = {