mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] um: protect find_task_by_pid_ns() with rcu lock
@ 2022-10-16 15:10 Dawei Li
  2022-10-16 17:52 ` Johannes Berg
  0 siblings, 1 reply; 2+ messages in thread
From: Dawei Li @ 2022-10-16 15:10 UTC (permalink / raw)
  To: richard, anton.ivanov, johannes; +Cc: linux-um, linux-kernel, Dawei Li

find_task_by_pid_ns() is safe if and only if it's under protection
from rcu read lock, implements the protection.

base-commit: 193cb8372424184dde28088a4230a5fed0afb0ad

Signed-off-by: Dawei Li <set_pte_at@outlook.com>
---
 arch/um/drivers/mconsole_kern.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index 5026e7b9adfe..6b80e766ae80 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -683,7 +683,10 @@ void mconsole_stack(struct mc_request *req)
 		return;
 	}
 
+	rcu_read_lock();
 	to = find_task_by_pid_ns(pid_requested, &init_pid_ns);
+	rcu_read_unlock();
+
 	if ((to == NULL) || (pid_requested == 0)) {
 		mconsole_reply(req, "Couldn't find that pid", 1, 0);
 		return;
-- 
2.25.1


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

* Re: [PATCH] um: protect find_task_by_pid_ns() with rcu lock
  2022-10-16 15:10 [PATCH] um: protect find_task_by_pid_ns() with rcu lock Dawei Li
@ 2022-10-16 17:52 ` Johannes Berg
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Berg @ 2022-10-16 17:52 UTC (permalink / raw)
  To: Dawei Li, richard, anton.ivanov; +Cc: linux-um, linux-kernel

On Sun, 2022-10-16 at 23:10 +0800, Dawei Li wrote:
> find_task_by_pid_ns() is safe if and only if it's under protection
> from rcu read lock, implements the protection.
> 
> base-commit: 193cb8372424184dde28088a4230a5fed0afb0ad
> 
> Signed-off-by: Dawei Li <set_pte_at@outlook.com>
> ---
>  arch/um/drivers/mconsole_kern.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
> index 5026e7b9adfe..6b80e766ae80 100644
> --- a/arch/um/drivers/mconsole_kern.c
> +++ b/arch/um/drivers/mconsole_kern.c
> @@ -683,7 +683,10 @@ void mconsole_stack(struct mc_request *req)
>  		return;
>  	}
>  
> +	rcu_read_lock();
>  	to = find_task_by_pid_ns(pid_requested, &init_pid_ns);
> +	rcu_read_unlock();
> +
>  	if ((to == NULL) || (pid_requested == 0)) {
>  		mconsole_reply(req, "Couldn't find that pid", 1, 0);
>  		return;

This can't be right - the 'to' pointer is used later in the code (not in
the existing context), so the protection, if needed, would have to
include the later "with_console()" call?

johannes

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

end of thread, other threads:[~2022-10-16 17:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-16 15:10 [PATCH] um: protect find_task_by_pid_ns() with rcu lock Dawei Li
2022-10-16 17:52 ` Johannes Berg

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

all inboxes | Powered by JetHome®