mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pid: Add the judgment of whether ns is NULL in the find_pid_ns
@ 2023-07-13  7:17 Xuewen Yan
  2023-07-19 11:46 ` Xuewen Yan
  2023-07-25  8:26 ` Christian Brauner
  0 siblings, 2 replies; 8+ messages in thread
From: Xuewen Yan @ 2023-07-13  7:17 UTC (permalink / raw)
  To: brauner, jack, keescook, peterz, vincent.guittot
  Cc: linux-kernel, xuewen.yan, di.shen

There is no the judgment of whether namspace is NULL in find_pid_ns.
But there is a corner case when ns is null, for example: if user
call find_get_pid when current is in exiting, the following stack would
set thread_id be null:
release_task
    __exit_signal(p);
        __unhash_process(tsk, group_dead);
              detach_pid(p, PIDTYPE_PID);
                  __change_pid(task, type, NULL);

If user call find_get_pid at now, in find_vpid function, the
task_active_pid_ns would return NULL. As a result, it would be
error when access the ns in find_pid_ns.

So add the judgment of whether ns is NULL in the find_pid_ns to
prevent this case happen.

Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
---
 kernel/pid.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/pid.c b/kernel/pid.c
index 6a1d23a11026..d4a9cb6f3eb9 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -308,6 +308,9 @@ void disable_pid_allocation(struct pid_namespace *ns)
 
 struct pid *find_pid_ns(int nr, struct pid_namespace *ns)
 {
+	if (!ns)
+		return NULL;
+
 	return idr_find(&ns->idr, nr);
 }
 EXPORT_SYMBOL_GPL(find_pid_ns);
-- 
2.25.1


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

end of thread, other threads:[~2023-07-27  1:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-13  7:17 [PATCH] pid: Add the judgment of whether ns is NULL in the find_pid_ns Xuewen Yan
2023-07-19 11:46 ` Xuewen Yan
2023-07-25  8:26 ` Christian Brauner
2023-07-25 12:24   ` Xuewen Yan
2023-07-25 12:47     ` Christian Brauner
2023-07-26  1:23       ` Xuewen Yan
2023-07-26  9:25         ` Christian Brauner
2023-07-27  1:21           ` Xuewen Yan

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®