* [PATCH] scripts/kallsyms: fix offset overflow of kallsyms_relative_base
@ 2019-12-09 3:51 Masahiro Yamada
2019-12-17 3:08 ` Masahiro Yamada
0 siblings, 1 reply; 2+ messages in thread
From: Masahiro Yamada @ 2019-12-09 3:51 UTC (permalink / raw)
To: linux-kbuild
Cc: Olof Johansson, Masahiro Yamada, Masahiro Yamada, linux-kernel
Since commit 5e5c4fa78745 ("scripts/kallsyms: shrink table before
sorting it"), kallsyms_relative_base can be larger than _text, which
causes overflow when building the 32-bit kernel.
https://lkml.org/lkml/2019/12/7/156
This is because _text is, unless --all-symbols is specified, now
trimmed from the symbol table before record_relative_base() is called.
Handle the offset signedness also for kallsyms_relative_base. Introduce
a new helper, output_address(), to reduce the code duplication.
Fixes: 5e5c4fa78745 ("scripts/kallsyms: shrink table before sorting it")
Reported-by: Olof Johansson <olof@lixom.net>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/kallsyms.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index fb55f262f42d..94153732ec00 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -310,6 +310,15 @@ static void output_label(const char *label)
printf("%s:\n", label);
}
+/* Provide proper symbols relocatability by their '_text' relativeness. */
+static void output_address(unsigned long long addr)
+{
+ if (_text <= addr)
+ printf("\tPTR\t_text + %#llx\n", addr - _text);
+ else
+ printf("\tPTR\t_text - %#llx\n", _text - addr);
+}
+
/* uncompress a compressed symbol. When this function is called, the best table
* might still be compressed itself, so the function needs to be recursive */
static int expand_symbol(const unsigned char *data, int len, char *result)
@@ -360,19 +369,6 @@ static void write_src(void)
printf("\t.section .rodata, \"a\"\n");
- /* Provide proper symbols relocatability by their relativeness
- * to a fixed anchor point in the runtime image, either '_text'
- * for absolute address tables, in which case the linker will
- * emit the final addresses at build time. Otherwise, use the
- * offset relative to the lowest value encountered of all relative
- * symbols, and emit non-relocatable fixed offsets that will be fixed
- * up at runtime.
- *
- * The symbol names cannot be used to construct normal symbol
- * references as the list of symbols contains symbols that are
- * declared static and are private to their .o files. This prevents
- * .tmp_kallsyms.o or any other object from referencing them.
- */
if (!base_relative)
output_label("kallsyms_addresses");
else
@@ -380,6 +376,13 @@ static void write_src(void)
for (i = 0; i < table_cnt; i++) {
if (base_relative) {
+ /*
+ * Use the offset relative to the lowest value
+ * encountered of all relative symbols, and emit
+ * non-relocatable fixed offsets that will be fixed
+ * up at runtime.
+ */
+
long long offset;
int overflow;
@@ -402,12 +405,7 @@ static void write_src(void)
}
printf("\t.long\t%#x\n", (int)offset);
} else if (!symbol_absolute(&table[i])) {
- if (_text <= table[i].addr)
- printf("\tPTR\t_text + %#llx\n",
- table[i].addr - _text);
- else
- printf("\tPTR\t_text - %#llx\n",
- _text - table[i].addr);
+ output_address(table[i].addr);
} else {
printf("\tPTR\t%#llx\n", table[i].addr);
}
@@ -416,7 +414,7 @@ static void write_src(void)
if (base_relative) {
output_label("kallsyms_relative_base");
- printf("\tPTR\t_text - %#llx\n", _text - relative_base);
+ output_address(relative_base);
printf("\n");
}
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] scripts/kallsyms: fix offset overflow of kallsyms_relative_base
2019-12-09 3:51 [PATCH] scripts/kallsyms: fix offset overflow of kallsyms_relative_base Masahiro Yamada
@ 2019-12-17 3:08 ` Masahiro Yamada
0 siblings, 0 replies; 2+ messages in thread
From: Masahiro Yamada @ 2019-12-17 3:08 UTC (permalink / raw)
To: Linux Kbuild mailing list; +Cc: Olof Johansson, Linux Kernel Mailing List
On Mon, Dec 9, 2019 at 12:52 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Since commit 5e5c4fa78745 ("scripts/kallsyms: shrink table before
> sorting it"), kallsyms_relative_base can be larger than _text, which
> causes overflow when building the 32-bit kernel.
>
> https://lkml.org/lkml/2019/12/7/156
>
> This is because _text is, unless --all-symbols is specified, now
> trimmed from the symbol table before record_relative_base() is called.
>
> Handle the offset signedness also for kallsyms_relative_base. Introduce
> a new helper, output_address(), to reduce the code duplication.
>
> Fixes: 5e5c4fa78745 ("scripts/kallsyms: shrink table before sorting it")
> Reported-by: Olof Johansson <olof@lixom.net>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
>
Applied to linux-kbuid.
> scripts/kallsyms.c | 38 ++++++++++++++++++--------------------
> 1 file changed, 18 insertions(+), 20 deletions(-)
>
> diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
> index fb55f262f42d..94153732ec00 100644
> --- a/scripts/kallsyms.c
> +++ b/scripts/kallsyms.c
> @@ -310,6 +310,15 @@ static void output_label(const char *label)
> printf("%s:\n", label);
> }
>
> +/* Provide proper symbols relocatability by their '_text' relativeness. */
> +static void output_address(unsigned long long addr)
> +{
> + if (_text <= addr)
> + printf("\tPTR\t_text + %#llx\n", addr - _text);
> + else
> + printf("\tPTR\t_text - %#llx\n", _text - addr);
> +}
> +
> /* uncompress a compressed symbol. When this function is called, the best table
> * might still be compressed itself, so the function needs to be recursive */
> static int expand_symbol(const unsigned char *data, int len, char *result)
> @@ -360,19 +369,6 @@ static void write_src(void)
>
> printf("\t.section .rodata, \"a\"\n");
>
> - /* Provide proper symbols relocatability by their relativeness
> - * to a fixed anchor point in the runtime image, either '_text'
> - * for absolute address tables, in which case the linker will
> - * emit the final addresses at build time. Otherwise, use the
> - * offset relative to the lowest value encountered of all relative
> - * symbols, and emit non-relocatable fixed offsets that will be fixed
> - * up at runtime.
> - *
> - * The symbol names cannot be used to construct normal symbol
> - * references as the list of symbols contains symbols that are
> - * declared static and are private to their .o files. This prevents
> - * .tmp_kallsyms.o or any other object from referencing them.
> - */
> if (!base_relative)
> output_label("kallsyms_addresses");
> else
> @@ -380,6 +376,13 @@ static void write_src(void)
>
> for (i = 0; i < table_cnt; i++) {
> if (base_relative) {
> + /*
> + * Use the offset relative to the lowest value
> + * encountered of all relative symbols, and emit
> + * non-relocatable fixed offsets that will be fixed
> + * up at runtime.
> + */
> +
> long long offset;
> int overflow;
>
> @@ -402,12 +405,7 @@ static void write_src(void)
> }
> printf("\t.long\t%#x\n", (int)offset);
> } else if (!symbol_absolute(&table[i])) {
> - if (_text <= table[i].addr)
> - printf("\tPTR\t_text + %#llx\n",
> - table[i].addr - _text);
> - else
> - printf("\tPTR\t_text - %#llx\n",
> - _text - table[i].addr);
> + output_address(table[i].addr);
> } else {
> printf("\tPTR\t%#llx\n", table[i].addr);
> }
> @@ -416,7 +414,7 @@ static void write_src(void)
>
> if (base_relative) {
> output_label("kallsyms_relative_base");
> - printf("\tPTR\t_text - %#llx\n", _text - relative_base);
> + output_address(relative_base);
> printf("\n");
> }
>
> --
> 2.17.1
>
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-12-17 3:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-09 3:51 [PATCH] scripts/kallsyms: fix offset overflow of kallsyms_relative_base Masahiro Yamada
2019-12-17 3:08 ` Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox