提交 359527df 编写于 作者: M Miguel Ojeda 提交者: Zheng Zengkai

kallsyms: increase maximum kernel symbol length to 512

maillist inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5J75G
CVE: NA

Reference: https://lore.kernel.org/rust-for-linux/CANiq72nDcJLSB3pLhkdqGdLitfmqqCUVVfkY5EjP9AcwVv9B4A@mail.gmail.com/T/#t

--------------------------------

Rust symbols can become quite long due to namespacing introduced
by modules, types, traits, generics, etc. For instance,
the following code:

    pub mod my_module {
        pub struct MyType;
        pub struct MyGenericType<T>(T);

        pub trait MyTrait {
            fn my_method() -> u32;
        }

        impl MyTrait for MyGenericType<MyType> {
            fn my_method() -> u32 {
                42
            }
        }
    }

generates a symbol of length 96 when using the upcoming v0 mangling scheme:

    _RNvXNtCshGpAVYOtgW1_7example9my_moduleINtB2_13MyGenericTypeNtB2_6MyTypeENtB2_7MyTrait9my_method

At the moment, Rust symbols may reach up to 300 in length.
Setting 512 as the maximum seems like a reasonable choice to
keep some headroom.
Reviewed-by: NKees Cook <keescook@chromium.org>
Reviewed-by: NPetr Mladek <pmladek@suse.com>
Co-developed-by: NAlex Gaynor <alex.gaynor@gmail.com>
Signed-off-by: NAlex Gaynor <alex.gaynor@gmail.com>
Co-developed-by: NWedson Almeida Filho <wedsonaf@google.com>
Signed-off-by: NWedson Almeida Filho <wedsonaf@google.com>
Co-developed-by: NGary Guo <gary@garyguo.net>
Signed-off-by: NGary Guo <gary@garyguo.net>
Co-developed-by: NBoqun Feng <boqun.feng@gmail.com>
Signed-off-by: NBoqun Feng <boqun.feng@gmail.com>
Signed-off-by: NMiguel Ojeda <ojeda@kernel.org>
Signed-off-by: NWeilong Chen <chenweilong@huawei.com>
上级 29aee99a
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <asm/sections.h> #include <asm/sections.h>
#define KSYM_NAME_LEN 128 #define KSYM_NAME_LEN 512
#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \ #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1) 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
......
...@@ -287,7 +287,7 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab, ...@@ -287,7 +287,7 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab,
* we use the smallest/strictest upper bound possible (56, based on * we use the smallest/strictest upper bound possible (56, based on
* the current definition of MODULE_NAME_LEN) to prevent overflows. * the current definition of MODULE_NAME_LEN) to prevent overflows.
*/ */
BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 128); BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 512);
#ifdef CONFIG_MODULES_USE_ELF_RELA #ifdef CONFIG_MODULES_USE_ELF_RELA
relas = (Elf_Rela *) relasec->sh_addr; relas = (Elf_Rela *) relasec->sh_addr;
...@@ -305,7 +305,7 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab, ...@@ -305,7 +305,7 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab,
/* Format: .klp.sym.sym_objname.sym_name,sympos */ /* Format: .klp.sym.sym_objname.sym_name,sympos */
cnt = sscanf(strtab + sym->st_name, cnt = sscanf(strtab + sym->st_name,
".klp.sym.%55[^.].%127[^,],%lu", ".klp.sym.%55[^.].%511[^,],%lu",
sym_objname, sym_name, &sympos); sym_objname, sym_name, &sympos);
if (cnt != 3) { if (cnt != 3) {
pr_err("symbol %s has an incorrectly formatted name\n", pr_err("symbol %s has an incorrectly formatted name\n",
......
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
#define _stringify_1(x) #x #define _stringify_1(x) #x
#define _stringify(x) _stringify_1(x) #define _stringify(x) _stringify_1(x)
#define KSYM_NAME_LEN 128 #define KSYM_NAME_LEN 512
/* A substantially bigger size than the current maximum. */ /* A substantially bigger size than the current maximum. */
#define KSYM_NAME_LEN_BUFFER 512 #define KSYM_NAME_LEN_BUFFER 2048
_Static_assert( _Static_assert(
KSYM_NAME_LEN_BUFFER == KSYM_NAME_LEN * 4, KSYM_NAME_LEN_BUFFER == KSYM_NAME_LEN * 4,
"Please keep KSYM_NAME_LEN_BUFFER in sync with KSYM_NAME_LEN" "Please keep KSYM_NAME_LEN_BUFFER in sync with KSYM_NAME_LEN"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#define KSYM_NAME_LEN 128 #define KSYM_NAME_LEN 512
struct module; struct module;
......
...@@ -85,7 +85,7 @@ struct perf_record_throttle { ...@@ -85,7 +85,7 @@ struct perf_record_throttle {
}; };
#ifndef KSYM_NAME_LEN #ifndef KSYM_NAME_LEN
#define KSYM_NAME_LEN 256 #define KSYM_NAME_LEN 512
#endif #endif
struct perf_record_ksymbol { struct perf_record_ksymbol {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <linux/types.h> #include <linux/types.h>
#ifndef KSYM_NAME_LEN #ifndef KSYM_NAME_LEN
#define KSYM_NAME_LEN 256 #define KSYM_NAME_LEN 512
#endif #endif
static inline u8 kallsyms2elf_binding(char type) static inline u8 kallsyms2elf_binding(char type)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册