avtab.h 3.9 KB

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