Skip to content

Commit 2e9fb99

Browse files
committed
params: don't hand NULL values to param.set callbacks.
An audit by Dongdong Deng revealed that most driver-author-written param calls don't handle val == NULL (which happens when parameters are specified with no =, eg "foo" instead of "foo=1"). The only real case to use this is boolean, so handle it specially for that case and remove a source of bugs for everyone else. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Cc: Dongdong Deng <dongdong.deng@windriver.com> Cc: Américo Wang <xiyou.wangcong@gmail.com>
1 parent d280080 commit 2e9fb99

1 file changed

Lines changed: 3 additions & 17 deletions

File tree

‎kernel/params.c‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ static int parse_one(char *param,
5858
/* Find parameter */
5959
for (i = 0; i < num_params; i++) {
6060
if (parameq(param, params[i].name)) {
61+
/* Noone handled NULL, so do it here. */
62+
if (!val && params[i].set != param_set_bool)
63+
return -EINVAL;
6164
DEBUGP("They are equal! Calling %p\n",
6265
params[i].set);
6366
return params[i].set(val, &params[i]);
@@ -181,7 +184,6 @@ int parse_args(const char *name,
181184
tmptype l; \
182185
int ret; \
183186
\
184-
if (!val) return -EINVAL; \
185187
ret = strtolfn(val, 0, &l); \
186188
if (ret == -EINVAL || ((type)l != l)) \
187189
return -EINVAL; \
@@ -203,12 +205,6 @@ STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, strict_strtoul);
203205

204206
int param_set_charp(const char *val, struct kernel_param *kp)
205207
{
206-
if (!val) {
207-
printk(KERN_ERR "%s: string parameter expected\n",
208-
kp->name);
209-
return -EINVAL;
210-
}
211-
212208
if (strlen(val) > 1024) {
213209
printk(KERN_ERR "%s: string parameter too long\n",
214210
kp->name);
@@ -309,12 +305,6 @@ static int param_array(const char *name,
309305
kp.arg = elem;
310306
kp.flags = flags;
311307

312-
/* No equals sign? */
313-
if (!val) {
314-
printk(KERN_ERR "%s: expects arguments\n", name);
315-
return -EINVAL;
316-
}
317-
318308
*num = 0;
319309
/* We expect a comma-separated list of values. */
320310
do {
@@ -381,10 +371,6 @@ int param_set_copystring(const char *val, struct kernel_param *kp)
381371
{
382372
const struct kparam_string *kps = kp->str;
383373

384-
if (!val) {
385-
printk(KERN_ERR "%s: missing param set value\n", kp->name);
386-
return -EINVAL;
387-
}
388374
if (strlen(val)+1 > kps->maxlen) {
389375
printk(KERN_ERR "%s: string doesn't fit in %u chars.\n",
390376
kp->name, kps->maxlen-1);

0 commit comments

Comments
 (0)