diff options
| author | Masahiro Yamada <masahiroy@kernel.org> | 2025-01-03 16:30:39 +0900 |
|---|---|---|
| committer | Masahiro Yamada <masahiroy@kernel.org> | 2025-01-10 23:01:22 +0900 |
| commit | be2fa44b5180a1f021efb40c55fdf63c249c3209 (patch) | |
| tree | 488b31c6af3c587c80db6ac2390fb4c10e8776a5 /scripts/genksyms/genksyms.h | |
| parent | genksyms: fix memory leak when the same symbol is added from source (diff) | |
| download | linux-be2fa44b5180a1f021efb40c55fdf63c249c3209.tar.gz linux-be2fa44b5180a1f021efb40c55fdf63c249c3209.zip | |
genksyms: fix memory leak when the same symbol is read from *.symref file
When a symbol that is already registered is read again from *.symref
file, __add_symbol() removes the previous one from the hash table without
freeing it.
[Test Case]
$ cat foo.c
#include <linux/export.h>
void foo(void);
void foo(void) {}
EXPORT_SYMBOL(foo);
$ cat foo.symref
foo void foo ( void )
foo void foo ( void )
When a symbol is removed from the hash table, it must be freed along
with its ->name and ->defn members. However, sym->name cannot be freed
because it is sometimes shared with node->string, but not always. If
sym->name and node->string share the same memory, free(sym->name) could
lead to a double-free bug.
To resolve this issue, always assign a strdup'ed string to sym->name.
Fixes: 64e6c1e12372 ("genksyms: track symbol checksum changes")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Diffstat (limited to 'scripts/genksyms/genksyms.h')
| -rw-r--r-- | scripts/genksyms/genksyms.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/scripts/genksyms/genksyms.h b/scripts/genksyms/genksyms.h index 21ed2ec2d98c..5621533dcb8e 100644 --- a/scripts/genksyms/genksyms.h +++ b/scripts/genksyms/genksyms.h @@ -32,7 +32,7 @@ struct string_list { struct symbol { struct symbol *hash_next; - const char *name; + char *name; enum symbol_type type; struct string_list *defn; struct symbol *expansion_trail; |
