OpenCloudOS-Kernel/scripts/genksyms
Masahiro Yamada 4517f37bf5 genksyms: fix memory leak when the same symbol is read from *.symref file
[ Upstream commit be2fa44b5180a1f021efb40c55fdf63c249c3209 ]

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: 64e6c1e123 ("genksyms: track symbol checksum changes")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-02-08 09:52:32 +01:00
..
.gitignore .gitignore: prefix local generated files with a slash 2021-05-02 00:43:35 +09:00
Makefile genksyms: fix stale comment 2021-05-02 00:43:34 +09:00
genksyms.c genksyms: fix memory leak when the same symbol is read from *.symref file 2025-02-08 09:52:32 +01:00
genksyms.h genksyms: fix memory leak when the same symbol is read from *.symref file 2025-02-08 09:52:32 +01:00
keywords.c genksyms: Ignore module scoped _Static_assert() 2020-12-21 13:57:08 +09:00
lex.l genksyms: remove useless case DOTS 2021-02-16 12:01:45 +09:00
parse.y genksyms: fix memory leak when the same symbol is read from *.symref file 2025-02-08 09:52:32 +01:00