public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts/kallsyms: fix wrong kallsyms_relative_base with CONFIG_KALLSYMS_BASE_RELATIVE
@ 2020-03-10 20:34 Mikhail Petrov
  2020-03-11  6:06 ` Masahiro Yamada
  0 siblings, 1 reply; 8+ messages in thread
From: Mikhail Petrov @ 2020-03-10 20:34 UTC (permalink / raw)
  To: Masahiro Yamada, linux-kbuild

There is the code in the read_symbol function in 'scripts/kallsyms.c':

	if (is_ignored_symbol(name, type))
		return NULL;

	/* Ignore most absolute/undefined (?) symbols. */
	if (strcmp(name, "_text") == 0)
		_text = addr;

But the is_ignored_symbol function returns true for name="_text" and type='a'. So the next condition is not executed and the _text variable is always zero.

It makes the wrong kallsyms_relative_base symbol as a result of the code:

	if (base_relative) {
		output_label("kallsyms_relative_base");
		output_address(relative_base);
		printf("\n");
	}

Because the output_address function uses the _text variable.

So the kallsyms_lookup function and all related functions in the kernel do not work properly. For example, the stack trace in oops:

	Call Trace:
	[aa095e58] [809feab8] kobj_ns_ops_tbl+0x7ff09ac8/0x7ff1c1c4 (unreliable)
	[aa095e98] [80002b64] kobj_ns_ops_tbl+0x7f50db74/0x80000010
	[aa095ef8] [809c3d24] kobj_ns_ops_tbl+0x7feced34/0x7ff1c1c4
	[aa095f28] [80002ed0] kobj_ns_ops_tbl+0x7f50dee0/0x80000010
	[aa095f38] [8000f238] kobj_ns_ops_tbl+0x7f51a248/0x80000010

The right stack trace:

	Call Trace:
	[aa095e58] [809feab8] module_vdu_video_init+0x2fc/0x3bc (unreliable)
	[aa095e98] [80002b64] do_one_initcall+0x40/0x1f0
	[aa095ef8] [809c3d24] kernel_init_freeable+0x164/0x1d8
	[aa095f28] [80002ed0] kernel_init+0x14/0x124
	[aa095f38] [8000f238] ret_from_kernel_thread+0x14/0x1c

Signed-off-by: Mikhail Petrov <Mikhail.Petrov@mir.dev>

---

diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 0133dfaaf352..3e8dea6e0a95 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -195,13 +195,13 @@ static struct sym_entry *read_symbol(FILE *in)
 		return NULL;
 	}
 
-	if (is_ignored_symbol(name, type))
-		return NULL;
-
-	/* Ignore most absolute/undefined (?) symbols. */
 	if (strcmp(name, "_text") == 0)
 		_text = addr;
 
+	/* Ignore most absolute/undefined (?) symbols. */
+	if (is_ignored_symbol(name, type))
+		return NULL;
+
 	check_symbol_range(name, addr, text_ranges, ARRAY_SIZE(text_ranges));
 	check_symbol_range(name, addr, &percpu_range, 1);
 

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-03-19  8:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-10 20:34 [PATCH] scripts/kallsyms: fix wrong kallsyms_relative_base with CONFIG_KALLSYMS_BASE_RELATIVE Mikhail Petrov
2020-03-11  6:06 ` Masahiro Yamada
2020-03-11 18:18   ` Mikhail Petrov
2020-03-11 20:56     ` Masahiro Yamada
2020-03-12  5:12       ` Michael Ellerman
2020-03-12 19:51         ` Mikhail Petrov
2020-03-12 19:36       ` Mikhail Petrov
2020-03-19  8:02         ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox