seccomp.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * seccomp example with syscall reporting
  3. *
  4. * Copyright (c) 2012 The Chromium OS Authors <chromium-os-dev@chromium.org>
  5. * Authors:
  6. * Kees Cook <keescook@chromium.org>
  7. * Will Drewry <wad@chromium.org>
  8. *
  9. * Use of this source code is governed by a BSD-style license that can be
  10. * found in the LICENSE file.
  11. */
  12. #define _GNU_SOURCE 1
  13. #include <stddef.h>
  14. #include <stdlib.h>
  15. #include <unistd.h>
  16. #include <libubox/utils.h>
  17. #include <libubox/blobmsg.h>
  18. #include <libubox/blobmsg_json.h>
  19. #include "log.h"
  20. #include "seccomp.h"
  21. #include "seccomp-oci.h"
  22. int install_syscall_filter(const char *argv, const char *file)
  23. {
  24. struct blob_buf b = { 0 };
  25. struct sock_fprog *prog = NULL;
  26. DEBUG("%s: setting up syscall filter\n", argv);
  27. blob_buf_init(&b, 0);
  28. if (!blobmsg_add_json_from_file(&b, file)) {
  29. ERROR("%s: failed to load %s\n", argv, file);
  30. return -1;
  31. }
  32. prog = parseOCIlinuxseccomp(b.head);
  33. if (!prog) {
  34. ERROR("%s: failed to parse seccomp filter rules %s\n", argv, file);
  35. return -1;
  36. }
  37. return applyOCIlinuxseccomp(prog);
  38. }