graphene.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. /* symbolic link this header file in include/linux */
  9. /* This header needs to be included in include/linux/sched.h */
  10. #ifndef __KERNEL__
  11. # ifdef __user
  12. # undef __user
  13. # endif
  14. # define __user
  15. #endif
  16. #define GRAPHENE_LIB_NAME 0x01
  17. #define GRAPHENE_LIB_ADDR 0x02
  18. #define GRAPHENE_UNIX_ROOT 0x03
  19. #define GRAPHENE_UNIX_PREFIX 0x04
  20. #define GRAPHENE_NET_RULE 0x05
  21. #define GRAPHENE_FS_PATH 0x06
  22. #define GRAPHENE_FS_RECURSIVE 0x07
  23. #define GRAPHENE_FS_READ 0x10
  24. #define GRAPHENE_FS_WRITE 0x20
  25. struct graphene_user_policy {
  26. int type;
  27. const void __user * value;
  28. };
  29. struct graphene_net_addr {
  30. union {
  31. struct in_addr sin_addr;
  32. struct in6_addr sin6_addr;
  33. } addr;
  34. unsigned short port_begin;
  35. unsigned short port_end;
  36. };
  37. struct graphene_net_policy {
  38. unsigned short family;
  39. struct graphene_net_addr local, peer;
  40. };
  41. #define GRAPHENE_SET_TASK _IO('k', 16)
  42. struct graphene_policies {
  43. int npolicies;
  44. struct graphene_user_policy policies[];
  45. };
  46. #ifdef __KERNEL__
  47. #include <linux/types.h>
  48. #include <linux/sched.h>
  49. #include <linux/net.h>
  50. #include <linux/path.h>
  51. #include <linux/list.h>
  52. #include <linux/spinlock.h>
  53. #include <linux/dcache.h>
  54. #include <linux/rcupdate.h>
  55. struct task_struct;
  56. struct path;
  57. struct qstr;
  58. struct graphene_path {
  59. struct list_head list;
  60. struct path path;
  61. int type;
  62. };
  63. #define LOCAL_ADDR_ANY 0x1
  64. #define LOCAL_PORT_ANY 0x2
  65. #define PEER_ADDR_ANY 0x4
  66. #define PEER_PORT_ANY 0x8
  67. struct graphene_net {
  68. struct list_head list;
  69. short family;
  70. unsigned char flags;
  71. struct graphene_net_addr local, peer;
  72. };
  73. struct graphene_unix {
  74. atomic_t count;
  75. struct list_head list;
  76. struct path root;
  77. struct qstr prefix;
  78. };
  79. /*
  80. * add the following line to struct task_struct (include/linux/sched.h):
  81. * struct graphene_struct *graphene;
  82. */
  83. struct graphene_info {
  84. atomic_t gi_count;
  85. struct path gi_libexec;
  86. u64 gi_libaddr;
  87. struct path gi_console[3];
  88. struct graphene_unix * gi_unix;
  89. struct list_head gi_paths;
  90. struct list_head gi_rpaths;
  91. struct list_head gi_net;
  92. u32 gi_gipc_session;
  93. };
  94. struct graphene_struct {
  95. atomic_t g_count;
  96. struct graphene_info __rcu *g_info;
  97. spinlock_t g_lock ____cacheline_aligned_in_smp;
  98. };
  99. #define GRAPHENE_ENABLED() (current->graphene != NULL)
  100. /* use this function in __put_task_struct (kernel/fork.c) */
  101. int dup_graphene_struct(struct task_struct *task);
  102. /* use this function in dup_task_struct (kernel/fork.c) */
  103. void put_graphene_struct(struct task_struct *task);
  104. /* add the following lines to common_perm (security/apparmor/lsm.c):
  105. * (when current->in_execve is true)
  106. * if (GRAPHNEE_ENABLED() && (error = graphene_execve_open(file))
  107. * return error;
  108. */
  109. int graphene_execve_open(struct file *file);
  110. /*
  111. * add the following lines to common_perm (security/apparmor/lsm.c):
  112. * if (GRAPHENE_ENABLED() &&
  113. * (error = graphene_common_perm(op, path, mask)))
  114. * return error;
  115. *
  116. * add the following lines to apparmor_dentry_open (security/apparmor/lsm.c):
  117. * if (GRAPHENE_ENABLED() &&
  118. * (error = graphene_common_perm(OP_OPEN, &file->path, mask)))
  119. * return error;
  120. */
  121. int graphene_common_perm(int op, struct path *path, u32 mask);
  122. /*
  123. * add the following lines to the initializer of apparmor_ops
  124. * (security/apparmor/lsm.c):
  125. * task_kill = graphene_task_kill,
  126. */
  127. int graphene_task_kill(struct task_struct *task, struct siginfo *info,
  128. int sig, u32 secid);
  129. /*
  130. * add the following lines to the initializer of apparmor_ops
  131. * (security/apparmor/lsm.c):
  132. * socket_bind = graphene_socket_bind,
  133. * socket_listen = graphene_socket_listen,
  134. * socket_connect = graphene_socket_connect,
  135. * socket_sendmsg = graphene_socket_sendmsg,
  136. * socket_recvmsg = grapheen_socket_recvmsg,
  137. */
  138. int graphene_socket_bind(struct socket *sock,
  139. struct sockaddr *address, int addrlen);
  140. int graphene_socket_listen(struct socket *sock, int backlog);
  141. int graphene_socket_connect(struct socket *sock,
  142. struct sockaddr *address, int addrlen);
  143. int graphene_socket_sendmsg(struct socket *sock,
  144. struct msghdr *msg, int size);
  145. int graphene_socket_recvmsg(struct socket *sock,
  146. struct msghdr *msg, int size, int flags);
  147. u32 gipc_get_session(struct task_struct *tsk);
  148. #endif /* __KERNEL__ */
  149. #endif