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: <20250207012045.2129841-2-stephen.s.brennan@oracle.com>
Date: Thu,  6 Feb 2025 17:20:43 -0800
From: Stephen Brennan <stephen.s.brennan@...cle.com>
To: Arnd Bergmann <arnd@...db.de>
Cc: Masahiro Yamada <masahiroy@...nel.org>,
        Andrii Nakryiko <andrii@...nel.org>,
        Nicolas Schier <nicolas@...sle.eu>, Kees Cook <kees@...nel.org>,
        KP Singh <kpsingh@...nel.org>,
        Stephen Brennan <stephen.s.brennan@...cle.com>,
        Martin KaFai Lau <martin.lau@...ux.dev>,
        Sami Tolvanen <samitolvanen@...gle.com>,
        Eduard Zingerman <eddyz87@...il.com>, linux-arch@...r.kernel.org,
        Stanislav Fomichev <sdf@...ichev.me>,
        Kent Overstreet <kent.overstreet@...ux.dev>,
        Pasha Tatashin <pasha.tatashin@...een.com>,
        Jiri Olsa <jolsa@...nel.org>,
        John Fastabend <john.fastabend@...il.com>,
        Jann Horn <jannh@...gle.com>, Ard Biesheuvel <ardb@...nel.org>,
        Yonghong Song <yonghong.song@...ux.dev>, Hao Luo <haoluo@...gle.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        linux-kbuild@...r.kernel.org, Daniel Borkmann <daniel@...earbox.net>,
        Nathan Chancellor <nathan@...nel.org>, linux-debuggers@...r.kernel.org,
        Alexei Starovoitov <ast@...nel.org>, Song Liu <song@...nel.org>,
        linux-kernel@...r.kernel.org, bpf@...r.kernel.org
Subject: [PATCH 1/2] kallsyms: output rodata to ".kallsyms_rodata"

When vmlinux is linked, the rodata from kallsyms is placed arbitrarily
within the .rodata section. The linking process is repeated several
times, since the kallsyms data size changes, which shifts symbols,
requiring re-generating the data and re-linking.

BTF is generated during the first link only. For variables, BTF includes
a BTF_K_DATASEC for each data section that may contain a variable, which
includes the variable's name, type, and offset within the data section.
Because the size of kallsyms data changes during later links, the
offsets of variables placed after it in .rodata will change. This means
that BTF_K_DATASEC information for those variables becomes inaccurate.

This is not currently a problem, because BTF currently only generates
variable data for percpu variables. However, the next commit will add
support for generating BTF for all global variables, including for the
.rodata section.

We could re-generate BTF each time vmlinux is linked, but this is quite
expensive, and should be avoided at all costs. Further as each chunk of
data (BTF and kallsyms) are re-generated, there's no guarantee that
their sizes will converge anyway.

Instead, we can take advantage of the fact that BTF only cares to store
the offset of variables from the start of their section. Therefore, so
long as the kallsyms data is stored last in the .rodata section, no
offsets will be affected. Adjust kallsyms to output to .rodata.kallsyms,
and update the linker script to include this at the end of .rodata.

Signed-off-by: Stephen Brennan <stephen.s.brennan@...cle.com>
---
 include/asm-generic/vmlinux.lds.h | 1 +
 scripts/kallsyms.c                | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 54504013c7491..9284f0e502e27 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -463,6 +463,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
 		. = ALIGN(8);						\
 		BOUNDED_SECTION_BY(__tracepoints_ptrs, ___tracepoints_ptrs) \
 		*(__tracepoints_strings)/* Tracepoints: strings */	\
+		*(.kallsyms_rodata)					\
 	}								\
 									\
 	.rodata1          : AT(ADDR(.rodata1) - LOAD_OFFSET) {		\
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 03852da3d2490..743d3dd453599 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -365,7 +365,7 @@ static void write_src(void)
 	printf("#define ALGN .balign 4\n");
 	printf("#endif\n");
 
-	printf("\t.section .rodata, \"a\"\n");
+	printf("\t.section .kallsyms_rodata, \"a\"\n");
 
 	output_label("kallsyms_num_syms");
 	printf("\t.long\t%u\n", table_cnt);
-- 
2.43.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ