Skip to content

Commit 65afac7

Browse files
committed
param: fix lots of bugs with writing charp params from sysfs, by leaking mem.
e180a6b "param: fix charp parameters set via sysfs" fixed the case where charp parameters written via sysfs were freed, leaving drivers accessing random memory. Unfortunately, storing a flag in the kparam struct was a bad idea: it's rodata so setting it causes an oops on some archs. But that's not all: 1) module_param_array() on charp doesn't work reliably, since we use an uninitialized temporary struct kernel_param. 2) there's a fundamental race if a module uses this parameter and then it's changed: they will still access the old, freed, memory. The simplest fix (ie. for 2.6.32) is to never free the memory. This prevents all these problems, at cost of a memory leak. In practice, there are only 18 places where a charp is writable via sysfs, and all are root-only writable. Reported-by: Takashi Iwai <tiwai@suse.de> Cc: Sitsofe Wheeler <sitsofe@yahoo.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Christof Schmitt <christof.schmitt@de.ibm.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Cc: stable@kernel.org
1 parent 964fe08 commit 65afac7

2 files changed

Lines changed: 1 addition & 10 deletions

File tree

‎include/linux/moduleparam.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ typedef int (*param_set_fn)(const char *val, struct kernel_param *kp);
3737
typedef int (*param_get_fn)(char *buffer, struct kernel_param *kp);
3838

3939
/* Flag bits for kernel_param.flags */
40-
#define KPARAM_KMALLOCED 1
4140
#define KPARAM_ISBOOL 2
4241

4342
struct kernel_param {

‎kernel/params.c‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,9 @@ int param_set_charp(const char *val, struct kernel_param *kp)
218218
return -ENOSPC;
219219
}
220220

221-
if (kp->flags & KPARAM_KMALLOCED)
222-
kfree(*(char **)kp->arg);
223-
224221
/* This is a hack. We can't need to strdup in early boot, and we
225222
* don't need to; this mangled commandline is preserved. */
226223
if (slab_is_available()) {
227-
kp->flags |= KPARAM_KMALLOCED;
228224
*(char **)kp->arg = kstrdup(val, GFP_KERNEL);
229225
if (!kp->arg)
230226
return -ENOMEM;
@@ -605,11 +601,7 @@ void module_param_sysfs_remove(struct module *mod)
605601

606602
void destroy_params(const struct kernel_param *params, unsigned num)
607603
{
608-
unsigned int i;
609-
610-
for (i = 0; i < num; i++)
611-
if (params[i].flags & KPARAM_KMALLOCED)
612-
kfree(*(char **)params[i].arg);
604+
/* FIXME: This should free kmalloced charp parameters. It doesn't. */
613605
}
614606

615607
static void __init kernel_add_sysfs_param(const char *name,

0 commit comments

Comments
 (0)