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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f4a5d205-ad40-4930-7bbb-25d3f7f940bb@fb.com>
Date:   Thu, 22 Apr 2021 18:01:57 -0700
From:   Yonghong Song <yhs@...com>
To:     Andrii Nakryiko <andrii@...nel.org>, <bpf@...r.kernel.org>,
        <netdev@...r.kernel.org>, <ast@...com>, <daniel@...earbox.net>
CC:     <kernel-team@...com>
Subject: Re: [PATCH v2 bpf-next 16/17] selftests/bpf: add global variables
 linking selftest



On 4/16/21 1:24 PM, Andrii Nakryiko wrote:
> Add selftest validating various aspects of statically linking global
> variables:
>    - correct resolution of extern variables across .bss, .data, and .rodata
>      sections;
>    - correct handling of weak definitions;
>    - correct de-duplication of repeating special externs (.kconfig, .ksyms).
> 
> Signed-off-by: Andrii Nakryiko <andrii@...nel.org>

Ack with a minor nit below.

Acked-by: Yonghong Song <yhs@...com>

> ---
>   tools/testing/selftests/bpf/Makefile          |  3 +-
>   .../selftests/bpf/prog_tests/linked_vars.c    | 43 +++++++++++++++
>   .../selftests/bpf/progs/linked_vars1.c        | 54 ++++++++++++++++++
>   .../selftests/bpf/progs/linked_vars2.c        | 55 +++++++++++++++++++
>   4 files changed, 154 insertions(+), 1 deletion(-)
>   create mode 100644 tools/testing/selftests/bpf/prog_tests/linked_vars.c
>   create mode 100644 tools/testing/selftests/bpf/progs/linked_vars1.c
>   create mode 100644 tools/testing/selftests/bpf/progs/linked_vars2.c
> 
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 427ccfec1a6a..d8f176b55c01 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -308,10 +308,11 @@ endef
>   
>   SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
>   
> -LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h
> +LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h linked_vars.skel.h
>   
>   test_static_linked.skel.h-deps := test_static_linked1.o test_static_linked2.o
>   linked_funcs.skel.h-deps := linked_funcs1.o linked_funcs2.o
> +linked_vars.skel.h-deps := linked_vars1.o linked_vars2.o
>   
>   LINKED_BPF_SRCS := $(patsubst %.o,%.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-deps)))
>   
> diff --git a/tools/testing/selftests/bpf/prog_tests/linked_vars.c b/tools/testing/selftests/bpf/prog_tests/linked_vars.c
> new file mode 100644
> index 000000000000..f3d6ba31ef99
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/linked_vars.c
> @@ -0,0 +1,43 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2021 Facebook */
> +
> +#include <test_progs.h>
> +#include <sys/syscall.h>
> +#include "linked_vars.skel.h"
> +
> +void test_linked_vars(void)
> +{
> +	int err;
> +	struct linked_vars *skel;
> +
> +	skel = linked_vars__open();
> +	if (!ASSERT_OK_PTR(skel, "skel_open"))
> +		return;
> +
> +	skel->bss->input_bss1 = 1000;
> +	skel->bss->input_bss2 = 2000;
> +	skel->bss->input_bss_weak = 3000;
> +
> +	err = linked_vars__load(skel);
> +	if (!ASSERT_OK(err, "skel_load"))
> +		goto cleanup;
> +
> +	err = linked_vars__attach(skel);
> +	if (!ASSERT_OK(err, "skel_attach"))
> +		goto cleanup;
> +
> +	/* 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");
> +	/* 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");
> +	/* 10 comes from "winner" input_rodata_weak in first obj file */

10 => 100 here.

> +	ASSERT_EQ(skel->bss->output_rodata1, 11 + 22 + 100, "output_weak1");
> +	ASSERT_EQ(skel->bss->output_rodata2, 11 + 22 + 100, "output_weak2");
> +
> +cleanup:
> +	linked_vars__destroy(skel);
> +}
> diff --git a/tools/testing/selftests/bpf/progs/linked_vars1.c b/tools/testing/selftests/bpf/progs/linked_vars1.c
> new file mode 100644
> index 000000000000..bc96eff9b8c1
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/linked_vars1.c
> @@ -0,0 +1,54 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2021 Facebook */
> +
> +#include "vmlinux.h"
> +#include <bpf/bpf_helpers.h>
> +#include <bpf/bpf_tracing.h>
> +
> +extern int LINUX_KERNEL_VERSION __kconfig;
> +/* this weak extern will be strict due to the other file's strong extern */
> +extern bool CONFIG_BPF_SYSCALL __kconfig __weak;
> +extern const void bpf_link_fops __ksym __weak;
> +
> +int input_bss1 = 0;
> +int input_data1 = 1;
> +const volatile int input_rodata1 = 11;
> +
> +int input_bss_weak __weak = 0;
> +/* these two definitions should win */
> +int input_data_weak __weak = 10;
> +const volatile int input_rodata_weak __weak = 100;
> +
[...]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ