999-seccomp_log.patch 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. --- a/kernel/seccomp.c
  2. +++ b/kernel/seccomp.c
  3. @@ -614,6 +614,7 @@ int __secure_computing(void)
  4. #ifdef CONFIG_SECCOMP_FILTER
  5. static u32 __seccomp_phase1_filter(int this_syscall, struct seccomp_data *sd)
  6. {
  7. + char name[sizeof(current->comm)];
  8. u32 filter_ret, action;
  9. int data;
  10. @@ -644,6 +645,13 @@ static u32 __seccomp_phase1_filter(int t
  11. case SECCOMP_RET_TRACE:
  12. return filter_ret; /* Save the rest for phase 2. */
  13. + case SECCOMP_RET_LOG:
  14. + get_task_comm(name, current);
  15. + pr_err_ratelimited("seccomp: %s [%u] tried to call non-whitelisted syscall: %d\n", name, current->pid, this_syscall);
  16. + syscall_set_return_value(current, task_pt_regs(current),
  17. + -data, 0);
  18. + goto skip;
  19. +
  20. case SECCOMP_RET_ALLOW:
  21. return SECCOMP_PHASE1_OK;
  22. --- a/include/uapi/linux/seccomp.h
  23. +++ b/include/uapi/linux/seccomp.h
  24. @@ -28,6 +28,7 @@
  25. #define SECCOMP_RET_KILL 0x00000000U /* kill the task immediately */
  26. #define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
  27. #define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */
  28. +#define SECCOMP_RET_LOG 0x00070000U /* allow + logline */
  29. #define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */
  30. #define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */