LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	ananth@in.ibm.com, David Miller <davem@davemloft.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Rusty Russell <rusty@rustcorp.com.au>
Subject: Re: [PATCH] kprobes: disable preempt for module_text_address()
Date: Wed, 05 Nov 2008 09:47:41 +0800	[thread overview]
Message-ID: <4910FB3D.4020805@cn.fujitsu.com> (raw)
In-Reply-To: <4910F697.2050203@redhat.com>

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




  reply	other threads:[~2008-11-05  1:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-04  5:56 Lai Jiangshan
2008-11-04 14:28 ` Ananth N Mavinakayanahalli
2008-11-05  0:53   ` Lai Jiangshan
2008-11-05  1:27 ` Masami Hiramatsu
2008-11-05  1:47   ` Lai Jiangshan [this message]
2008-11-05 19:30     ` Hiroshi Shimamoto
2008-11-05 21:40     ` Masami Hiramatsu
2008-11-05 22:46       ` Hiroshi Shimamoto
2008-11-05 23:07         ` Masami Hiramatsu
2008-11-06  0:06           ` [PATCH] kprobes: bugfix: try_module_get even if calling_mod is NULL Masami Hiramatsu
2008-11-07  1:00             ` Andrew Morton
2008-11-07  2:28               ` Masami Hiramatsu
2008-11-07  2:54                 ` Andrew Morton
2008-11-07  4:46                   ` Ananth N Mavinakayanahalli
2008-11-06  1:06       ` [PATCH] kprobes: disable preempt for module_text_address() Lai Jiangshan
2008-11-06 15:37         ` [PATCH] kprobes: disable preempt for module_text_address() and kernel_text_address() Masami Hiramatsu
2008-11-07  0:32           ` Lai Jiangshan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4910FB3D.4020805@cn.fujitsu.com \
    --to=laijs@cn.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=ananth@in.ibm.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --subject='Re: [PATCH] kprobes: disable preempt for module_text_address()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).