summaryrefslogtreecommitdiff
path: root/scripts/genksyms/parse.y
diff options
context:
space:
mode:
authorMasahiro Yamada <masahiroy@kernel.org>2025-01-03 10:30:39 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-03-13 14:46:58 +0300
commita13772b475aa404872da06ff3de2dfe9530dbb06 (patch)
treecd41ac99e23a8c0fcc513cf23701772f80130950 /scripts/genksyms/parse.y
parentf34bbd20257916d0aef9240f5e1a245ba37af3b0 (diff)
downloadlinux-a13772b475aa404872da06ff3de2dfe9530dbb06.tar.xz
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: 64e6c1e12372 ("genksyms: track symbol checksum changes") Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'scripts/genksyms/parse.y')
-rw-r--r--scripts/genksyms/parse.y4
1 files changed, 2 insertions, 2 deletions
diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y
index 7df3fe290d53..84813ce54a2d 100644
--- a/scripts/genksyms/parse.y
+++ b/scripts/genksyms/parse.y
@@ -479,12 +479,12 @@ enumerator_list:
enumerator:
IDENT
{
- const char *name = strdup((*$1)->string);
+ const char *name = (*$1)->string;
add_symbol(name, SYM_ENUM_CONST, NULL, 0);
}
| IDENT '=' EXPRESSION_PHRASE
{
- const char *name = strdup((*$1)->string);
+ const char *name = (*$1)->string;
struct string_list *expr = copy_list_range(*$3, *$2);
add_symbol(name, SYM_ENUM_CONST, expr, 0);
}