All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] livepatch: RCU protect struct klp_func all the time when used in klp_ftrace_handler()
@ 2015-02-18 17:02 Petr Mladek
  2015-02-20 23:29 ` Jiri Kosina
  2015-02-22 22:03 ` Jiri Kosina
  0 siblings, 2 replies; 4+ messages in thread
From: Petr Mladek @ 2015-02-18 17:02 UTC (permalink / raw)
  To: jpoimboe, sjenning, jkosina, vojtech
  Cc: masami.hiramatsu.pt, mbenes, live-patching, linux-kernel, Petr Mladek

func->new_func has been accessed after rcu_read_unlock() in klp_ftrace_handler()
and therefore the access was not protected.

Signed-off-by: Petr Mladek <pmladek@suse.cz>
---
 kernel/livepatch/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index ff7f47d026ac..cde66192e20e 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -314,12 +314,12 @@ static void notrace klp_ftrace_handler(unsigned long ip,
 	rcu_read_lock();
 	func = list_first_or_null_rcu(&ops->func_stack, struct klp_func,
 				      stack_node);
-	rcu_read_unlock();
-
 	if (WARN_ON_ONCE(!func))
-		return;
+		goto unlock;
 
 	klp_arch_set_pc(regs, (unsigned long)func->new_func);
+unlock:
+	rcu_read_unlock();
 }
 
 static int klp_disable_func(struct klp_func *func)
-- 
1.8.5.6


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

* Re: [PATCH] livepatch: RCU protect struct klp_func all the time when used in klp_ftrace_handler()
  2015-02-18 17:02 [PATCH] livepatch: RCU protect struct klp_func all the time when used in klp_ftrace_handler() Petr Mladek
@ 2015-02-20 23:29 ` Jiri Kosina
  2015-02-21  3:52   ` Josh Poimboeuf
  2015-02-22 22:03 ` Jiri Kosina
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Kosina @ 2015-02-20 23:29 UTC (permalink / raw)
  To: Petr Mladek
  Cc: jpoimboe, sjenning, vojtech, masami.hiramatsu.pt, mbenes,
	live-patching, linux-kernel

On Wed, 18 Feb 2015, Petr Mladek wrote:

> func->new_func has been accessed after rcu_read_unlock() in klp_ftrace_handler()
> and therefore the access was not protected.
> 
> Signed-off-by: Petr Mladek <pmladek@suse.cz>
> ---
>  kernel/livepatch/core.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> index ff7f47d026ac..cde66192e20e 100644
> --- a/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c
> @@ -314,12 +314,12 @@ static void notrace klp_ftrace_handler(unsigned long ip,
>  	rcu_read_lock();
>  	func = list_first_or_null_rcu(&ops->func_stack, struct klp_func,
>  				      stack_node);
> -	rcu_read_unlock();
> -
>  	if (WARN_ON_ONCE(!func))
> -		return;
> +		goto unlock;
>  
>  	klp_arch_set_pc(regs, (unsigned long)func->new_func);
> +unlock:
> +	rcu_read_unlock();

This can't hurt, even though the only scenario where this could in theory 
trigger as a bug (module removal) is non-issue now.

But I'd like to take it nevertheless ... Seth, Josh?

Thanks,

-- 
Jiri Kosina
SUSE Labs

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

* Re: [PATCH] livepatch: RCU protect struct klp_func all the time when used in klp_ftrace_handler()
  2015-02-20 23:29 ` Jiri Kosina
@ 2015-02-21  3:52   ` Josh Poimboeuf
  0 siblings, 0 replies; 4+ messages in thread
From: Josh Poimboeuf @ 2015-02-21  3:52 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: Petr Mladek, sjenning, vojtech, masami.hiramatsu.pt, mbenes,
	live-patching, linux-kernel

On Sat, Feb 21, 2015 at 12:29:30AM +0100, Jiri Kosina wrote:
> On Wed, 18 Feb 2015, Petr Mladek wrote:
> 
> > func->new_func has been accessed after rcu_read_unlock() in klp_ftrace_handler()
> > and therefore the access was not protected.
> > 
> > Signed-off-by: Petr Mladek <pmladek@suse.cz>
> > ---
> >  kernel/livepatch/core.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> > index ff7f47d026ac..cde66192e20e 100644
> > --- a/kernel/livepatch/core.c
> > +++ b/kernel/livepatch/core.c
> > @@ -314,12 +314,12 @@ static void notrace klp_ftrace_handler(unsigned long ip,
> >  	rcu_read_lock();
> >  	func = list_first_or_null_rcu(&ops->func_stack, struct klp_func,
> >  				      stack_node);
> > -	rcu_read_unlock();
> > -
> >  	if (WARN_ON_ONCE(!func))
> > -		return;
> > +		goto unlock;
> >  
> >  	klp_arch_set_pc(regs, (unsigned long)func->new_func);
> > +unlock:
> > +	rcu_read_unlock();
> 
> This can't hurt, even though the only scenario where this could in theory 
> trigger as a bug (module removal) is non-issue now.
> 
> But I'd like to take it nevertheless ... Seth, Josh?

Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>

-- 
Josh

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

* Re: [PATCH] livepatch: RCU protect struct klp_func all the time when used in klp_ftrace_handler()
  2015-02-18 17:02 [PATCH] livepatch: RCU protect struct klp_func all the time when used in klp_ftrace_handler() Petr Mladek
  2015-02-20 23:29 ` Jiri Kosina
@ 2015-02-22 22:03 ` Jiri Kosina
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2015-02-22 22:03 UTC (permalink / raw)
  To: Petr Mladek
  Cc: jpoimboe, sjenning, vojtech, masami.hiramatsu.pt, mbenes,
	live-patching, linux-kernel

On Wed, 18 Feb 2015, Petr Mladek wrote:

> func->new_func has been accessed after rcu_read_unlock() in klp_ftrace_handler()
> and therefore the access was not protected.
> 
> Signed-off-by: Petr Mladek <pmladek@suse.cz>

Applied to for-3.20/upstream-fixes, thanks.

-- 
Jiri Kosina
SUSE Labs

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

end of thread, other threads:[~2015-02-22 22:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-18 17:02 [PATCH] livepatch: RCU protect struct klp_func all the time when used in klp_ftrace_handler() Petr Mladek
2015-02-20 23:29 ` Jiri Kosina
2015-02-21  3:52   ` Josh Poimboeuf
2015-02-22 22:03 ` Jiri Kosina

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.