staticvoid ptrace_child(void)
{ int ret; /* Calling os_getpid because some libcs cached getpid incorrectly */ int pid = os_getpid(), ppid = getppid(); int sc_result;
/* * This syscall will be intercepted by the parent. Don't call more than * once, please.
*/
sc_result = os_getpid();
if (sc_result == pid) /* Nothing modified by the parent, we are running normally. */
ret = 1; elseif (sc_result == ppid) /* * Expected in check_ptrace and check_sysemu when they succeed * in modifying the stack frame
*/
ret = 0; else /* Serious trouble! This could be caused by a bug in host 2.6 * SKAS3/2.6 patch before release -V6, together with a bug in * the UML code itself.
*/
ret = 2;
/* Stow away the location of the mcontext in the stack */
seccomp_test_stub_data->mctx_offset = (unsignedlong)&uc->uc_mcontext -
(unsignedlong)&seccomp_test_stub_data->sigstack[0];
/* Prevent libc from clearing memory (mctx_offset in particular) */
syscall(__NR_exit, 0);
}
staticbool __init init_seccomp(void)
{ int pid; int status; int n; unsignedlong sp;
/* * We check that we can install a seccomp filter and then exit(0) * from a trapped syscall. * * Note that we cannot verify that no seccomp filter already exists * for a syscall that results in the process/thread to be killed.
*/
os_info("Checking that seccomp filters can be installed...");
/* Use the syscall data area as stack, we just need something */
sp = (unsignedlong)&seccomp_test_stub_data->syscall_data + sizeof(seccomp_test_stub_data->syscall_data) - sizeof(void *);
pid = clone(seccomp_helper, (void *)sp, CLONE_VFORK | CLONE_VM, NULL);
if (pid < 0)
fatal_perror("check_seccomp : clone failed");
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { struct uml_pt_regs *regs; unsignedlong fp_size; int r;
/* Fill in the host_fp_size from the mcontext. */
regs = calloc(1, sizeof(struct uml_pt_regs));
get_stub_state(regs, seccomp_test_stub_data, &fp_size);
host_fp_size = fp_size;
free(regs);
/* Repeat with the correct size */
regs = calloc(1, sizeof(struct uml_pt_regs) + host_fp_size);
r = get_stub_state(regs, seccomp_test_stub_data, NULL);
/* Store as the default startup registers */
exec_fp_regs = malloc(host_fp_size);
memcpy(exec_regs, regs->gp, sizeof(exec_regs));
memcpy(exec_fp_regs, regs->fp, host_fp_size);
__uml_setup("seccomp=", uml_seccomp_config, "seccomp=\n" " Configure whether or not SECCOMP is used. With SECCOMP, userspace\n" " processes work collaboratively with the kernel instead of being\n" " traced using ptrace. All syscalls from the application are caught and\n" " redirected using a signal. This signal handler in turn is permitted to\n" " do the selected set of syscalls to communicate with the UML kernel and\n" " do the required memory management.\n" "\n" " This method is overall faster than the ptrace based userspace, primarily\n" " because it reduces the number of context switches for (minor) page faults.\n" "\n" " However, the SECCOMP filter is not (yet) restrictive enough to prevent\n" " userspace from reading and writing all physical memory. Userspace\n" " processes could also trick the stub into disabling SIGALRM which\n" " prevents it from being interrupted for scheduling purposes.\n" "\n" " This is insecure and should only be used with a trusted userspace\n\n"
);
void __init os_early_checks(void)
{ int pid;
/* Print out the core dump limits early */
check_coredump_limit();
/* Need to check this early because mmapping happens before the * kernel is running.
*/
check_tmpexec();
if (seccomp_config) { if (init_seccomp()) {
using_seccomp = 1; return;
}
if (seccomp_config == 2)
fatal("SECCOMP userspace requested but not functional!\n");
}
using_seccomp = 0;
check_ptrace();
pid = start_ptraced_child(); if (init_pid_registers(pid))
fatal("Failed to initialize default registers");
stop_ptraced_child(pid, 1);
}
int __init parse_iomem(char *str, int *add)
{ struct iomem_region *new; struct stat64 buf; char *file, *driver; int fd, size;
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.