Skip to contentSkip to conversation

Fix: tracepoint: use after rcu free

PATCH In review Mathieu Desnoyers 2 participants 5 messages May 8, 2014 Tracing

lore
Share & tools
lore

Mathieu Desnoyers

author reviewer
#0 lore raw

PATCH 1/1 Fix: tracepoint: use after rcu free

commit de7b2973903c6cc50b31ee5682a69b2219b9919d

Author: Mathieu Desnoyers <[email protected]>
Date:   Tue Apr 8 17:26:21 2014 -0400

tracepoint: Use struct pointer instead of name hash for reg/unreg tracepoints

introduces a use after free by calling release_probes on the old struct tracepoint array before the newly allocated array is published with rcu_assign_pointer. There is a race window where tracepoints (RCU readers) can perform a "use-after-grace-period-after-free", which shows up as a GPF in stress-tests.

---
 kernel/tracepoint.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/tracepoint.c +2 -2
index ac5b23c..6620e58 100644
@@ -188,7 +188,6 @@ static int tracepoint_add_func(struct tracepoint *tp,
 		WARN_ON_ONCE(1);
 		return PTR_ERR(old);
 	}
-	release_probes(old);
 
 	/*
 	 * rcu_assign_pointer has a smp_wmb() which makes sure that the new
@@ -200,6 +199,7 @@ static int tracepoint_add_func(struct tracepoint *tp,
 	rcu_assign_pointer(tp->funcs, tp_funcs);
 	if (!static_key_enabled(&tp->key))
 		static_key_slow_inc(&tp->key);
+	release_probes(old);
 	return 0;
 }
 
@@ -221,7 +221,6 @@ static int tracepoint_remove_func(struct tracepoint *tp,
 		WARN_ON_ONCE(1);
 		return PTR_ERR(old);
 	}
-	release_probes(old);
 
 	if (!tp_funcs) {
 		/* Removed last function */
@@ -232,6 +231,7 @@ static int tracepoint_remove_func(struct tracepoint *tp,
 			static_key_slow_dec(&tp->key);
 	}
 	rcu_assign_pointer(tp->funcs, tp_funcs);
+	release_probes(old);
 	return 0;
 }
 
Signature · 1 line
1.7.10.4
maintainer
#1 lore raw
Quoted 3 lines · On Thu, 8 May 2014 07:47:49 -0400 Mathieu Desnoyers…

commit de7b2973903c6cc50b31ee5682a69b2219b9919d

Author: Mathieu Desnoyers <[email protected]>
Date:   Tue Apr 8 17:26:21 2014 -0400

Hi Mathieu,

Thanks for the quick fix.

Quoted 4 lines

tracepoint: Use struct pointer instead of name hash for reg/unreg tracepoints

introduces a use after free by calling release_probes on the old struct

Note when talking about commits already in mainline, use the first 12 characters of the commit sha1 followed by the subject. Like so:

Commit de7b2973903c "tracepoint: Use struct pointer instead of name hash for reg/unreg tracepoints" introduces a use after free ...

Quoted 6 lines

tracepoint array before the newly allocated array is published with rcu_assign_pointer. There is a race window where tracepoints (RCU readers) can perform a "use-after-grace-period-after-free", which shows up as a GPF in stress-tests.

Also, Link tags need to point to lkml.kernel.org.

Which is "lkml.kernel.org/r/" followed by the Message-ID.

We can also include a (even though it's redundant)

Fixes de7b2973903c "tracepoint: Use struct pointer instead of name hash for reg/unreg tracepoints"

I'll update the change log to reflect my comments and then pull this into my urgent branch and start testing it.

Thanks,

-- Steve

Quoted 45 lines
CC Steven Rostedt <[email protected]>
CC Sasha Levin <[email protected]>
CC Oleg Nesterov <[email protected]>
CC Dave Jones <[email protected]>
---
 kernel/tracepoint.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/tracepoint.c +2 -2
index ac5b23c..6620e58 100644
@@ -188,7 +188,6 @@ static int tracepoint_add_func(struct tracepoint *tp,
 		WARN_ON_ONCE(1);
 		return PTR_ERR(old);
 	}
-	release_probes(old);
 
 	/*
 	 * rcu_assign_pointer has a smp_wmb() which makes sure that the new
@@ -200,6 +199,7 @@ static int tracepoint_add_func(struct tracepoint *tp,
 	rcu_assign_pointer(tp->funcs, tp_funcs);
 	if (!static_key_enabled(&tp->key))
 		static_key_slow_inc(&tp->key);
+	release_probes(old);
 	return 0;
 }
 
@@ -221,7 +221,6 @@ static int tracepoint_remove_func(struct tracepoint *tp,
 		WARN_ON_ONCE(1);
 		return PTR_ERR(old);
 	}
-	release_probes(old);
 
 	if (!tp_funcs) {
 		/* Removed last function */
@@ -232,6 +231,7 @@ static int tracepoint_remove_func(struct tracepoint *tp,
 			static_key_slow_dec(&tp->key);
 	}
 	rcu_assign_pointer(tp->funcs, tp_funcs);
+	release_probes(old);
 	return 0;
 }
 
author reviewer
#2 lore raw

----- Original Message -----

Quoted 23 lines

From: "Steven Rostedt" <[email protected]>
To: "Mathieu Desnoyers" <[email protected]>
Cc: [email protected], "Sasha Levin" <[email protected]>, "Oleg Nesterov" <[email protected]>, "Dave Jones" <[email protected]>
Sent: Thursday, May 8, 2014 9:05:20 AM
Subject: Re: [PATCH] Fix: tracepoint: use after rcu free

Quoted 3 lines · On Thu, 8 May 2014 07:47:49 -0400 Mathieu Desnoyers…

commit de7b2973903c6cc50b31ee5682a69b2219b9919d

Author: Mathieu Desnoyers <[email protected]>
Date:   Tue Apr 8 17:26:21 2014 -0400

Hi Mathieu,

Thanks for the quick fix.

Quoted 4 lines

tracepoint: Use struct pointer instead of name hash for reg/unreg tracepoints

Quoted 7 lines
Quoted 1 line

introduces a use after free by calling release_probes on the old struct

Note when talking about commits already in mainline, use the first 12 characters of the commit sha1 followed by the subject. Like so:

Commit de7b2973903c "tracepoint: Use struct pointer instead of name hash for reg/unreg tracepoints" introduces a use after free ...

OK, will do.

Quoted 7 lines
Quoted 7 lines

tracepoint array before the newly allocated array is published with rcu_assign_pointer. There is a race window where tracepoints (RCU readers) can perform a "use-after-grace-period-after-free", which shows up as a GPF in stress-tests.

Quoted 7 lines
Quoted 1 line

Also, Link tags need to point to lkml.kernel.org.

Which is "lkml.kernel.org/r/" followed by the Message-ID.

OK

Quoted 5 lines

We can also include a (even though it's redundant)

Fixes de7b2973903c "tracepoint: Use struct pointer instead of name hash for

reg/unreg tracepoints"

Thanks for the pointers, I'll keep those in mind for my next patches.

Quoted 3 lines

I'll update the change log to reflect my comments and then pull this into my urgent branch and start testing it.

Thanks!

Mathieu

Quoted 54 lines

Thanks,

-- Steve

Quoted 47 lines
CC Steven Rostedt <[email protected]>
CC Sasha Levin <[email protected]>
CC Oleg Nesterov <[email protected]>
CC Dave Jones <[email protected]>
---
 kernel/tracepoint.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/tracepoint.c +1 -2
index ac5b23c..6620e58 100644
@@ -188,7 +188,6 @@ static int tracepoint_add_func(struct tracepoint *tp,
 		WARN_ON_ONCE(1);
 		return PTR_ERR(old);
 	}
-	release_probes(old);
 
 	/*
 	 * rcu_assign_pointer has a smp_wmb() which makes sure that the new
@@ -200,6 +199,7 @@ static int tracepoint_add_func(struct tracepoint *tp,
 	rcu_assign_pointer(tp->funcs, tp_funcs);
 	if (!static_key_enabled(&tp->key))
 		static_key_slow_inc(&tp->key);
+	release_probes(old);
 	return 0;
 }
 
@@ -221,7 +221,6 @@ static int tracepoint_remove_func(struct tracepoint
 *tp,
 		WARN_ON_ONCE(1);
 		return PTR_ERR(old);
 	}
-	release_probes(old);
 
 	if (!tp_funcs) {
kernel/tracepoint.c +1 -0
 		/* Removed last function */
@@ -232,6 +231,7 @@ static int tracepoint_remove_func(struct tracepoint
 *tp,
 			static_key_slow_dec(&tp->key);
 	}
 	rcu_assign_pointer(tp->funcs, tp_funcs);
+	release_probes(old);
 	return 0;
 }
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
maintainer
#3 lore raw
Quoted 7 lines · On Thu, 8 May 2014 13:08:25 +0000 (UTC) Mathieu Desnoyers…
Quoted 5 lines

We can also include a (even though it's redundant)

Fixes de7b2973903c "tracepoint: Use struct pointer instead of name hash for

reg/unreg tracepoints"

Thanks for the pointers, I'll keep those in mind for my next patches.

Oh, one more thing I keep forgetting to mention to you. Your subject lines :-)

I converted it to be:

tracepoint: Fix use of tracepoint funcs after rcu free

only the subsystem tag should be used. Not a "Fix" tag. But the "Fix" may be used in the subject itself. Also, I've been told that Linus prefers to have the subject written more like a sentence and the first character capitalized.

-- Steve

author reviewer
#4 lore raw

----- Original Message -----

Quoted 22 lines

From: "Steven Rostedt" <[email protected]>
To: "Mathieu Desnoyers" <[email protected]>
Cc: [email protected], "Sasha Levin" <[email protected]>, "Oleg Nesterov" <[email protected]>, "Dave Jones" <[email protected]>
Sent: Thursday, May 8, 2014 9:15:29 AM
Subject: Re: [PATCH] Fix: tracepoint: use after rcu free

Quoted 8 lines · On Thu, 8 May 2014 13:08:25 +0000 (UTC) Mathieu Desnoyers…
Quoted 6 lines

We can also include a (even though it's redundant)

Fixes de7b2973903c "tracepoint: Use struct pointer instead of name hash

for
reg/unreg tracepoints"

Thanks for the pointers, I'll keep those in mind for my next patches.

Oh, one more thing I keep forgetting to mention to you. Your subject lines :-)

Quoted 8 lines

I converted it to be:

tracepoint: Fix use of tracepoint funcs after rcu free

only the subsystem tag should be used. Not a "Fix" tag. But the "Fix" may be used in the subject itself. Also, I've been told that Linus prefers to have the subject written more like a sentence and the first character capitalized.

OK, I'm taking notes for next time.

Thanks!

Mathieu

Quoted 3 lines

-- Steve

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com