Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Multi-level security (MLS) policy operations. |
| 4 | * |
Stephen Smalley | 7efbb60 | 2017-08-17 13:32:36 -0400 | [diff] [blame] | 5 | * Author : Stephen Smalley, <sds@tycho.nsa.gov> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | /* |
| 8 | * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com> |
| 9 | * |
| 10 | * Support for enhanced MLS infrastructure. |
| 11 | * |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 12 | * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 14 | /* |
Paul Moore | 82c21bf | 2011-08-01 11:10:33 +0000 | [diff] [blame] | 15 | * Updated: Hewlett-Packard <paul@paul-moore.com> |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 16 | * |
Eric Paris | d497fc87 | 2008-04-22 17:46:15 -0400 | [diff] [blame] | 17 | * Added support to import/export the MLS label from NetLabel |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 18 | * |
| 19 | * (c) Copyright Hewlett-Packard Development Company, L.P., 2006 |
| 20 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #ifndef _SS_MLS_H_ |
| 23 | #define _SS_MLS_H_ |
| 24 | |
Ondrej Mosnacek | 5007728 | 2020-04-17 10:11:56 +0200 | [diff] [blame] | 25 | #include <linux/jhash.h> |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "context.h" |
Ondrej Mosnacek | 5007728 | 2020-04-17 10:11:56 +0200 | [diff] [blame] | 28 | #include "ebitmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "policydb.h" |
| 30 | |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 31 | int mls_compute_context_len(struct policydb *p, struct context *context); |
| 32 | void mls_sid_to_context(struct policydb *p, struct context *context, |
| 33 | char **scontext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | int mls_context_isvalid(struct policydb *p, struct context *c); |
Stephen Smalley | 45e5421 | 2007-11-07 10:08:00 -0500 | [diff] [blame] | 35 | int mls_range_isvalid(struct policydb *p, struct mls_range *r); |
| 36 | int mls_level_isvalid(struct policydb *p, struct mls_level *l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Stephen Smalley | 12b29f3 | 2008-05-07 13:03:20 -0400 | [diff] [blame] | 38 | int mls_context_to_sid(struct policydb *p, |
| 39 | char oldc, |
Jann Horn | 95ffe19 | 2018-08-06 23:19:32 +0200 | [diff] [blame] | 40 | char *scontext, |
James Morris | f5c1d5b | 2005-07-28 01:07:37 -0700 | [diff] [blame] | 41 | struct context *context, |
| 42 | struct sidtab *s, |
| 43 | u32 def_sid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 45 | int mls_from_string(struct policydb *p, char *str, struct context *context, |
| 46 | gfp_t gfp_mask); |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 47 | |
Guido Trentalancia | 0719aaf | 2010-02-03 16:40:20 +0100 | [diff] [blame] | 48 | int mls_range_set(struct context *context, struct mls_range *range); |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | int mls_convert_context(struct policydb *oldp, |
| 51 | struct policydb *newp, |
Ondrej Mosnacek | ee1a84f | 2018-11-30 16:24:08 +0100 | [diff] [blame] | 52 | struct context *oldc, |
| 53 | struct context *newc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 55 | int mls_compute_sid(struct policydb *p, |
| 56 | struct context *scontext, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | struct context *tcontext, |
| 58 | u16 tclass, |
| 59 | u32 specified, |
Harry Ciao | 6f5317e | 2011-03-02 13:32:33 +0800 | [diff] [blame] | 60 | struct context *newcontext, |
| 61 | bool sock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 63 | int mls_setup_user_range(struct policydb *p, |
| 64 | struct context *fromcon, struct user_datum *user, |
Eric Paris | d497fc87 | 2008-04-22 17:46:15 -0400 | [diff] [blame] | 65 | struct context *usercon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Paul Moore | 0275276 | 2006-11-29 13:18:18 -0500 | [diff] [blame] | 67 | #ifdef CONFIG_NETLABEL |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 68 | void mls_export_netlbl_lvl(struct policydb *p, |
| 69 | struct context *context, |
Paul Moore | 0275276 | 2006-11-29 13:18:18 -0500 | [diff] [blame] | 70 | struct netlbl_lsm_secattr *secattr); |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 71 | void mls_import_netlbl_lvl(struct policydb *p, |
| 72 | struct context *context, |
Paul Moore | 0275276 | 2006-11-29 13:18:18 -0500 | [diff] [blame] | 73 | struct netlbl_lsm_secattr *secattr); |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 74 | int mls_export_netlbl_cat(struct policydb *p, |
| 75 | struct context *context, |
Paul Moore | 0275276 | 2006-11-29 13:18:18 -0500 | [diff] [blame] | 76 | struct netlbl_lsm_secattr *secattr); |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 77 | int mls_import_netlbl_cat(struct policydb *p, |
| 78 | struct context *context, |
Paul Moore | 0275276 | 2006-11-29 13:18:18 -0500 | [diff] [blame] | 79 | struct netlbl_lsm_secattr *secattr); |
| 80 | #else |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 81 | static inline void mls_export_netlbl_lvl(struct policydb *p, |
| 82 | struct context *context, |
Paul Moore | 0275276 | 2006-11-29 13:18:18 -0500 | [diff] [blame] | 83 | struct netlbl_lsm_secattr *secattr) |
| 84 | { |
| 85 | return; |
| 86 | } |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 87 | static inline void mls_import_netlbl_lvl(struct policydb *p, |
| 88 | struct context *context, |
Paul Moore | 0275276 | 2006-11-29 13:18:18 -0500 | [diff] [blame] | 89 | struct netlbl_lsm_secattr *secattr) |
| 90 | { |
| 91 | return; |
| 92 | } |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 93 | static inline int mls_export_netlbl_cat(struct policydb *p, |
| 94 | struct context *context, |
Paul Moore | 0275276 | 2006-11-29 13:18:18 -0500 | [diff] [blame] | 95 | struct netlbl_lsm_secattr *secattr) |
| 96 | { |
| 97 | return -ENOMEM; |
| 98 | } |
Stephen Smalley | aa8e712 | 2018-03-01 18:48:02 -0500 | [diff] [blame] | 99 | static inline int mls_import_netlbl_cat(struct policydb *p, |
| 100 | struct context *context, |
Paul Moore | 0275276 | 2006-11-29 13:18:18 -0500 | [diff] [blame] | 101 | struct netlbl_lsm_secattr *secattr) |
| 102 | { |
| 103 | return -ENOMEM; |
| 104 | } |
| 105 | #endif |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 106 | |
Ondrej Mosnacek | 5007728 | 2020-04-17 10:11:56 +0200 | [diff] [blame] | 107 | static inline u32 mls_range_hash(const struct mls_range *r, u32 hash) |
| 108 | { |
| 109 | hash = jhash_2words(r->level[0].sens, r->level[1].sens, hash); |
| 110 | hash = ebitmap_hash(&r->level[0].cat, hash); |
| 111 | hash = ebitmap_hash(&r->level[1].cat, hash); |
| 112 | return hash; |
| 113 | } |
| 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | #endif /* _SS_MLS_H */ |
| 116 | |