staticint pid_max_cb(void *data)
{ int fd, ret;
pid_t pid;
ret = mount("", "/", NULL, MS_PRIVATE | MS_REC, 0); if (ret) {
fprintf(stderr, "%m - Failed to make rootfs private mount\n"); return -1;
}
umount2("/proc", MNT_DETACH);
ret = mount("proc", "/proc", "proc", 0, NULL); if (ret) {
fprintf(stderr, "%m - Failed to mount proc\n"); return -1;
}
fd = open("/proc/sys/kernel/pid_max", O_RDWR | O_CLOEXEC | O_NOCTTY); if (fd < 0) {
fprintf(stderr, "%m - Failed to open pid_max\n"); return -1;
}
ret = write(fd, "500", sizeof("500") - 1); if (ret < 0) {
fprintf(stderr, "%m - Failed to write pid_max\n"); return -1;
}
for (int i = 0; i < 501; i++) {
pid = fork(); if (pid == 0) exit(EXIT_SUCCESS);
wait_for_pid(pid); if (pid > 500) {
fprintf(stderr, "Managed to create pid number beyond limit\n"); return -1;
}
}
return 0;
}
staticint pid_max_nested_inner(void *data)
{ int fret = -1;
pid_t pids[2]; int fd, i, ret;
ret = mount("", "/", NULL, MS_PRIVATE | MS_REC, 0); if (ret) {
fprintf(stderr, "%m - Failed to make rootfs private mount\n"); return fret;
}
umount2("/proc", MNT_DETACH);
ret = mount("proc", "/proc", "proc", 0, NULL); if (ret) {
fprintf(stderr, "%m - Failed to mount proc\n"); return fret;
}
fd = open("/proc/sys/kernel/pid_max", O_RDWR | O_CLOEXEC | O_NOCTTY); if (fd < 0) {
fprintf(stderr, "%m - Failed to open pid_max\n"); return fret;
}
ret = write(fd, "500", sizeof("500") - 1);
close(fd); if (ret < 0) {
fprintf(stderr, "%m - Failed to write pid_max\n"); return fret;
}
pids[0] = fork(); if (pids[0] < 0) {
fprintf(stderr, "Failed to create first new process\n"); return fret;
}
if (pids[0] == 0) exit(EXIT_SUCCESS);
pids[1] = fork();
wait_for_pid(pids[0]); if (pids[1] >= 0) { if (pids[1] == 0) exit(EXIT_SUCCESS);
wait_for_pid(pids[1]);
fprintf(stderr, "Managed to create process even though ancestor pid namespace had a limit\n"); return fret;
}
/* Now make sure that we wrap pids at 400. */ for (i = 0; i < 510; i++) {
pid_t pid;
pid = fork(); if (pid < 0) return fret;
if (pid == 0) exit(EXIT_SUCCESS);
wait_for_pid(pid); if (pid >= 500) {
fprintf(stderr, "Managed to create process with pid %d beyond configured limit\n", pid); return fret;
}
}
return 0;
}
staticint pid_max_nested_outer(void *data)
{ int fret = -1, nr_procs = 400;
pid_t pids[1000]; int fd, i, ret;
pid_t pid;
ret = mount("", "/", NULL, MS_PRIVATE | MS_REC, 0); if (ret) {
fprintf(stderr, "%m - Failed to make rootfs private mount\n"); return fret;
}
umount2("/proc", MNT_DETACH);
ret = mount("proc", "/proc", "proc", 0, NULL); if (ret) {
fprintf(stderr, "%m - Failed to mount proc\n"); return fret;
}
fd = open("/proc/sys/kernel/pid_max", O_RDWR | O_CLOEXEC | O_NOCTTY); if (fd < 0) {
fprintf(stderr, "%m - Failed to open pid_max\n"); return fret;
}
ret = write(fd, "400", sizeof("400") - 1);
close(fd); if (ret < 0) {
fprintf(stderr, "%m - Failed to write pid_max\n"); return fret;
}
/* * Create 397 processes. This leaves room for do_clone() (398) and * one more 399. So creating another process needs to fail.
*/ for (nr_procs = 0; nr_procs < 396; nr_procs++) {
pid = fork(); if (pid < 0) goto reap;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.