graphene.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #ifndef _LINUX_GRAPHENE_H
  2. #define _LINUX_GRAPHENE_H
  3. #include <linux/ioctl.h>
  4. #include <linux/in.h>
  5. #include <linux/in6.h>
  6. #define GRAPHENE_FILE "/dev/graphene"
  7. #define GRAPHENE_MINOR 239
  8. #define GRAPHENE_UNIX_PREFIX_FMT "/graphene/%016lx"
  9. #define GRAPHENE_MCAST_GROUP "239.0.0.1"
  10. /* symbolic link this header file in include/linux */
  11. /* This header needs to be included in include/linux/sched.h */
  12. #ifndef __KERNEL__
  13. # ifdef __user
  14. # undef __user
  15. # endif
  16. # define __user
  17. #endif
  18. #define GRAPHENE_LIB_NAME 0001
  19. #define GRAPHENE_LIB_ADDR 0002
  20. #define GRAPHENE_UNIX_PREFIX 0003
  21. #define GRAPHENE_MCAST_PORT 0004
  22. #define GRAPHENE_FS_PATH 0005
  23. #define GRAPHENE_NET_RULE 0006
  24. #define GRAPHENE_POLICY_TYPES 0007
  25. #define GRAPHENE_FS_RECURSIVE 0010
  26. #define GRAPHENE_FS_READ 0020
  27. #define GRAPHENE_FS_WRITE 0040
  28. #define GRAPHENE_NET_BIND 0100
  29. struct graphene_user_policy {
  30. int type;
  31. const void __user * value;
  32. };
  33. struct graphene_net_addr {
  34. union {
  35. struct in_addr sin_addr;
  36. struct in6_addr sin6_addr;
  37. } addr;
  38. unsigned short port_begin;
  39. unsigned short port_end;
  40. };
  41. struct graphene_net_rule {
  42. unsigned short family;
  43. struct graphene_net_addr addr;
  44. };
  45. #define GRAPHENE_SET_TASK _IOW('k', 16, void *)
  46. struct graphene_policies {
  47. int npolicies;
  48. struct graphene_user_policy policies[];
  49. };
  50. #ifdef __KERNEL__
  51. #include <linux/types.h>
  52. #include <linux/sched.h>
  53. #include <linux/net.h>
  54. #include <linux/path.h>
  55. #include <linux/list.h>
  56. #include <linux/spinlock.h>
  57. #include <linux/dcache.h>
  58. #include <linux/rcupdate.h>
  59. struct task_struct;
  60. struct path;
  61. struct qstr;
  62. struct graphene_path {
  63. struct list_head list;
  64. struct path path;
  65. int type;
  66. };
  67. #define ADDR_ANY 0x1
  68. #define PORT_ANY 0x2
  69. struct graphene_net {
  70. struct list_head list;
  71. short family;
  72. unsigned char flags;
  73. struct graphene_net_addr addr;
  74. };
  75. struct graphene_unix {
  76. atomic_t count;
  77. struct list_head list;
  78. struct path root;
  79. struct qstr prefix;
  80. };
  81. /*
  82. * add the following line to struct task_struct (include/linux/sched.h):
  83. * struct graphene_struct *graphene;
  84. */
  85. struct graphene_info {
  86. atomic_t gi_count;
  87. struct path gi_libexec;
  88. u64 gi_libaddr;
  89. struct path gi_console[3];
  90. char gi_unix[28]; /* fmt: @/graphene/%016lx/ */
  91. struct list_head gi_paths;
  92. struct list_head gi_rpaths;
  93. struct list_head gi_binds;
  94. struct list_head gi_peers;
  95. unsigned short gi_mcast_port;
  96. struct file * gi_mcast_sock;
  97. u64 gi_gipc_session;
  98. };
  99. struct graphene_struct {
  100. atomic_t g_count;
  101. struct graphene_info __rcu *g_info;
  102. spinlock_t g_lock ____cacheline_aligned_in_smp;
  103. };
  104. #define GRAPHENE_ENABLED() (current->graphene != NULL)
  105. /* use this function in __put_task_struct (kernel/fork.c) */
  106. int dup_graphene_struct(struct task_struct *task);
  107. /* use this function in dup_task_struct (kernel/fork.c) */
  108. void put_graphene_struct(struct task_struct *task);
  109. /* add the following lines to common_perm (security/apparmor/lsm.c):
  110. * (when current->in_execve is true)
  111. * if (GRAPHNEE_ENABLED() && (error = graphene_execve_open(file))
  112. * return error;
  113. */
  114. int graphene_execve_open(struct file *file);
  115. unsigned long
  116. graphene_execve_get_area(struct file *file, unsigned long addr,
  117. unsigned long len, unsigned long pgoff,
  118. unsigned long flags);
  119. /*
  120. * add the following lines to common_perm (security/apparmor/lsm.c):
  121. * if (GRAPHENE_ENABLED() &&
  122. * (error = graphene_common_perm(op, path, mask)))
  123. * return error;
  124. *
  125. * add the following lines to apparmor_dentry_open (security/apparmor/lsm.c):
  126. * if (GRAPHENE_ENABLED() &&
  127. * (error = graphene_common_perm(OP_OPEN, &file->path, mask)))
  128. * return error;
  129. */
  130. int graphene_common_perm(int op, struct path *path, u32 mask);
  131. /*
  132. * add the following lines to the initializer of apparmor_ops
  133. * (security/apparmor/lsm.c):
  134. * task_kill = graphene_task_kill,
  135. */
  136. int graphene_task_kill(struct task_struct *task, struct siginfo *info,
  137. int sig, u32 secid);
  138. /*
  139. * add the following lines to the initializer of apparmor_ops
  140. * (security/apparmor/lsm.c):
  141. * socket_bind = graphene_socket_bind,
  142. * socket_listen = graphene_socket_listen,
  143. * socket_connect = graphene_socket_connect,
  144. * socket_sendmsg = graphene_socket_sendmsg,
  145. * socket_recvmsg = grapheen_socket_recvmsg,
  146. */
  147. int graphene_socket_bind(struct socket *sock,
  148. struct sockaddr *address, int addrlen);
  149. int graphene_socket_listen(struct socket *sock, int backlog);
  150. int graphene_socket_connect(struct socket *sock,
  151. struct sockaddr *address, int addrlen);
  152. int graphene_socket_sendmsg(struct socket *sock,
  153. struct msghdr *msg, int size);
  154. int graphene_socket_recvmsg(struct socket *sock,
  155. struct msghdr *msg, int size, int flags);
  156. u64 gipc_get_session(struct task_struct *tsk);
  157. #endif /* __KERNEL__ */
  158. #endif