lsm_audit.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_FS 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. struct task_struct *tsk;
  36. union {
  37. struct {
  38. struct path path;
  39. struct inode *inode;
  40. } fs;
  41. struct {
  42. int netif;
  43. struct sock *sk;
  44. u16 family;
  45. __be16 dport;
  46. __be16 sport;
  47. union {
  48. struct {
  49. __be32 daddr;
  50. __be32 saddr;
  51. } v4;
  52. struct {
  53. struct in6_addr daddr;
  54. struct in6_addr saddr;
  55. } v6;
  56. } fam;
  57. } net;
  58. int cap;
  59. int ipc_id;
  60. struct task_struct *tsk;
  61. #ifdef CONFIG_KEYS
  62. struct {
  63. key_serial_t key;
  64. char *key_desc;
  65. } key_struct;
  66. #endif
  67. char *kmod_name;
  68. } u;
  69. /* this union contains LSM specific data */
  70. union {
  71. #ifdef CONFIG_SECURITY_SMACK
  72. /* SMACK data */
  73. struct smack_audit_data {
  74. const char *function;
  75. char *subject;
  76. char *object;
  77. char *request;
  78. int result;
  79. } smack_audit_data;
  80. #endif
  81. #ifdef CONFIG_SECURITY_SELINUX
  82. /* SELinux data */
  83. struct {
  84. u32 ssid;
  85. u32 tsid;
  86. u16 tclass;
  87. u32 requested;
  88. u32 audited;
  89. u32 denied;
  90. /*
  91. * auditdeny is a bit tricky and unintuitive. See the
  92. * comments in avc.c for it's meaning and usage.
  93. */
  94. u32 auditdeny;
  95. struct av_decision *avd;
  96. int result;
  97. } selinux_audit_data;
  98. #endif
  99. };
  100. /* these callback will be implemented by a specific LSM */
  101. void (*lsm_pre_audit)(struct audit_buffer *, void *);
  102. void (*lsm_post_audit)(struct audit_buffer *, void *);
  103. };
  104. #define v4info fam.v4
  105. #define v6info fam.v6
  106. int ipv4_skb_to_auditdata(struct sk_buff *skb,
  107. struct common_audit_data *ad, u8 *proto);
  108. int ipv6_skb_to_auditdata(struct sk_buff *skb,
  109. struct common_audit_data *ad, u8 *proto);
  110. /* Initialize an LSM audit data structure. */
  111. #define COMMON_AUDIT_DATA_INIT(_d, _t) \
  112. { memset((_d), 0, sizeof(struct common_audit_data)); \
  113. (_d)->type = LSM_AUDIT_DATA_##_t; }
  114. void common_lsm_audit(struct common_audit_data *a);
  115. #endif