lsm_audit.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Common LSM logging functions
  4. * Heavily borrowed from selinux/avc.h
  5. *
  6. * Author : Etienne BASSET <etienne.basset@ensta.org>
  7. *
  8. * All credits to : Stephen Smalley, <sds@tycho.nsa.gov>
  9. * All BUGS to : Etienne BASSET <etienne.basset@ensta.org>
  10. */
  11. #ifndef _LSM_COMMON_LOGGING_
  12. #define _LSM_COMMON_LOGGING_
  13. #include <linux/stddef.h>
  14. #include <linux/errno.h>
  15. #include <linux/kernel.h>
  16. #include <linux/kdev_t.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/init.h>
  19. #include <linux/audit.h>
  20. #include <linux/in6.h>
  21. #include <linux/path.h>
  22. #include <linux/key.h>
  23. #include <linux/skbuff.h>
  24. #include <rdma/ib_verbs.h>
  25. struct lsm_network_audit {
  26. int netif;
  27. struct sock *sk;
  28. u16 family;
  29. __be16 dport;
  30. __be16 sport;
  31. union {
  32. struct {
  33. __be32 daddr;
  34. __be32 saddr;
  35. } v4;
  36. struct {
  37. struct in6_addr daddr;
  38. struct in6_addr saddr;
  39. } v6;
  40. } fam;
  41. };
  42. struct lsm_ioctlop_audit {
  43. struct path path;
  44. u16 cmd;
  45. };
  46. struct lsm_ibpkey_audit {
  47. u64 subnet_prefix;
  48. u16 pkey;
  49. };
  50. struct lsm_ibendport_audit {
  51. char dev_name[IB_DEVICE_NAME_MAX];
  52. u8 port;
  53. };
  54. /* Auxiliary data to use in generating the audit record. */
  55. struct common_audit_data {
  56. char type;
  57. #define LSM_AUDIT_DATA_PATH 1
  58. #define LSM_AUDIT_DATA_NET 2
  59. #define LSM_AUDIT_DATA_CAP 3
  60. #define LSM_AUDIT_DATA_IPC 4
  61. #define LSM_AUDIT_DATA_TASK 5
  62. #define LSM_AUDIT_DATA_KEY 6
  63. #define LSM_AUDIT_DATA_NONE 7
  64. #define LSM_AUDIT_DATA_KMOD 8
  65. #define LSM_AUDIT_DATA_INODE 9
  66. #define LSM_AUDIT_DATA_DENTRY 10
  67. #define LSM_AUDIT_DATA_IOCTL_OP 11
  68. #define LSM_AUDIT_DATA_FILE 12
  69. #define LSM_AUDIT_DATA_IBPKEY 13
  70. #define LSM_AUDIT_DATA_IBENDPORT 14
  71. #define LSM_AUDIT_DATA_NOTIFICATION 16
  72. union {
  73. struct path path;
  74. struct dentry *dentry;
  75. struct inode *inode;
  76. struct lsm_network_audit *net;
  77. int cap;
  78. int ipc_id;
  79. struct task_struct *tsk;
  80. #ifdef CONFIG_KEYS
  81. struct {
  82. key_serial_t key;
  83. char *key_desc;
  84. } key_struct;
  85. #endif
  86. char *kmod_name;
  87. struct lsm_ioctlop_audit *op;
  88. struct file *file;
  89. struct lsm_ibpkey_audit *ibpkey;
  90. struct lsm_ibendport_audit *ibendport;
  91. } u;
  92. /* this union contains LSM specific data */
  93. union {
  94. #ifdef CONFIG_SECURITY_SMACK
  95. struct smack_audit_data *smack_audit_data;
  96. #endif
  97. #ifdef CONFIG_SECURITY_SELINUX
  98. struct selinux_audit_data *selinux_audit_data;
  99. #endif
  100. #ifdef CONFIG_SECURITY_APPARMOR
  101. struct apparmor_audit_data *apparmor_audit_data;
  102. #endif
  103. }; /* per LSM data pointer union */
  104. };
  105. #define v4info fam.v4
  106. #define v6info fam.v6
  107. int ipv4_skb_to_auditdata(struct sk_buff *skb,
  108. struct common_audit_data *ad, u8 *proto);
  109. int ipv6_skb_to_auditdata(struct sk_buff *skb,
  110. struct common_audit_data *ad, u8 *proto);
  111. void common_lsm_audit(struct common_audit_data *a,
  112. void (*pre_audit)(struct audit_buffer *, void *),
  113. void (*post_audit)(struct audit_buffer *, void *));
  114. #endif