1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * Multi-level security (MLS) policy operations.
41da177e4SLinus Torvalds *
5*0fe53224SStephen Smalley * Author : Stephen Smalley, <stephen.smalley.work@gmail.com>
61da177e4SLinus Torvalds */
71da177e4SLinus Torvalds /*
81da177e4SLinus Torvalds * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com>
91da177e4SLinus Torvalds *
101da177e4SLinus Torvalds * Support for enhanced MLS infrastructure.
111da177e4SLinus Torvalds *
12376bd9cbSDarrel Goeddel * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc.
131da177e4SLinus Torvalds */
147420ed23SVenkat Yekkirala /*
1582c21bfaSPaul Moore * Updated: Hewlett-Packard <paul@paul-moore.com>
167420ed23SVenkat Yekkirala *
1702752760SPaul Moore * Added support to import/export the MLS label from NetLabel
187420ed23SVenkat Yekkirala *
197420ed23SVenkat Yekkirala * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
207420ed23SVenkat Yekkirala */
211da177e4SLinus Torvalds
221da177e4SLinus Torvalds #ifndef _SS_MLS_H_
231da177e4SLinus Torvalds #define _SS_MLS_H_
241da177e4SLinus Torvalds
2550077289SOndrej Mosnacek #include <linux/jhash.h>
2650077289SOndrej Mosnacek
271da177e4SLinus Torvalds #include "context.h"
2850077289SOndrej Mosnacek #include "ebitmap.h"
291da177e4SLinus Torvalds #include "policydb.h"
301da177e4SLinus Torvalds
31aa8e712cSStephen Smalley int mls_compute_context_len(struct policydb *p, struct context *context);
32aa8e712cSStephen Smalley void mls_sid_to_context(struct policydb *p, struct context *context,
33aa8e712cSStephen Smalley char **scontext);
341da177e4SLinus Torvalds int mls_context_isvalid(struct policydb *p, struct context *c);
3545e5421eSStephen Smalley int mls_range_isvalid(struct policydb *p, struct mls_range *r);
3645e5421eSStephen Smalley int mls_level_isvalid(struct policydb *p, struct mls_level *l);
371da177e4SLinus Torvalds
3812b29f34SStephen Smalley int mls_context_to_sid(struct policydb *p,
3912b29f34SStephen Smalley char oldc,
4095ffe194SJann Horn char *scontext,
41f5c1d5b2SJames Morris struct context *context,
42f5c1d5b2SJames Morris struct sidtab *s,
43f5c1d5b2SJames Morris u32 def_sid);
441da177e4SLinus Torvalds
45aa8e712cSStephen Smalley int mls_from_string(struct policydb *p, char *str, struct context *context,
46aa8e712cSStephen Smalley gfp_t gfp_mask);
47376bd9cbSDarrel Goeddel
480719aaf5SGuido Trentalancia int mls_range_set(struct context *context, struct mls_range *range);
490719aaf5SGuido Trentalancia
501da177e4SLinus Torvalds int mls_convert_context(struct policydb *oldp,
511da177e4SLinus Torvalds struct policydb *newp,
52ee1a84fdSOndrej Mosnacek struct context *oldc,
53ee1a84fdSOndrej Mosnacek struct context *newc);
541da177e4SLinus Torvalds
55aa8e712cSStephen Smalley int mls_compute_sid(struct policydb *p,
56aa8e712cSStephen Smalley struct context *scontext,
571da177e4SLinus Torvalds struct context *tcontext,
581da177e4SLinus Torvalds u16 tclass,
591da177e4SLinus Torvalds u32 specified,
606f5317e7SHarry Ciao struct context *newcontext,
616f5317e7SHarry Ciao bool sock);
621da177e4SLinus Torvalds
63aa8e712cSStephen Smalley int mls_setup_user_range(struct policydb *p,
64aa8e712cSStephen Smalley struct context *fromcon, struct user_datum *user,
651da177e4SLinus Torvalds struct context *usercon);
661da177e4SLinus Torvalds
6702752760SPaul Moore #ifdef CONFIG_NETLABEL
68aa8e712cSStephen Smalley void mls_export_netlbl_lvl(struct policydb *p,
69aa8e712cSStephen Smalley struct context *context,
7002752760SPaul Moore struct netlbl_lsm_secattr *secattr);
71aa8e712cSStephen Smalley void mls_import_netlbl_lvl(struct policydb *p,
72aa8e712cSStephen Smalley struct context *context,
7302752760SPaul Moore struct netlbl_lsm_secattr *secattr);
74aa8e712cSStephen Smalley int mls_export_netlbl_cat(struct policydb *p,
75aa8e712cSStephen Smalley struct context *context,
7602752760SPaul Moore struct netlbl_lsm_secattr *secattr);
77aa8e712cSStephen Smalley int mls_import_netlbl_cat(struct policydb *p,
78aa8e712cSStephen Smalley struct context *context,
7902752760SPaul Moore struct netlbl_lsm_secattr *secattr);
8002752760SPaul Moore #else
mls_export_netlbl_lvl(struct policydb * p,struct context * context,struct netlbl_lsm_secattr * secattr)81aa8e712cSStephen Smalley static inline void mls_export_netlbl_lvl(struct policydb *p,
82aa8e712cSStephen Smalley struct context *context,
8302752760SPaul Moore struct netlbl_lsm_secattr *secattr)
8402752760SPaul Moore {
8502752760SPaul Moore return;
8602752760SPaul Moore }
mls_import_netlbl_lvl(struct policydb * p,struct context * context,struct netlbl_lsm_secattr * secattr)87aa8e712cSStephen Smalley static inline void mls_import_netlbl_lvl(struct policydb *p,
88aa8e712cSStephen Smalley struct context *context,
8902752760SPaul Moore struct netlbl_lsm_secattr *secattr)
9002752760SPaul Moore {
9102752760SPaul Moore return;
9202752760SPaul Moore }
mls_export_netlbl_cat(struct policydb * p,struct context * context,struct netlbl_lsm_secattr * secattr)93aa8e712cSStephen Smalley static inline int mls_export_netlbl_cat(struct policydb *p,
94aa8e712cSStephen Smalley struct context *context,
9502752760SPaul Moore struct netlbl_lsm_secattr *secattr)
9602752760SPaul Moore {
9702752760SPaul Moore return -ENOMEM;
9802752760SPaul Moore }
mls_import_netlbl_cat(struct policydb * p,struct context * context,struct netlbl_lsm_secattr * secattr)99aa8e712cSStephen Smalley static inline int mls_import_netlbl_cat(struct policydb *p,
100aa8e712cSStephen Smalley struct context *context,
10102752760SPaul Moore struct netlbl_lsm_secattr *secattr)
10202752760SPaul Moore {
10302752760SPaul Moore return -ENOMEM;
10402752760SPaul Moore }
10502752760SPaul Moore #endif
1067420ed23SVenkat Yekkirala
mls_range_hash(const struct mls_range * r,u32 hash)10750077289SOndrej Mosnacek static inline u32 mls_range_hash(const struct mls_range *r, u32 hash)
10850077289SOndrej Mosnacek {
10950077289SOndrej Mosnacek hash = jhash_2words(r->level[0].sens, r->level[1].sens, hash);
11050077289SOndrej Mosnacek hash = ebitmap_hash(&r->level[0].cat, hash);
11150077289SOndrej Mosnacek hash = ebitmap_hash(&r->level[1].cat, hash);
11250077289SOndrej Mosnacek return hash;
11350077289SOndrej Mosnacek }
11450077289SOndrej Mosnacek
1151da177e4SLinus Torvalds #endif /* _SS_MLS_H */
1161da177e4SLinus Torvalds
117