]> git.ipfire.org Git - thirdparty/linux.git/commit
module: Fix freeing of charp module parameters when CONFIG_SYSFS=n
authorPetr Pavlu <petr.pavlu@suse.com>
Fri, 13 Mar 2026 13:48:02 +0000 (14:48 +0100)
committerSami Tolvanen <samitolvanen@google.com>
Wed, 18 Mar 2026 21:43:18 +0000 (21:43 +0000)
commitdeffe1edba626d474fef38007c03646ca5876a0e
tree113de16495393340dc12e1891e4b5c181644ead1
parent4afc71bba8b7d7841681e7647ae02f5079aaf28f
module: Fix freeing of charp module parameters when CONFIG_SYSFS=n

When setting a charp module parameter, the param_set_charp() function
allocates memory to store a copy of the input value. Later, when the module
is potentially unloaded, the destroy_params() function is called to free
this allocated memory.

However, destroy_params() is available only when CONFIG_SYSFS=y, otherwise
only a dummy variant is present. In the unlikely case that the kernel is
configured with CONFIG_MODULES=y and CONFIG_SYSFS=n, this results in
a memory leak of charp values when a module is unloaded.

Fix this issue by making destroy_params() always available when
CONFIG_MODULES=y. Rename the function to module_destroy_params() to clarify
that it is intended for use by the module loader.

Fixes: e180a6b7759a ("param: fix charp parameters set via sysfs")
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
include/linux/moduleparam.h
kernel/module/main.c
kernel/params.c