avtab.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * An access vector table (avtab) is a hash table
  4. * of access vectors and transition types indexed
  5. * by a type pair and a class. An access vector
  6. * table is used to represent the type enforcement
  7. * tables.
  8. *
  9. * Author : Stephen Smalley, <stephen.smalley.work@gmail.com>
  10. */
  11. /* Updated: Frank Mayer <mayerf@tresys.com> and
  12. * Karl MacMillan <kmacmillan@tresys.com>
  13. * Added conditional policy language extensions
  14. * Copyright (C) 2003 Tresys Technology, LLC
  15. *
  16. * Updated: Yuichi Nakamura <ynakam@hitachisoft.jp>
  17. * Tuned number of hash slots for avtab to reduce memory usage
  18. */
  19. #ifndef _SS_AVTAB_H_
  20. #define _SS_AVTAB_H_
  21. #include "security.h"
  22. struct avtab_key {
  23. u16 source_type; /* source type */
  24. u16 target_type; /* target type */
  25. u16 target_class; /* target object class */
  26. #define AVTAB_ALLOWED 0x0001
  27. #define AVTAB_AUDITALLOW 0x0002
  28. #define AVTAB_AUDITDENY 0x0004
  29. #define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY)
  30. #define AVTAB_TRANSITION 0x0010
  31. #define AVTAB_MEMBER 0x0020
  32. #define AVTAB_CHANGE 0x0040
  33. #define AVTAB_TYPE (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE)
  34. /* extended permissions */
  35. #define AVTAB_XPERMS_ALLOWED 0x0100
  36. #define AVTAB_XPERMS_AUDITALLOW 0x0200
  37. #define AVTAB_XPERMS_DONTAUDIT 0x0400
  38. #define AVTAB_XPERMS \
  39. (AVTAB_XPERMS_ALLOWED | AVTAB_XPERMS_AUDITALLOW | \
  40. AVTAB_XPERMS_DONTAUDIT)
  41. #define AVTAB_ENABLED_OLD 0x80000000 /* reserved for used in cond_avtab */
  42. #define AVTAB_ENABLED 0x8000 /* reserved for used in cond_avtab */
  43. u16 specified; /* what field is specified */
  44. };
  45. /*
  46. * For operations that require more than the 32 permissions provided by the avc
  47. * extended permissions may be used to provide 256 bits of permissions.
  48. */
  49. struct avtab_extended_perms {
  50. /* These are not flags. All 256 values may be used */
  51. #define AVTAB_XPERMS_IOCTLFUNCTION 0x01
  52. #define AVTAB_XPERMS_IOCTLDRIVER 0x02
  53. /* extension of the avtab_key specified */
  54. u8 specified; /* ioctl, netfilter, ... */
  55. /*
  56. * if 256 bits is not adequate as is often the case with ioctls, then
  57. * multiple extended perms may be used and the driver field
  58. * specifies which permissions are included.
  59. */
  60. u8 driver;
  61. /* 256 bits of permissions */
  62. struct extended_perms_data perms;
  63. };
  64. struct avtab_datum {
  65. union {
  66. u32 data; /* access vector or type value */
  67. struct avtab_extended_perms *xperms;
  68. } u;
  69. };
  70. struct avtab_node {
  71. struct avtab_key key;
  72. struct avtab_datum datum;
  73. struct avtab_node *next;
  74. };
  75. struct avtab {
  76. struct avtab_node **htable;
  77. u32 nel; /* number of elements */
  78. u32 nslot; /* number of hash slots */
  79. u32 mask; /* mask to compute hash func */
  80. };
  81. void avtab_init(struct avtab *h);
  82. int avtab_alloc(struct avtab *, u32);
  83. int avtab_alloc_dup(struct avtab *new, const struct avtab *orig);
  84. void avtab_destroy(struct avtab *h);
  85. #define MAX_AVTAB_HASH_BITS 16
  86. #define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS)
  87. #ifdef CONFIG_SECURITY_SELINUX_DEBUG
  88. void avtab_hash_eval(struct avtab *h, const char *tag);
  89. #else
  90. static inline void avtab_hash_eval(struct avtab *h, const char *tag)
  91. {
  92. }
  93. #endif
  94. struct policydb;
  95. int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
  96. int (*insert)(struct avtab *a, const struct avtab_key *k,
  97. const struct avtab_datum *d, void *p),
  98. void *p);
  99. int avtab_read(struct avtab *a, void *fp, struct policydb *pol);
  100. int avtab_write_item(struct policydb *p, const struct avtab_node *cur,
  101. void *fp);
  102. int avtab_write(struct policydb *p, struct avtab *a, void *fp);
  103. struct avtab_node *avtab_insert_nonunique(struct avtab *h,
  104. const struct avtab_key *key,
  105. const struct avtab_datum *datum);
  106. struct avtab_node *avtab_search_node(struct avtab *h,
  107. const struct avtab_key *key);
  108. struct avtab_node *avtab_search_node_next(struct avtab_node *node,
  109. u16 specified);
  110. #endif /* _SS_AVTAB_H_ */