lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 22 Jul 2021 23:05:40 +0100
From:   Alan Maguire <alan.maguire@...cle.com>
To:     ast@...nel.org, daniel@...earbox.net, andrii@...nel.org
Cc:     kafai@...com, songliubraving@...com, yhs@...com,
        john.fastabend@...il.com, kpsingh@...nel.org, morbo@...gle.com,
        bpf@...r.kernel.org, netdev@...r.kernel.org,
        Alan Maguire <alan.maguire@...cle.com>
Subject: [PATCH bpf-next] selftests/bpf: add multidimensional array BTF-based data dump test

There are currently no multidimensional array tests for
BTF-based data dumping.  In BTF, a multidimensional array is
represented as an array with an element type of array.  However,
pahole and llvm collapse multidimensional arrays into a
one-dimensional array [1].  Accordingly, the test uses the BTF
add interfaces to create a multidimensional char [2][4] array,
and tests type-based display matches expectations.

[1] See Documentation/bpf/btf.rst Section 2.2.3

Suggested-by: Andrii Nakryiko <andrii@...nel.org>
Signed-off-by: Alan Maguire <alan.maguire@...cle.com>
---
 tools/testing/selftests/bpf/prog_tests/btf_dump.c | 39 +++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
index 52ccf0c..70d26cf 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
@@ -681,6 +681,45 @@ static void test_btf_dump_struct_data(struct btf *btf, struct btf_dump *d,
 "}",
 			   { .cb = { 0, 0, 1, 0, 0},});
 
+	/* multidimensional array; because pahole and llvm collapse arrays
+	 * with multiple dimensions into a single dimension, we add a
+	 * multidimensional array explicitly.
+	 */
+	type_id = btf__find_by_name(btf, "char");
+	if (ASSERT_GT(type_id, 0, "find char")) {
+		__s32 index_id, array1_id, array2_id;
+		char strs[2][4] = { "one", "two" };
+
+		index_id = btf__find_by_name(btf, "int");
+		ASSERT_GT(index_id, 0, "find int");
+
+		array2_id = btf__add_array(btf, index_id, type_id, 4);
+		ASSERT_GT(array2_id, 0, "add multidim 2");
+
+		array1_id = btf__add_array(btf, index_id, array2_id, 2);
+		ASSERT_GT(array1_id, 0, "add multidim 1");
+
+		str[0] = '\0';
+		ret = btf_dump__dump_type_data(d, array1_id, &strs, sizeof(strs), &opts);
+		ASSERT_GT(ret, 0, "dump multidimensional array");
+
+		ASSERT_STREQ(str,
+"(char[2][4])[\n"
+"	[\n"
+"		'o',\n"
+"		'n',\n"
+"		'e',\n"
+"	],\n"
+"	[\n"
+"		't',\n"
+"		'w',\n"
+"		'o',\n"
+"	],\n"
+"]",
+			     "multidimensional char array matches");
+	}
+
+
 	/* struct with bitfields */
 	TEST_BTF_DUMP_DATA_C(btf, d, "struct", str, struct bpf_insn, BTF_F_COMPACT,
 		{.code = (__u8)1,.dst_reg = (__u8)0x2,.src_reg = (__u8)0x3,.off = (__s16)4,.imm = (__s32)5,});
-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ