mls.h 3.1 KB

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