Re: [RESEND PATCH] module param_call: fix potential NULL pointer dereference

From: AmÃrico Wang
Date: Wed Feb 24 2010 - 20:48:28 EST


On Wed, Feb 24, 2010 at 9:01 AM, Rusty Russell <rusty@xxxxxxxxxxxxxxx> wrote:
> On Wed, 24 Feb 2010 02:15:19 am AmÃrico Wang wrote:
>> On Tue, Feb 23, 2010 at 02:26:45PM +1030, Rusty Russell wrote:
>> >On Mon, 22 Feb 2010 09:10:51 pm Dongdong Deng wrote:
>> >> The param_set_fn() function will get a parameter which is a NULL
>> >> pointer when insmod module via bare params as following method:
>> >>
>> >> $insmod foo.ko foo
>> >>
>> >> If the param_set_fn() function didn't check that parameter and used
>> >> it directly, it could caused an OOPS due to NULL pointer dereference.
>> >>
>> >> The solution is simple:
>> >> Using "" to replace NULL parameter, thereby the param_set_fn()
>> >> function will never get a NULL pointer.
>> >
>> >This changes the value of booleans, and loses checking for int params, etc.
>> >
>> >I liked Americo's approach; I've combined the two approaches below.
>> >
>> >Since I'm going away, can Andrew take this?
>> >
>> >Subject: 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 as suggested by Americo.
>> >
>> >Signed-off-by: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
>> >Cc: Dongdong Deng <dongdong.deng@xxxxxxxxxxxxx>
>> >Cc: AmÃrico Wang <xiyou.wangcong@xxxxxxxxx>
>> >
>> >diff --git a/kernel/params.c b/kernel/params.c
>> >--- a/kernel/params.c
>> >+++ b/kernel/params.c
>> >@@ -59,6 +59,9 @@ static int parse_one(char *param,
>> > Â Â /* Find parameter */
>> > Â Â for (i = 0; i < num_params; i++) {
>> > Â Â Â Â Â Â if (parameq(param, params[i].name)) {
>> >+ Â Â Â Â Â Â Â Â Â Â/* Noone handled NULL, so do it here. */
>> >+ Â Â Â Â Â Â Â Â Â Âif (!val && params[i].set != param_set_bool)
>> >+ Â Â Â Â Â Â Â Â Â Â Â Â Â Âreturn -EINVAL;
>>
>> Sorry, after rethinking about this, I think it might be wrong.
>>
>> With this patch, when I use non-standard bool functions, I will not
>> have a chance to use '!val' which should be valid for all bool
>> functions. Or am I missing something?
>
> Sure, at that point we'd need something more sophisticated. ÂBut to
> fix this properly we want a flags word, and thus something like this
> which I worked on earlier:
>
> http://ozlabs.org/~rusty/kernel/rr-latest/param:param_ops.patch
>

Thanks, Rusty!

I love that patch, but since 2.6.33 is already out, can we try to get it
merged for 2.6.34?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/