mls.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Multi-level security (MLS) policy operations.
  4. *
  5. * Author : Stephen Smalley, <[email protected]>
  6. */
  7. /*
  8. * Updated: Trusted Computer Solutions, Inc. <[email protected]>
  9. *
  10. * Support for enhanced MLS infrastructure.
  11. *
  12. * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc.
  13. */
  14. /*
  15. * Updated: Hewlett-Packard <[email protected]>
  16. *
  17. * Added support to import/export the MLS label from NetLabel
  18. *
  19. * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
  20. */
  21. #ifndef _SS_MLS_H_
  22. #define _SS_MLS_H_
  23. #include <linux/jhash.h>
  24. #include "context.h"
  25. #include "ebitmap.h"
  26. #include "policydb.h"
  27. int mls_compute_context_len(struct policydb *p, struct context *context);
  28. void mls_sid_to_context(struct policydb *p, struct context *context,
  29. char **scontext);
  30. int mls_context_isvalid(struct policydb *p, struct context *c);
  31. int mls_range_isvalid(struct policydb *p, struct mls_range *r);
  32. int mls_level_isvalid(struct policydb *p, struct mls_level *l);
  33. int mls_context_to_sid(struct policydb *p,
  34. char oldc,
  35. char *scontext,
  36. struct context *context,
  37. struct sidtab *s,
  38. u32 def_sid);
  39. int mls_from_string(struct policydb *p, char *str, struct context *context,
  40. gfp_t gfp_mask);
  41. int mls_range_set(struct context *context, struct mls_range *range);
  42. int mls_convert_context(struct policydb *oldp,
  43. struct policydb *newp,
  44. struct context *oldc,
  45. struct context *newc);
  46. int mls_compute_sid(struct policydb *p,
  47. struct context *scontext,
  48. struct context *tcontext,
  49. u16 tclass,
  50. u32 specified,
  51. struct context *newcontext,
  52. bool sock);
  53. int mls_setup_user_range(struct policydb *p,
  54. struct context *fromcon, struct user_datum *user,
  55. struct context *usercon);
  56. #ifdef CONFIG_NETLABEL
  57. void mls_export_netlbl_lvl(struct policydb *p,
  58. struct context *context,
  59. struct netlbl_lsm_secattr *secattr);
  60. void mls_import_netlbl_lvl(struct policydb *p,
  61. struct context *context,
  62. struct netlbl_lsm_secattr *secattr);
  63. int mls_export_netlbl_cat(struct policydb *p,
  64. struct context *context,
  65. struct netlbl_lsm_secattr *secattr);
  66. int mls_import_netlbl_cat(struct policydb *p,
  67. struct context *context,
  68. struct netlbl_lsm_secattr *secattr);
  69. #else
  70. static inline void mls_export_netlbl_lvl(struct policydb *p,
  71. struct context *context,
  72. struct netlbl_lsm_secattr *secattr)
  73. {
  74. return;
  75. }
  76. static inline void mls_import_netlbl_lvl(struct policydb *p,
  77. struct context *context,
  78. struct netlbl_lsm_secattr *secattr)
  79. {
  80. return;
  81. }
  82. static inline int mls_export_netlbl_cat(struct policydb *p,
  83. struct context *context,
  84. struct netlbl_lsm_secattr *secattr)
  85. {
  86. return -ENOMEM;
  87. }
  88. static inline int mls_import_netlbl_cat(struct policydb *p,
  89. struct context *context,
  90. struct netlbl_lsm_secattr *secattr)
  91. {
  92. return -ENOMEM;
  93. }
  94. #endif
  95. static inline u32 mls_range_hash(const struct mls_range *r, u32 hash)
  96. {
  97. hash = jhash_2words(r->level[0].sens, r->level[1].sens, hash);
  98. hash = ebitmap_hash(&r->level[0].cat, hash);
  99. hash = ebitmap_hash(&r->level[1].cat, hash);
  100. return hash;
  101. }
  102. #endif /* _SS_MLS_H */