lsm_audit.h 2.4 KB

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