wrapper.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include <linux/unistd.h>
  4. #include <sys/wait.h>
  5. #include <sys/stat.h>
  6. #include <sys/socket.h>
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include <asm-errno.h>
  10. #include "utils.h"
  11. #include "pal_security.h"
  12. #include "graphene.h"
  13. extern unsigned long pal_addr;
  14. bool do_fork = false;
  15. bool do_trace = false;
  16. extern struct pal_sec_info * pal_sec_info_addr;
  17. extern struct config_store root_config;
  18. int ioctl_set_graphene (struct config_store * config, int ndefault,
  19. const struct graphene_user_policy * default_policies);
  20. int init_child (int argc, const char ** argv, const char ** envp)
  21. {
  22. const char * pipe_prefix = pal_sec_info_addr->pipe_prefix;
  23. char pipe_root[sizeof(GRAPHENE_PIPEDIR) + 20];
  24. snprintf(pipe_root, sizeof(GRAPHENE_PIPEDIR) + 20, GRAPHENE_PIPEDIR "/%08x",
  25. pal_sec_info_addr->domain_id);
  26. struct graphene_net_policy mcast_rules[2];
  27. memset(mcast_rules, 0, sizeof(struct graphene_net_policy) * 2);
  28. mcast_rules[0].family = AF_INET;
  29. mcast_rules[0].local.port_begin = pal_sec_info_addr->mcast_port;
  30. mcast_rules[0].local.port_end = pal_sec_info_addr->mcast_port;
  31. mcast_rules[0].peer.port_begin = 0;
  32. mcast_rules[0].peer.port_end = 65535;
  33. mcast_rules[1].family = AF_INET;
  34. mcast_rules[1].local.port_begin = 0;
  35. mcast_rules[1].local.port_end = 65535;
  36. inet_pton(AF_INET, MCAST_GROUP, &mcast_rules[1].peer.addr);
  37. mcast_rules[1].peer.port_begin = pal_sec_info_addr->mcast_port;
  38. mcast_rules[1].peer.port_end = pal_sec_info_addr->mcast_port;
  39. const struct graphene_user_policy default_policies[] = {
  40. { .type = GRAPHENE_LIB_NAME, .value = PAL_LOADER, },
  41. { .type = GRAPHENE_LIB_ADDR, .value = (void *) pal_addr, },
  42. { .type = GRAPHENE_UNIX_ROOT, .value = pipe_root, },
  43. { .type = GRAPHENE_UNIX_PREFIX, .value = pipe_prefix, },
  44. { .type = GRAPHENE_NET_RULE, .value = &mcast_rules[0], },
  45. { .type = GRAPHENE_NET_RULE, .value = &mcast_rules[1], },
  46. };
  47. return ioctl_set_graphene(&root_config, 6, default_policies);
  48. }
  49. int run_parent (pid_t child, int argc, const char ** argv, const char * envp)
  50. {
  51. return 0;
  52. }