2013-08-11 00:56:10

by Andi Kleen

[permalink] [raw]
Subject: [PATCH 1/3] kbuild: Increase kallsyms max symbol length

From: Joe Mario <[email protected]>

[AK: This seems like a ticking time bomb even without LTO,
so should be merged now. It causes very weird problems.
Thanks to Joe for tracking them down.]

With the added postfixes that LTO adds for local
symbols, the longest name in the kernel overflows
the namebuf[KSYM_NAME_LEN] array by two bytes. That name is:
__pci_fixup_resumePCI_VENDOR_ID_SERVERWORKSPCI_DEVICE_ID_SERVERWORKS_HT1000SBquirk_disable_broadcom_boot_interrupt.1488004.672802

Double the max symbol name length.

Signed-off-by: Andi Kleen <[email protected]>
---
include/linux/kallsyms.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 6883e19..711a50f 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -9,7 +9,7 @@
#include <linux/kernel.h>
#include <linux/stddef.h>

-#define KSYM_NAME_LEN 128
+#define KSYM_NAME_LEN 256
#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)

--
1.8.3.1


2013-08-11 00:55:53

by Andi Kleen

[permalink] [raw]
Subject: [PATCH 2/3] Kbuild: Handle longer symbols in kallsyms.c

From: Andi Kleen <[email protected]>

Also warn for too long symbols

Signed-off-by: Andi Kleen <[email protected]>
---
scripts/kallsyms.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 6940f00..e5af4c5 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -27,7 +27,7 @@
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
#endif

-#define KSYM_NAME_LEN 128
+#define KSYM_NAME_LEN 256

struct sym_entry {
unsigned long long addr;
@@ -118,6 +118,12 @@ static int read_symbol(FILE *in, struct sym_entry *s)
fprintf(stderr, "Read error or end of file.\n");
return -1;
}
+ if (strlen(str) > KSYM_NAME_LEN) {
+ fprintf(stderr, "Symbol %s too long for kallsyms.\n"
+ "Please increae KSYM_NAME_LEN both in kernel and kallsyms.c",
+ str);
+ return -1;
+ }

sym = str;
/* skip prefix char */
--
1.8.3.1

2013-08-11 00:55:59

by Andi Kleen

[permalink] [raw]
Subject: [PATCH 3/3] kprobes: Use KSYM_NAME_LEN to size identifier buffers

From: Joe Mario <[email protected]>

Use KSYM_NAME_LEN to size identifier buffers, so that it can
be easier increased.

Cc: [email protected]
Signed-off-by: Joe Mario <[email protected]>
Signed-off-by: Andi Kleen <[email protected]>
---
kernel/kprobes.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 6e33498..e174daf 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2083,7 +2083,7 @@ static int __init init_kprobes(void)
{
int i, err = 0;
unsigned long offset = 0, size = 0;
- char *modname, namebuf[128];
+ char *modname, namebuf[KSYM_NAME_LEN];
const char *symbol_name;
void *addr;
struct kprobe_blackpoint *kb;
@@ -2209,7 +2209,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
const char *sym = NULL;
unsigned int i = *(loff_t *) v;
unsigned long offset = 0;
- char *modname, namebuf[128];
+ char *modname, namebuf[KSYM_NAME_LEN];

head = &kprobe_table[i];
preempt_disable();
--
1.8.3.1

Subject: Re: [PATCH 3/3] kprobes: Use KSYM_NAME_LEN to size identifier buffers

On Sat, Aug 10, 2013 at 05:55:33PM -0700, Andi Kleen wrote:
> From: Joe Mario <[email protected]>
>
> Use KSYM_NAME_LEN to size identifier buffers, so that it can
> be easier increased.
>
> Cc: [email protected]
> Signed-off-by: Joe Mario <[email protected]>
> Signed-off-by: Andi Kleen <[email protected]>

Acked-by: Ananth N Mavinakayanahalli <[email protected]>

> ---
> kernel/kprobes.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 6e33498..e174daf 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2083,7 +2083,7 @@ static int __init init_kprobes(void)
> {
> int i, err = 0;
> unsigned long offset = 0, size = 0;
> - char *modname, namebuf[128];
> + char *modname, namebuf[KSYM_NAME_LEN];
> const char *symbol_name;
> void *addr;
> struct kprobe_blackpoint *kb;
> @@ -2209,7 +2209,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
> const char *sym = NULL;
> unsigned int i = *(loff_t *) v;
> unsigned long offset = 0;
> - char *modname, namebuf[128];
> + char *modname, namebuf[KSYM_NAME_LEN];
>
> head = &kprobe_table[i];
> preempt_disable();
> --
> 1.8.3.1