| 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 | /* |
| 9 | * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com> |
| 10 | * Support for enhanced MLS infrastructure. |
| 11 | * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc. |
| 12 | * |
| 13 | * Updated: Hewlett-Packard <paul@paul-moore.com> |
| 14 | * Added support to import/export the MLS label from NetLabel |
| 15 | * Copyright (X) Hewlett-Packard Development Company, L.P., 2006 |
| 16 | */ |
| 17 | |
| 18 | #ifndef _SS_MLS_H_ |
| 19 | #define _SS_MLS_H_ |
| 20 | |
| 21 | #include <linux/jhash.h> |
| 22 | |
| 23 | #include "context.h" |
| 24 | #include "ebitmap.h" |
| 25 | #include "policydb.h" |
| 26 | |
| 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 | |
| 34 | int mls_context_to_sid(struct policydb *p, char oldc, char *scontext, |
| 35 | struct context *context, struct sidtab *s, u32 def_sid); |
| 36 | |
| 37 | int mls_from_string(struct policydb *p, char *str, struct context *context, |
| 38 | gfp_t gfp_mask); |
| 39 | |
| 40 | int mls_range_set(struct context *context, struct mls_range *range); |
| 41 | |
| 42 | int mls_convert_context(struct policydb *oldp, struct policydb *newp, |
| 43 | struct context *oldc, struct context *newc); |
| 44 | |
| 45 | int mls_compute_sid(struct policydb *p, struct context *scontext, |
| 46 | struct context *tcontext, u16 tclass, u32 specified, |
| 47 | struct context *newcontext, bool sock); |
| 48 | |
| 49 | int mls_setup_user_range(struct policydb *p, struct context *fromcon, |
| 50 | struct user_datum *user, struct context *usercon); |
| 51 | |
| 52 | #ifdef CONFIG_NETLABEL |
| 53 | void mls_export_netlbl_lvl(struct policydb *p, struct context *context, |
| 54 | struct netlbl_lsm_secattr *secattr); |
| 55 | void mls_import_netlbl_lvl(struct policydb *p, struct context *context, |
| 56 | struct netlbl_lsm_secattr *secattr); |
| 57 | int mls_export_netlbl_cat(struct policydb *p, struct context *context, |
| 58 | struct netlbl_lsm_secattr *secattr); |
| 59 | int mls_import_netlbl_cat(struct policydb *p, struct context *context, |
| 60 | struct netlbl_lsm_secattr *secattr); |
| 61 | #else |
| 62 | static inline void mls_export_netlbl_lvl(struct policydb *p, |
| 63 | struct context *context, |
| 64 | struct netlbl_lsm_secattr *secattr) |
| 65 | { |
| 66 | return; |
| 67 | } |
| 68 | static inline void mls_import_netlbl_lvl(struct policydb *p, |
| 69 | struct context *context, |
| 70 | struct netlbl_lsm_secattr *secattr) |
| 71 | { |
| 72 | return; |
| 73 | } |
| 74 | static inline int mls_export_netlbl_cat(struct policydb *p, |
| 75 | struct context *context, |
| 76 | struct netlbl_lsm_secattr *secattr) |
| 77 | { |
| 78 | return -ENOMEM; |
| 79 | } |
| 80 | static inline int mls_import_netlbl_cat(struct policydb *p, |
| 81 | struct context *context, |
| 82 | struct netlbl_lsm_secattr *secattr) |
| 83 | { |
| 84 | return -ENOMEM; |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | static inline u32 mls_range_hash(const struct mls_range *r, u32 hash) |
| 89 | { |
| 90 | hash = jhash_2words(a: r->level[0].sens, b: r->level[1].sens, initval: hash); |
| 91 | hash = ebitmap_hash(e: &r->level[0].cat, hash); |
| 92 | hash = ebitmap_hash(e: &r->level[1].cat, hash); |
| 93 | return hash; |
| 94 | } |
| 95 | |
| 96 | #endif /* _SS_MLS_H */ |
| 97 | |