Re: [PATCH] kprobes: disable preempt for module_text_address()

From: Lai Jiangshan
Date: Tue Nov 04 2008 - 20:50:48 EST


Masami Hiramatsu wrote:
> Hi Lai,
>
> Lai Jiangshan wrote:
>> __register_kprobe() may be preempted after module_text_address()
>> but before try_module_get(), and in this interval the module may be
>> unloaded and try_module_get(probed_mod) will access to invalid address.
>> this patch uses preempt_disable() to protect it.
>
> Thank you for your work.
>
> I think this is the problem of module_text_address() because it can
> return incorrect address of struct module if a preemption happens.
> So, I think the module_text_address() would better to call try_module_get()
> before returning its address, or at least they should comment that caller
> needs disabling preemption.
>
> struct module *module_text_address(unsigned long addr)
> {
> struct module *mod;
>
> preempt_disable(); /*
> * I also think this preemption disabling is not so useful
> * without try_module_get(), because caller have to
> * disable preemption...
> */
> mod = __module_text_address(addr);
> /* here, try_module_get() is needed.
> * (or commenting "caller must disable preemption!") */
> preempt_enable();
>
> /*
> * !!Here!! if the preemption happened, it could return invalid "mod".
> * In that case, even if module_text_address() returns non-NULL,
> * the addr is no longer in any module.
> */
> return mod;
> }
>
> Thank you,
>

I don't think module_text_address() are needed to modified.
only __register_kprobe() uses module_text_address()'s return value.
other users of module_text_address() are just for testing it's
return value. so only __register_kprobe() needs disabling preemption
currently.

actually, calling __module_text_address() in __register_kprobe() is
better after my fix applied. but I found that a line have exceed
80 characters, so I don't use __module_text_address().

Thanx, Lai



--
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/