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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210422014556.3451936-6-andrii@kernel.org>
Date:   Wed, 21 Apr 2021 18:45:55 -0700
From:   Andrii Nakryiko <andrii@...nel.org>
To:     <bpf@...r.kernel.org>, <netdev@...r.kernel.org>, <ast@...com>,
        <daniel@...earbox.net>
CC:     <andrii@...nel.org>, <kernel-team@...com>
Subject: [PATCH bpf-next 5/6] selftests/bpf: extend linked_vars selftests with static variables

Now that BPF static linker supports static variable renames and thus
non-unique static variables in BPF skeleton, add tests validating static
variables are resolved properly during multi-file static linking.

Signed-off-by: Andrii Nakryiko <andrii@...nel.org>
---
 tools/testing/selftests/bpf/prog_tests/linked_vars.c | 12 ++++++++----
 tools/testing/selftests/bpf/progs/linked_vars1.c     |  4 +++-
 tools/testing/selftests/bpf/progs/linked_vars2.c     |  4 +++-
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/linked_vars.c b/tools/testing/selftests/bpf/prog_tests/linked_vars.c
index f3d6ba31ef99..73f3fea41230 100644
--- a/tools/testing/selftests/bpf/prog_tests/linked_vars.c
+++ b/tools/testing/selftests/bpf/prog_tests/linked_vars.c
@@ -14,8 +14,12 @@ void test_linked_vars(void)
 	if (!ASSERT_OK_PTR(skel, "skel_open"))
 		return;
 
+	skel->bss->linked_vars1__input_bss_static = 100;
 	skel->bss->input_bss1 = 1000;
+
+	skel->bss->linked_vars2__input_bss_static = 200;
 	skel->bss->input_bss2 = 2000;
+
 	skel->bss->input_bss_weak = 3000;
 
 	err = linked_vars__load(skel);
@@ -29,11 +33,11 @@ void test_linked_vars(void)
 	/* trigger */
 	syscall(SYS_getpgid);
 
-	ASSERT_EQ(skel->bss->output_bss1, 1000 + 2000 + 3000, "output_bss1");
-	ASSERT_EQ(skel->bss->output_bss2, 1000 + 2000 + 3000, "output_bss2");
+	ASSERT_EQ(skel->bss->output_bss1, 100 + 1000 + 2000 + 3000, "output_bss1");
+	ASSERT_EQ(skel->bss->output_bss2, 200 + 1000 + 2000 + 3000, "output_bss2");
 	/* 10 comes from "winner" input_data_weak in first obj file */
-	ASSERT_EQ(skel->bss->output_data1, 1 + 2 + 10, "output_bss1");
-	ASSERT_EQ(skel->bss->output_data2, 1 + 2 + 10, "output_bss2");
+	ASSERT_EQ(skel->bss->output_data1, 1 + 2 + 10, "output_data1");
+	ASSERT_EQ(skel->bss->output_data2, 1 + 2 + 10, "output_data2");
 	/* 10 comes from "winner" input_rodata_weak in first obj file */
 	ASSERT_EQ(skel->bss->output_rodata1, 11 + 22 + 100, "output_weak1");
 	ASSERT_EQ(skel->bss->output_rodata2, 11 + 22 + 100, "output_weak2");
diff --git a/tools/testing/selftests/bpf/progs/linked_vars1.c b/tools/testing/selftests/bpf/progs/linked_vars1.c
index bc96eff9b8c1..05c7a2739c88 100644
--- a/tools/testing/selftests/bpf/progs/linked_vars1.c
+++ b/tools/testing/selftests/bpf/progs/linked_vars1.c
@@ -10,6 +10,8 @@ extern int LINUX_KERNEL_VERSION __kconfig;
 extern bool CONFIG_BPF_SYSCALL __kconfig __weak;
 extern const void bpf_link_fops __ksym __weak;
 
+static volatile int input_bss_static = 0;
+
 int input_bss1 = 0;
 int input_data1 = 1;
 const volatile int input_rodata1 = 11;
@@ -32,7 +34,7 @@ long output_sink1 = 0;
 static __noinline int get_bss_res(void)
 {
 	/* just make sure all the relocations work against .text as well */
-	return input_bss1 + input_bss2 + input_bss_weak;
+	return input_bss_static + input_bss1 + input_bss2 + input_bss_weak;
 }
 
 SEC("raw_tp/sys_enter")
diff --git a/tools/testing/selftests/bpf/progs/linked_vars2.c b/tools/testing/selftests/bpf/progs/linked_vars2.c
index 946c0ce4f505..c390ac667150 100644
--- a/tools/testing/selftests/bpf/progs/linked_vars2.c
+++ b/tools/testing/selftests/bpf/progs/linked_vars2.c
@@ -10,6 +10,8 @@ extern int LINUX_KERNEL_VERSION __kconfig;
 extern bool CONFIG_BPF_SYSCALL __kconfig;
 extern const void __start_BTF __ksym;
 
+static volatile int input_bss_static = 0;
+
 int input_bss2 = 0;
 int input_data2 = 2;
 const volatile int input_rodata2 = 22;
@@ -38,7 +40,7 @@ static __noinline int get_data_res(void)
 SEC("raw_tp/sys_enter")
 int BPF_PROG(handler2)
 {
-	output_bss2 = input_bss1 + input_bss2 + input_bss_weak;
+	output_bss2 = input_bss_static + input_bss1 + input_bss2 + input_bss_weak;
 	output_data2 = get_data_res();
 	output_rodata2 = input_rodata1 + input_rodata2 + input_rodata_weak;
 
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ