Skip to contentSkip to conversation

livepatch: RCU protect struct klp_func all the time when used in klp_ftrace_handler()

PATCH Applied Petr Mladek 3 participants 4 messages Feb 18, 2015 – Feb 22, 2015 Live patching

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 livepatch: RCU protect struct klp_func all the time when used in klp_ftrace_handler()

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

---
 kernel/livepatch/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/livepatch/core.c +3 -3
index ff7f47d026ac..cde66192e20e 100644
@@ -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)
Signature · 1 line
1.8.5.6
#1 lore raw
Quoted 15 lines · Petr Mladek

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

---
 kernel/livepatch/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/livepatch/core.c +0 -0
index ff7f47d026ac..cde66192e20e 100644
@@ -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,

kernel/livepatch/core.c static void notrace klp_ftrace_handler(unsigned long ip, · line 322

Quoted 10 lines
kernel/livepatch/core.c +3 -3
 				      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,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#2 lore raw
Quoted 24 lines · Jiri Kosina
Quoted 22 lines · Petr Mladek

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

---
 kernel/livepatch/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/livepatch/core.c +1 -3
index ff7f47d026ac..cde66192e20e 100644
@@ -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;
 
Quoted 8 lines

kernel/livepatch/core.c static void notrace klp_ftrace_handler(unsigned long ip, · line 322

Quoted 3 lines
kernel/livepatch/core.c +2 -0
 	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?

Signature · 1 line
Josh