public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -tip ] [BUGFIX] kprobes: Fix a double lock bug of kprobe_mutex
@ 2013-04-18  9:33 Masami Hiramatsu
  2013-04-18 15:49 ` Ananth N Mavinakayanahalli
  2013-04-18 18:17 ` Tejun Heo
  0 siblings, 2 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2013-04-18  9:33 UTC (permalink / raw)
  To: Ingo Molnar, Linus Torvalds, linux-kernel
  Cc: Tejun Heo, David S. Miller, Ananth N Mavinakayanahalli,
	yrl.pp-manager.tt

Fix a double locking bug caused when debug.kprobe-optimization=0.
While the proc_kprobes_optimization_handler locks kprobe_mutex,
wait_for_kprobe_optimizer locks it again and that causes a double lock.
To fix the bug, this introduces different mutex for protecting
sysctl parameter and locks it in proc_kprobes_optimization_handler.
Of course, since we need to lock kprobe_mutex when touching kprobes
resources, that is done in *optimize_all_kprobes().

This bug was from ad72b3bea744b4db01c89af0f86f3e8920d354df

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
---
 kernel/kprobes.c |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index e35be53..3fed7f0 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -794,16 +794,16 @@ out:
 }
 
 #ifdef CONFIG_SYSCTL
-/* This should be called with kprobe_mutex locked */
 static void __kprobes optimize_all_kprobes(void)
 {
 	struct hlist_head *head;
 	struct kprobe *p;
 	unsigned int i;
 
+	mutex_lock(&kprobe_mutex);
 	/* If optimization is already allowed, just return */
 	if (kprobes_allow_optimization)
-		return;
+		goto out;
 
 	kprobes_allow_optimization = true;
 	for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
@@ -813,18 +813,22 @@ static void __kprobes optimize_all_kprobes(void)
 				optimize_kprobe(p);
 	}
 	printk(KERN_INFO "Kprobes globally optimized\n");
+out:
+	mutex_unlock(&kprobe_mutex);
 }
 
-/* This should be called with kprobe_mutex locked */
 static void __kprobes unoptimize_all_kprobes(void)
 {
 	struct hlist_head *head;
 	struct kprobe *p;
 	unsigned int i;
 
+	mutex_lock(&kprobe_mutex);
 	/* If optimization is already prohibited, just return */
-	if (!kprobes_allow_optimization)
+	if (!kprobes_allow_optimization) {
+		mutex_unlock(&kprobe_mutex);
 		return;
+	}
 
 	kprobes_allow_optimization = false;
 	for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
@@ -834,11 +838,14 @@ static void __kprobes unoptimize_all_kprobes(void)
 				unoptimize_kprobe(p, false);
 		}
 	}
+	mutex_unlock(&kprobe_mutex);
+
 	/* Wait for unoptimizing completion */
 	wait_for_kprobe_optimizer();
 	printk(KERN_INFO "Kprobes globally unoptimized\n");
 }
 
+static DEFINE_MUTEX(kprobe_sysctl_mutex);
 int sysctl_kprobes_optimization;
 int proc_kprobes_optimization_handler(struct ctl_table *table, int write,
 				      void __user *buffer, size_t *length,
@@ -846,7 +853,7 @@ int proc_kprobes_optimization_handler(struct ctl_table *table, int write,
 {
 	int ret;
 
-	mutex_lock(&kprobe_mutex);
+	mutex_lock(&kprobe_sysctl_mutex);
 	sysctl_kprobes_optimization = kprobes_allow_optimization ? 1 : 0;
 	ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
 
@@ -854,7 +861,7 @@ int proc_kprobes_optimization_handler(struct ctl_table *table, int write,
 		optimize_all_kprobes();
 	else
 		unoptimize_all_kprobes();
-	mutex_unlock(&kprobe_mutex);
+	mutex_unlock(&kprobe_sysctl_mutex);
 
 	return ret;
 }


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH -tip ] [BUGFIX] kprobes: Fix a double lock bug of kprobe_mutex
  2013-04-18  9:33 [PATCH -tip ] [BUGFIX] kprobes: Fix a double lock bug of kprobe_mutex Masami Hiramatsu
@ 2013-04-18 15:49 ` Ananth N Mavinakayanahalli
  2013-04-18 18:17 ` Tejun Heo
  1 sibling, 0 replies; 5+ messages in thread
From: Ananth N Mavinakayanahalli @ 2013-04-18 15:49 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Linus Torvalds, linux-kernel, Tejun Heo,
	David S. Miller, yrl.pp-manager.tt

On Thu, Apr 18, 2013 at 06:33:18PM +0900, Masami Hiramatsu wrote:
> Fix a double locking bug caused when debug.kprobe-optimization=0.
> While the proc_kprobes_optimization_handler locks kprobe_mutex,
> wait_for_kprobe_optimizer locks it again and that causes a double lock.
> To fix the bug, this introduces different mutex for protecting
> sysctl parameter and locks it in proc_kprobes_optimization_handler.
> Of course, since we need to lock kprobe_mutex when touching kprobes
> resources, that is done in *optimize_all_kprobes().
> 
> This bug was from ad72b3bea744b4db01c89af0f86f3e8920d354df
> 
> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
> Cc: "David S. Miller" <davem@davemloft.net>

Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -tip ] [BUGFIX] kprobes: Fix a double lock bug of kprobe_mutex
  2013-04-18  9:33 [PATCH -tip ] [BUGFIX] kprobes: Fix a double lock bug of kprobe_mutex Masami Hiramatsu
  2013-04-18 15:49 ` Ananth N Mavinakayanahalli
@ 2013-04-18 18:17 ` Tejun Heo
  2013-04-19  7:22   ` Ingo Molnar
  1 sibling, 1 reply; 5+ messages in thread
From: Tejun Heo @ 2013-04-18 18:17 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Linus Torvalds, linux-kernel, David S. Miller,
	Ananth N Mavinakayanahalli, yrl.pp-manager.tt

On Thu, Apr 18, 2013 at 06:33:18PM +0900, Masami Hiramatsu wrote:
> Fix a double locking bug caused when debug.kprobe-optimization=0.
> While the proc_kprobes_optimization_handler locks kprobe_mutex,
> wait_for_kprobe_optimizer locks it again and that causes a double lock.
> To fix the bug, this introduces different mutex for protecting
> sysctl parameter and locks it in proc_kprobes_optimization_handler.
> Of course, since we need to lock kprobe_mutex when touching kprobes
> resources, that is done in *optimize_all_kprobes().
> 
> This bug was from ad72b3bea744b4db01c89af0f86f3e8920d354df
> 
> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
> Cc: "David S. Miller" <davem@davemloft.net>

Oops,

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -tip ] [BUGFIX] kprobes: Fix a double lock bug of kprobe_mutex
  2013-04-18 18:17 ` Tejun Heo
@ 2013-04-19  7:22   ` Ingo Molnar
  2013-04-19  7:25     ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2013-04-19  7:22 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Masami Hiramatsu, Ingo Molnar, Linus Torvalds, linux-kernel,
	David S. Miller, Ananth N Mavinakayanahalli, yrl.pp-manager.tt


* Tejun Heo <tj@kernel.org> wrote:

> On Thu, Apr 18, 2013 at 06:33:18PM +0900, Masami Hiramatsu wrote:
> > Fix a double locking bug caused when debug.kprobe-optimization=0.
> > While the proc_kprobes_optimization_handler locks kprobe_mutex,
> > wait_for_kprobe_optimizer locks it again and that causes a double lock.
> > To fix the bug, this introduces different mutex for protecting
> > sysctl parameter and locks it in proc_kprobes_optimization_handler.
> > Of course, since we need to lock kprobe_mutex when touching kprobes
> > resources, that is done in *optimize_all_kprobes().
> > 
> > This bug was from ad72b3bea744b4db01c89af0f86f3e8920d354df
> > 
> > Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Tejun Heo <tj@kernel.org>
> > Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
> > Cc: "David S. Miller" <davem@davemloft.net>
> 
> Oops,
> 
> Acked-by: Tejun Heo <tj@kernel.org>

Since you pushed the original commit, mind pushing this fix to Linus too?

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -tip ] [BUGFIX] kprobes: Fix a double lock bug of kprobe_mutex
  2013-04-19  7:22   ` Ingo Molnar
@ 2013-04-19  7:25     ` Ingo Molnar
  0 siblings, 0 replies; 5+ messages in thread
From: Ingo Molnar @ 2013-04-19  7:25 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Masami Hiramatsu, Ingo Molnar, Linus Torvalds, linux-kernel,
	David S. Miller, Ananth N Mavinakayanahalli, yrl.pp-manager.tt


* Ingo Molnar <mingo@kernel.org> wrote:

> 
> * Tejun Heo <tj@kernel.org> wrote:
> 
> > On Thu, Apr 18, 2013 at 06:33:18PM +0900, Masami Hiramatsu wrote:
> > > Fix a double locking bug caused when debug.kprobe-optimization=0.
> > > While the proc_kprobes_optimization_handler locks kprobe_mutex,
> > > wait_for_kprobe_optimizer locks it again and that causes a double lock.
> > > To fix the bug, this introduces different mutex for protecting
> > > sysctl parameter and locks it in proc_kprobes_optimization_handler.
> > > Of course, since we need to lock kprobe_mutex when touching kprobes
> > > resources, that is done in *optimize_all_kprobes().
> > > 
> > > This bug was from ad72b3bea744b4db01c89af0f86f3e8920d354df
> > > 
> > > Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> > > Cc: Ingo Molnar <mingo@redhat.com>
> > > Cc: Tejun Heo <tj@kernel.org>
> > > Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
> > > Cc: "David S. Miller" <davem@davemloft.net>
> > 
> > Oops,
> > 
> > Acked-by: Tejun Heo <tj@kernel.org>
> 
> Since you pushed the original commit, mind pushing this fix to Linus too?

I see Linus applied it out of email, so never mind.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-04-19  7:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-18  9:33 [PATCH -tip ] [BUGFIX] kprobes: Fix a double lock bug of kprobe_mutex Masami Hiramatsu
2013-04-18 15:49 ` Ananth N Mavinakayanahalli
2013-04-18 18:17 ` Tejun Heo
2013-04-19  7:22   ` Ingo Molnar
2013-04-19  7:25     ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox