提交 579035dc 编写于 作者: A Andrew Vagin 提交者: Linus Torvalds

pid-namespace: limit value of ns_last_pid to (0, max_pid)

The kernel doesn't check the pid for negative values, so if you try to
write -2 to /proc/sys/kernel/ns_last_pid, you will get a kernel panic.

The crash happens because the next pid is -1, and alloc_pidmap() will
try to access to a nonexistent pidmap.

  map = &pid_ns->pidmap[pid/BITS_PER_PAGE];
Signed-off-by: NAndrew Vagin <avagin@openvz.org>
Acked-by: NCyrill Gorcunov <gorcunov@openvz.org>
Acked-by: NOleg Nesterov <oleg@redhat.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 35c448a8
...@@ -232,15 +232,19 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write, ...@@ -232,15 +232,19 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
*/ */
tmp.data = &current->nsproxy->pid_ns->last_pid; tmp.data = &current->nsproxy->pid_ns->last_pid;
return proc_dointvec(&tmp, write, buffer, lenp, ppos); return proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
} }
extern int pid_max;
static int zero = 0;
static struct ctl_table pid_ns_ctl_table[] = { static struct ctl_table pid_ns_ctl_table[] = {
{ {
.procname = "ns_last_pid", .procname = "ns_last_pid",
.maxlen = sizeof(int), .maxlen = sizeof(int),
.mode = 0666, /* permissions are checked in the handler */ .mode = 0666, /* permissions are checked in the handler */
.proc_handler = pid_ns_ctl_handler, .proc_handler = pid_ns_ctl_handler,
.extra1 = &zero,
.extra2 = &pid_max,
}, },
{ } { }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册