lsm_audit.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Common LSM logging functions
  3. * Heavily borrowed from selinux/avc.h
  4. *
  5. * Author : Etienne BASSET <etienne.basset@ensta.org>
  6. *
  7. * All credits to : Stephen Smalley, <sds@epoch.ncsc.mil>
  8. * All BUGS to : Etienne BASSET <etienne.basset@ensta.org>
  9. */
  10. #ifndef _LSM_COMMON_LOGGING_
  11. #define _LSM_COMMON_LOGGING_
  12. #include <linux/stddef.h>
  13. #include <linux/errno.h>
  14. #include <linux/kernel.h>
  15. #include <linux/kdev_t.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/init.h>
  18. #include <linux/audit.h>
  19. #include <linux/in6.h>
  20. #include <linux/path.h>
  21. #include <linux/key.h>
  22. #include <linux/skbuff.h>
  23. #include <asm/system.h>
  24. /* Auxiliary data to use in generating the audit record. */
  25. struct common_audit_data {
  26. char type;
  27. #define LSM_AUDIT_DATA_PATH 1
  28. #define LSM_AUDIT_DATA_NET 2
  29. #define LSM_AUDIT_DATA_CAP 3
  30. #define LSM_AUDIT_DATA_IPC 4
  31. #define LSM_AUDIT_DATA_TASK 5
  32. #define LSM_AUDIT_DATA_KEY 6
  33. #define LSM_AUDIT_DATA_NONE 7
  34. #define LSM_AUDIT_DATA_KMOD 8
  35. #define LSM_AUDIT_DATA_INODE 9
  36. #define LSM_AUDIT_DATA_DENTRY 10
  37. struct task_struct *tsk;
  38. union {
  39. struct path path;
  40. struct dentry *dentry;
  41. struct inode *inode;
  42. struct {
  43. int netif;
  44. struct sock *sk;
  45. u16 family;
  46. __be16 dport;
  47. __be16 sport;
  48. union {
  49. struct {
  50. __be32 daddr;
  51. __be32 saddr;
  52. } v4;
  53. struct {
  54. struct in6_addr daddr;
  55. struct in6_addr saddr;
  56. } v6;
  57. } fam;
  58. } net;
  59. int cap;
  60. int ipc_id;
  61. struct task_struct *tsk;
  62. #ifdef CONFIG_KEYS
  63. struct {
  64. key_serial_t key;
  65. char *key_desc;
  66. } key_struct;
  67. #endif
  68. char *kmod_name;
  69. } u;
  70. /* this union contains LSM specific data */
  71. union {
  72. #ifdef CONFIG_SECURITY_SMACK
  73. /* SMACK data */
  74. struct smack_audit_data {
  75. const char *function;
  76. char *subject;
  77. char *object;
  78. char *request;
  79. int result;
  80. } smack_audit_data;
  81. #endif
  82. #ifdef CONFIG_SECURITY_SELINUX
  83. /* SELinux data */
  84. struct {
  85. u32 ssid;
  86. u32 tsid;
  87. u16 tclass;
  88. u32 requested;
  89. u32 audited;
  90. u32 denied;
  91. /*
  92. * auditdeny is a bit tricky and unintuitive. See the
  93. * comments in avc.c for it's meaning and usage.
  94. */
  95. u32 auditdeny;
  96. struct av_decision *avd;
  97. int result;
  98. } selinux_audit_data;
  99. #endif
  100. #ifdef CONFIG_SECURITY_APPARMOR
  101. struct {
  102. int error;
  103. int op;
  104. int type;
  105. void *profile;
  106. const char *name;
  107. const char *info;
  108. union {
  109. void *target;
  110. struct {
  111. long pos;
  112. void *target;
  113. } iface;
  114. struct {
  115. int rlim;
  116. unsigned long max;
  117. } rlim;
  118. struct {
  119. const char *target;
  120. u32 request;
  121. u32 denied;
  122. uid_t ouid;
  123. } fs;
  124. };
  125. } apparmor_audit_data;
  126. #endif
  127. };
  128. /* these callback will be implemented by a specific LSM */
  129. void (*lsm_pre_audit)(struct audit_buffer *, void *);
  130. void (*lsm_post_audit)(struct audit_buffer *, void *);
  131. };
  132. #define v4info fam.v4
  133. #define v6info fam.v6
  134. int ipv4_skb_to_auditdata(struct sk_buff *skb,
  135. struct common_audit_data *ad, u8 *proto);
  136. int ipv6_skb_to_auditdata(struct sk_buff *skb,
  137. struct common_audit_data *ad, u8 *proto);
  138. /* Initialize an LSM audit data structure. */
  139. #define COMMON_AUDIT_DATA_INIT(_d, _t) \
  140. { memset((_d), 0, sizeof(struct common_audit_data)); \
  141. (_d)->type = LSM_AUDIT_DATA_##_t; }
  142. void common_lsm_audit(struct common_audit_data *a);
  143. #endif