Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Pid namespaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *    (C) 2007 Pavel Emelyanov <xemul@openvz.org>, OpenVZ, SWsoft Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *    (C) 2007 Sukadev Bhattiprolu <sukadev@us.ibm.com>, IBM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *     Many thanks to Oleg Nesterov for comments and help
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/pid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/pid_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/user_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/cred.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/acct.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/proc_ns.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static DEFINE_MUTEX(pid_caches_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static struct kmem_cache *pid_ns_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /* Write once array, filled from the beginning. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static struct kmem_cache *pid_cache[MAX_PID_NS_LEVEL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * creates the kmem cache to allocate pids from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * @level: pid namespace level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static struct kmem_cache *create_pid_cachep(unsigned int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	/* Level 0 is init_pid_ns.pid_cachep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct kmem_cache **pkc = &pid_cache[level - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct kmem_cache *kc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	char name[4 + 10 + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	kc = READ_ONCE(*pkc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (kc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		return kc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	snprintf(name, sizeof(name), "pid_%u", level + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	len = sizeof(struct pid) + level * sizeof(struct upid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	mutex_lock(&pid_caches_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	/* Name collision forces to do allocation under mutex. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (!*pkc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		*pkc = kmem_cache_create(name, len, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 					 SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	mutex_unlock(&pid_caches_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	/* current can fail, but someone else can succeed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	return READ_ONCE(*pkc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static struct ucounts *inc_pid_namespaces(struct user_namespace *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	return inc_ucount(ns, current_euid(), UCOUNT_PID_NAMESPACES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static void dec_pid_namespaces(struct ucounts *ucounts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	dec_ucount(ucounts, UCOUNT_PID_NAMESPACES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct pid_namespace *parent_pid_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct pid_namespace *ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	unsigned int level = parent_pid_ns->level + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct ucounts *ucounts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (!in_userns(parent_pid_ns->user_ns, user_ns))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	err = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (level > MAX_PID_NS_LEVEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	ucounts = inc_pid_namespaces(user_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (!ucounts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	ns = kmem_cache_zalloc(pid_ns_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (ns == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		goto out_dec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	idr_init(&ns->idr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	ns->pid_cachep = create_pid_cachep(level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (ns->pid_cachep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		goto out_free_idr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	err = ns_alloc_inum(&ns->ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		goto out_free_idr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	ns->ns.ops = &pidns_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	kref_init(&ns->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	ns->level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	ns->parent = get_pid_ns(parent_pid_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	ns->user_ns = get_user_ns(user_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	ns->ucounts = ucounts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	ns->pid_allocated = PIDNS_ADDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) out_free_idr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	idr_destroy(&ns->idr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	kmem_cache_free(pid_ns_cachep, ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) out_dec:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	dec_pid_namespaces(ucounts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static void delayed_free_pidns(struct rcu_head *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct pid_namespace *ns = container_of(p, struct pid_namespace, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	dec_pid_namespaces(ns->ucounts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	put_user_ns(ns->user_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	kmem_cache_free(pid_ns_cachep, ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static void destroy_pid_namespace(struct pid_namespace *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	ns_free_inum(&ns->ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	idr_destroy(&ns->idr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	call_rcu(&ns->rcu, delayed_free_pidns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct pid_namespace *copy_pid_ns(unsigned long flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct user_namespace *user_ns, struct pid_namespace *old_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (!(flags & CLONE_NEWPID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		return get_pid_ns(old_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (task_active_pid_ns(current) != old_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	return create_pid_namespace(user_ns, old_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static void free_pid_ns(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct pid_namespace *ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	ns = container_of(kref, struct pid_namespace, kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	destroy_pid_namespace(ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) void put_pid_ns(struct pid_namespace *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct pid_namespace *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	while (ns != &init_pid_ns) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		parent = ns->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (!kref_put(&ns->kref, free_pid_ns))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		ns = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) EXPORT_SYMBOL_GPL(put_pid_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) void zap_pid_ns_processes(struct pid_namespace *pid_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	int nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct task_struct *task, *me = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	int init_pids = thread_group_leader(me) ? 1 : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct pid *pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	/* Don't allow any more processes into the pid namespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	disable_pid_allocation(pid_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	 * Ignore SIGCHLD causing any terminated children to autoreap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * This speeds up the namespace shutdown, plus see the comment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 * below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	spin_lock_irq(&me->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	me->sighand->action[SIGCHLD - 1].sa.sa_handler = SIG_IGN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	spin_unlock_irq(&me->sighand->siglock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	 * The last thread in the cgroup-init thread group is terminating.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	 * Find remaining pid_ts in the namespace, signal and wait for them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	 * to exit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	 * Note:  This signals each threads in the namespace - even those that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	 * 	  belong to the same thread group, To avoid this, we would have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	 * 	  to walk the entire tasklist looking a processes in this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 * 	  namespace, but that could be unnecessarily expensive if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	 * 	  pid namespace has just a few processes. Or we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	 * 	  maintain a tasklist for each pid namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	read_lock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	nr = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	idr_for_each_entry_continue(&pid_ns->idr, pid, nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		task = pid_task(pid, PIDTYPE_PID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		if (task && !__fatal_signal_pending(task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			group_send_sig_info(SIGKILL, SEND_SIG_PRIV, task, PIDTYPE_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	read_unlock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	 * Reap the EXIT_ZOMBIE children we had before we ignored SIGCHLD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	 * kernel_wait4() will also block until our children traced from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	 * parent namespace are detached and become EXIT_DEAD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		clear_thread_flag(TIF_SIGPENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		rc = kernel_wait4(-1, NULL, __WALL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	} while (rc != -ECHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	 * kernel_wait4() misses EXIT_DEAD children, and EXIT_ZOMBIE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	 * process whose parents processes are outside of the pid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	 * namespace.  Such processes are created with setns()+fork().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	 * If those EXIT_ZOMBIE processes are not reaped by their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	 * parents before their parents exit, they will be reparented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	 * to pid_ns->child_reaper.  Thus pidns->child_reaper needs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	 * stay valid until they all go away.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	 * The code relies on the pid_ns->child_reaper ignoring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	 * SIGCHILD to cause those EXIT_ZOMBIE processes to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	 * autoreaped if reparented.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	 * Semantically it is also desirable to wait for EXIT_ZOMBIE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	 * processes before allowing the child_reaper to be reaped, as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	 * that gives the invariant that when the init process of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	 * pid namespace is reaped all of the processes in the pid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	 * namespace are gone.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	 * Once all of the other tasks are gone from the pid_namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 * free_pid() will awaken this task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		if (pid_ns->pid_allocated == init_pids)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	__set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (pid_ns->reboot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		current->signal->group_exit_code = pid_ns->reboot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	acct_exit_ns(pid_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #ifdef CONFIG_CHECKPOINT_RESTORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int pid_ns_ctl_handler(struct ctl_table *table, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		void *buffer, size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	struct pid_namespace *pid_ns = task_active_pid_ns(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	struct ctl_table tmp = *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	int ret, next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (write && !checkpoint_restore_ns_capable(pid_ns->user_ns))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	 * Writing directly to ns' last_pid field is OK, since this field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	 * is volatile in a living namespace anyway and a code writing to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	 * it should synchronize its usage with external means.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	next = idr_get_cursor(&pid_ns->idr) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	tmp.data = &next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (!ret && write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		idr_set_cursor(&pid_ns->idr, next + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) extern int pid_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static struct ctl_table pid_ns_ctl_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		.procname = "ns_last_pid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		.maxlen = sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		.mode = 0666, /* permissions are checked in the handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		.proc_handler = pid_ns_ctl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		.extra1 = SYSCTL_ZERO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		.extra2 = &pid_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static struct ctl_path kern_path[] = { { .procname = "kernel", }, { } };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #endif	/* CONFIG_CHECKPOINT_RESTORE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (pid_ns == &init_pid_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	case LINUX_REBOOT_CMD_RESTART2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	case LINUX_REBOOT_CMD_RESTART:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		pid_ns->reboot = SIGHUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	case LINUX_REBOOT_CMD_POWER_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	case LINUX_REBOOT_CMD_HALT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		pid_ns->reboot = SIGINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	read_lock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	send_sig(SIGKILL, pid_ns->child_reaper, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	read_unlock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	do_exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	/* Not reached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static inline struct pid_namespace *to_pid_ns(struct ns_common *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return container_of(ns, struct pid_namespace, ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static struct ns_common *pidns_get(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	struct pid_namespace *ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	ns = task_active_pid_ns(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		get_pid_ns(ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return ns ? &ns->ns : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static struct ns_common *pidns_for_children_get(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	struct pid_namespace *ns = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	task_lock(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (task->nsproxy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		ns = task->nsproxy->pid_ns_for_children;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		get_pid_ns(ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	task_unlock(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	if (ns) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		read_lock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		if (!ns->child_reaper) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 			put_pid_ns(ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			ns = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		read_unlock(&tasklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	return ns ? &ns->ns : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static void pidns_put(struct ns_common *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	put_pid_ns(to_pid_ns(ns));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static int pidns_install(struct nsset *nsset, struct ns_common *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	struct nsproxy *nsproxy = nsset->nsproxy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	struct pid_namespace *active = task_active_pid_ns(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	struct pid_namespace *ancestor, *new = to_pid_ns(ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (!ns_capable(new->user_ns, CAP_SYS_ADMIN) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	    !ns_capable(nsset->cred->user_ns, CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	 * Only allow entering the current active pid namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	 * or a child of the current active pid namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	 * This is required for fork to return a usable pid value and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	 * this maintains the property that processes and their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	 * children can not escape their current pid namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	if (new->level < active->level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	ancestor = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	while (ancestor->level > active->level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		ancestor = ancestor->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	if (ancestor != active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	put_pid_ns(nsproxy->pid_ns_for_children);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	nsproxy->pid_ns_for_children = get_pid_ns(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static struct ns_common *pidns_get_parent(struct ns_common *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	struct pid_namespace *active = task_active_pid_ns(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	struct pid_namespace *pid_ns, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	/* See if the parent is in the current namespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	pid_ns = p = to_pid_ns(ns)->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			return ERR_PTR(-EPERM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		if (p == active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		p = p->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	return &get_pid_ns(pid_ns)->ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static struct user_namespace *pidns_owner(struct ns_common *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	return to_pid_ns(ns)->user_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) const struct proc_ns_operations pidns_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	.name		= "pid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	.type		= CLONE_NEWPID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	.get		= pidns_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	.put		= pidns_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	.install	= pidns_install,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	.owner		= pidns_owner,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	.get_parent	= pidns_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) const struct proc_ns_operations pidns_for_children_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	.name		= "pid_for_children",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	.real_ns_name	= "pid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	.type		= CLONE_NEWPID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	.get		= pidns_for_children_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	.put		= pidns_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	.install	= pidns_install,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	.owner		= pidns_owner,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	.get_parent	= pidns_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static __init int pid_namespaces_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) #ifdef CONFIG_CHECKPOINT_RESTORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	register_sysctl_paths(kern_path, pid_ns_ctl_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) __initcall(pid_namespaces_init);