···173173 *174174 * Returns valid seccomp BPF response codes.175175 */176176-static u32 seccomp_run_filters(struct seccomp_data *sd)176176+static u32 seccomp_run_filters(const struct seccomp_data *sd)177177{178178 struct seccomp_data sd_local;179179 u32 ret = SECCOMP_RET_ALLOW;···554554 BUG();555555}556556#else557557-int __secure_computing(const struct seccomp_data *sd)558558-{559559- u32 phase1_result = seccomp_phase1(sd);560560-561561- if (likely(phase1_result == SECCOMP_PHASE1_OK))562562- return 0;563563- else if (likely(phase1_result == SECCOMP_PHASE1_SKIP))564564- return -1;565565- else566566- return seccomp_phase2(phase1_result);567567-}568557569558#ifdef CONFIG_SECCOMP_FILTER570570-static u32 __seccomp_phase1_filter(int this_syscall, struct seccomp_data *sd)559559+static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd)571560{572561 u32 filter_ret, action;573562 int data;···588599 goto skip;589600590601 case SECCOMP_RET_TRACE:591591- return filter_ret; /* Save the rest for phase 2. */602602+ /* ENOSYS these calls if there is no tracer attached. */603603+ if (!ptrace_event_enabled(current, PTRACE_EVENT_SECCOMP)) {604604+ syscall_set_return_value(current,605605+ task_pt_regs(current),606606+ -ENOSYS, 0);607607+ goto skip;608608+ }609609+610610+ /* Allow the BPF to provide the event message */611611+ ptrace_event(PTRACE_EVENT_SECCOMP, data);612612+ /*613613+ * The delivery of a fatal signal during event614614+ * notification may silently skip tracer notification.615615+ * Terminating the task now avoids executing a system616616+ * call that may not be intended.617617+ */618618+ if (fatal_signal_pending(current))619619+ do_exit(SIGSYS);620620+ /* Check if the tracer forced the syscall to be skipped. */621621+ this_syscall = syscall_get_nr(current, task_pt_regs(current));622622+ if (this_syscall < 0)623623+ goto skip;624624+625625+ return 0;592626593627 case SECCOMP_RET_ALLOW:594594- return SECCOMP_PHASE1_OK;628628+ return 0;595629596630 case SECCOMP_RET_KILL:597631 default:···626614627615skip:628616 audit_seccomp(this_syscall, 0, action);629629- return SECCOMP_PHASE1_SKIP;617617+ return -1;618618+}619619+#else620620+static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd)621621+{622622+ BUG();630623}631624#endif632625633633-/**634634- * seccomp_phase1() - run fast path seccomp checks on the current syscall635635- * @arg sd: The seccomp_data or NULL636636- *637637- * This only reads pt_regs via the syscall_xyz helpers. The only change638638- * it will make to pt_regs is via syscall_set_return_value, and it will639639- * only do that if it returns SECCOMP_PHASE1_SKIP.640640- *641641- * If sd is provided, it will not read pt_regs at all.642642- *643643- * It may also call do_exit or force a signal; these actions must be644644- * safe.645645- *646646- * If it returns SECCOMP_PHASE1_OK, the syscall passes checks and should647647- * be processed normally.648648- *649649- * If it returns SECCOMP_PHASE1_SKIP, then the syscall should not be650650- * invoked. In this case, seccomp_phase1 will have set the return value651651- * using syscall_set_return_value.652652- *653653- * If it returns anything else, then the return value should be passed654654- * to seccomp_phase2 from a context in which ptrace hooks are safe.655655- */656656-u32 seccomp_phase1(struct seccomp_data *sd)626626+int __secure_computing(const struct seccomp_data *sd)657627{658628 int mode = current->seccomp.mode;659659- int this_syscall = sd ? sd->nr :660660- syscall_get_nr(current, task_pt_regs(current));629629+ int this_syscall;661630662631 if (config_enabled(CONFIG_CHECKPOINT_RESTORE) &&663632 unlikely(current->ptrace & PT_SUSPEND_SECCOMP))664664- return SECCOMP_PHASE1_OK;633633+ return 0;634634+635635+ this_syscall = sd ? sd->nr :636636+ syscall_get_nr(current, task_pt_regs(current));665637666638 switch (mode) {667639 case SECCOMP_MODE_STRICT:668640 __secure_computing_strict(this_syscall); /* may call do_exit */669669- return SECCOMP_PHASE1_OK;670670-#ifdef CONFIG_SECCOMP_FILTER641641+ return 0;671642 case SECCOMP_MODE_FILTER:672672- return __seccomp_phase1_filter(this_syscall, sd);673673-#endif643643+ return __seccomp_filter(this_syscall, sd);674644 default:675645 BUG();676646 }677677-}678678-679679-/**680680- * seccomp_phase2() - finish slow path seccomp work for the current syscall681681- * @phase1_result: The return value from seccomp_phase1()682682- *683683- * This must be called from a context in which ptrace hooks can be used.684684- *685685- * Returns 0 if the syscall should be processed or -1 to skip the syscall.686686- */687687-int seccomp_phase2(u32 phase1_result)688688-{689689- struct pt_regs *regs = task_pt_regs(current);690690- u32 action = phase1_result & SECCOMP_RET_ACTION;691691- int data = phase1_result & SECCOMP_RET_DATA;692692-693693- BUG_ON(action != SECCOMP_RET_TRACE);694694-695695- audit_seccomp(syscall_get_nr(current, regs), 0, action);696696-697697- /* Skip these calls if there is no tracer. */698698- if (!ptrace_event_enabled(current, PTRACE_EVENT_SECCOMP)) {699699- syscall_set_return_value(current, regs,700700- -ENOSYS, 0);701701- return -1;702702- }703703-704704- /* Allow the BPF to provide the event message */705705- ptrace_event(PTRACE_EVENT_SECCOMP, data);706706- /*707707- * The delivery of a fatal signal during event708708- * notification may silently skip tracer notification.709709- * Terminating the task now avoids executing a system710710- * call that may not be intended.711711- */712712- if (fatal_signal_pending(current))713713- do_exit(SIGSYS);714714- if (syscall_get_nr(current, regs) < 0)715715- return -1; /* Explicit request to skip. */716716-717717- return 0;718647}719648#endif /* CONFIG_HAVE_ARCH_SECCOMP_FILTER */720649