diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h index 49538b172483..9829e74c9bd7 100644 --- a/include/linux/pid_namespace.h +++ b/include/linux/pid_namespace.h @@ -44,6 +44,7 @@ struct pid_namespace { kgid_t pid_gid; int hide_pid; int reboot; /* group exit code if this pidns was rebooted */ + bool pid1; struct ns_common ns; } __randomize_layout; diff --git a/kernel/pid.c b/kernel/pid.c index a7f38aff740a..c2af4d420e2a 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -199,6 +199,15 @@ struct pid *alloc_pid(struct pid_namespace *ns) goto out_free; } + + if (ns->pid1) { + if (nr != 1) { + printk("%s: pid %d\n", __func__, nr); + BUG(); + } + ns->pid1 = false; + } + pid->numbers[i].nr = nr; pid->numbers[i].ns = tmp; tmp = tmp->parent; diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 0b53eef7d34b..234bf7c2d53f 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -135,6 +135,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns ns->ucounts = ucounts; ns->pid_allocated = PIDNS_ADDING; INIT_WORK(&ns->proc_work, proc_cleanup_work); + ns->pid1 = true; return ns;