提交 153f32d7 编写于 作者: B Boqun Feng 提交者: Zheng Zengkai

kallsyms: avoid hardcoding the buffer size

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

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

This makes it easier to update the size later on.

Furthermore, a static assert is added to ensure both are updated
when that happens. The relationship used is one that keeps the new
size (512+1) close to the original buffer size (500).
Reviewed-by: NKees Cook <keescook@chromium.org>
Signed-off-by: NBoqun Feng <boqun.feng@gmail.com>
Co-developed-by: NMiguel Ojeda <ojeda@kernel.org>
Signed-off-by: NMiguel Ojeda <ojeda@kernel.org>
Signed-off-by: NWeilong Chen <chenweilong@huawei.com>
上级 99d1d3bc
...@@ -27,8 +27,18 @@ ...@@ -27,8 +27,18 @@
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
#define _stringify_1(x) #x
#define _stringify(x) _stringify_1(x)
#define KSYM_NAME_LEN 128 #define KSYM_NAME_LEN 128
/* A substantially bigger size than the current maximum. */
#define KSYM_NAME_LEN_BUFFER 512
_Static_assert(
KSYM_NAME_LEN_BUFFER == KSYM_NAME_LEN * 4,
"Please keep KSYM_NAME_LEN_BUFFER in sync with KSYM_NAME_LEN"
);
struct sym_entry { struct sym_entry {
unsigned long long addr; unsigned long long addr;
unsigned int len; unsigned int len;
...@@ -197,15 +207,15 @@ static void check_symbol_range(const char *sym, unsigned long long addr, ...@@ -197,15 +207,15 @@ static void check_symbol_range(const char *sym, unsigned long long addr,
static struct sym_entry *read_symbol(FILE *in) static struct sym_entry *read_symbol(FILE *in)
{ {
char name[500], type; char name[KSYM_NAME_LEN_BUFFER+1], type;
unsigned long long addr; unsigned long long addr;
unsigned int len; unsigned int len;
struct sym_entry *sym; struct sym_entry *sym;
int rc; int rc;
rc = fscanf(in, "%llx %c %499s\n", &addr, &type, name); rc = fscanf(in, "%llx %c %" _stringify(KSYM_NAME_LEN_BUFFER) "s\n", &addr, &type, name);
if (rc != 3) { if (rc != 3) {
if (rc != EOF && fgets(name, 500, in) == NULL) if (rc != EOF && fgets(name, sizeof(name), in) == NULL)
fprintf(stderr, "Read error or end of file.\n"); fprintf(stderr, "Read error or end of file.\n");
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册