diff options
| author | Guido Trentalancia <guido@trentalancia.com> | 2010-02-03 10:40:20 -0500 |
|---|---|---|
| committer | James Morris <jmorris@namei.org> | 2010-02-03 17:06:36 -0500 |
| commit | 0719aaf5ead7555b7b7a4a080ebf2826a871384e (patch) | |
| tree | 19c0b16b1013d84a8b8092737d38e60f3dd7e939 | |
| parent | 42596eafdd75257a640f64701b9b07090bcd84b0 (diff) | |
selinux: allow MLS->non-MLS and vice versa upon policy reload
Allow runtime switching between different policy types (e.g. from a MLS/MCS
policy to a non-MLS/non-MCS policy or viceversa).
Signed-off-by: Guido Trentalancia <guido@trentalancia.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
| -rw-r--r-- | security/selinux/include/security.h | 3 | ||||
| -rw-r--r-- | security/selinux/selinuxfs.c | 3 | ||||
| -rw-r--r-- | security/selinux/ss/context.h | 12 | ||||
| -rw-r--r-- | security/selinux/ss/mls.c | 26 | ||||
| -rw-r--r-- | security/selinux/ss/mls.h | 2 | ||||
| -rw-r--r-- | security/selinux/ss/mls_types.h | 7 | ||||
| -rw-r--r-- | security/selinux/ss/policydb.c | 24 | ||||
| -rw-r--r-- | security/selinux/ss/policydb.h | 4 | ||||
| -rw-r--r-- | security/selinux/ss/services.c | 62 |
9 files changed, 84 insertions, 59 deletions
diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h index 022cf067aa3f..1f7c2491d3dc 100644 --- a/security/selinux/include/security.h +++ b/security/selinux/include/security.h | |||
| @@ -57,7 +57,6 @@ | |||
| 57 | struct netlbl_lsm_secattr; | 57 | struct netlbl_lsm_secattr; |
| 58 | 58 | ||
| 59 | extern int selinux_enabled; | 59 | extern int selinux_enabled; |
| 60 | extern int selinux_mls_enabled; | ||
| 61 | 60 | ||
| 62 | /* Policy capabilities */ | 61 | /* Policy capabilities */ |
| 63 | enum { | 62 | enum { |
| @@ -80,6 +79,8 @@ extern int selinux_policycap_openperm; | |||
| 80 | /* limitation of boundary depth */ | 79 | /* limitation of boundary depth */ |
| 81 | #define POLICYDB_BOUNDS_MAXDEPTH 4 | 80 | #define POLICYDB_BOUNDS_MAXDEPTH 4 |
| 82 | 81 | ||
| 82 | int security_mls_enabled(void); | ||
| 83 | |||
| 83 | int security_load_policy(void *data, size_t len); | 84 | int security_load_policy(void *data, size_t len); |
| 84 | 85 | ||
| 85 | int security_policycap_supported(unsigned int req_cap); | 86 | int security_policycap_supported(unsigned int req_cap); |
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index b7bb0f5ec07c..a1cfc464bbb9 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c | |||
| @@ -282,7 +282,8 @@ static ssize_t sel_read_mls(struct file *filp, char __user *buf, | |||
| 282 | char tmpbuf[TMPBUFLEN]; | 282 | char tmpbuf[TMPBUFLEN]; |
| 283 | ssize_t length; | 283 | ssize_t length; |
| 284 | 284 | ||
| 285 | length = scnprintf(tmpbuf, TMPBUFLEN, "%d", selinux_mls_enabled); | 285 | length = scnprintf(tmpbuf, TMPBUFLEN, "%d", |
| 286 | security_mls_enabled()); | ||
| 286 | return simple_read_from_buffer(buf, count, ppos, tmpbuf, length); | 287 | return simple_read_from_buffer(buf, count, ppos, tmpbuf, length); |
| 287 | } | 288 | } |
| 288 | 289 | ||
diff --git a/security/selinux/ss/context.h b/security/selinux/ss/context.h index d9dd7a2f6a8a..45e8fb0515f8 100644 --- a/security/selinux/ss/context.h +++ b/security/selinux/ss/context.h | |||
| @@ -41,9 +41,6 @@ static inline int mls_context_cpy(struct context *dst, struct context *src) | |||
| 41 | { | 41 | { |
| 42 | int rc; | 42 | int rc; |
| 43 | 43 | ||
| 44 | if (!selinux_mls_enabled) | ||
| 45 | return 0; | ||
| 46 | |||
| 47 | dst->range.level[0].sens = src->range.level[0].sens; | 44 | dst->range.level[0].sens = src->range.level[0].sens; |
| 48 | rc = ebitmap_cpy(&dst->range.level[0].cat, &src->range.level[0].cat); | 45 | rc = ebitmap_cpy(&dst->range.level[0].cat, &src->range.level[0].cat); |
| 49 | if (rc) | 46 | if (rc) |
| @@ -64,9 +61,6 @@ static inline int mls_context_cpy_low(struct context *dst, struct context *src) | |||
| 64 | { | 61 | { |
| 65 | int rc; | 62 | int rc; |
| 66 | 63 | ||
| 67 | if (!selinux_mls_enabled) | ||
| 68 | return 0; | ||
| 69 | |||
| 70 | dst->range.level[0].sens = src->range.level[0].sens; | 64 | dst->range.level[0].sens = src->range.level[0].sens; |
| 71 | rc = ebitmap_cpy(&dst->range.level[0].cat, &src->range.level[0].cat); | 65 | rc = ebitmap_cpy(&dst->range.level[0].cat, &src->range.level[0].cat); |
| 72 | if (rc) | 66 | if (rc) |
| @@ -82,9 +76,6 @@ out: | |||
| 82 | 76 | ||
| 83 | static inline int mls_context_cmp(struct context *c1, struct context *c2) | 77 | static inline int mls_context_cmp(struct context *c1, struct context *c2) |
| 84 | { | 78 | { |
| 85 | if (!selinux_mls_enabled) | ||
| 86 | return 1; | ||
| 87 | |||
| 88 | return ((c1->range.level[0].sens == c2->range.level[0].sens) && | 79 | return ((c1->range.level[0].sens == c2->range.level[0].sens) && |
| 89 | ebitmap_cmp(&c1->range.level[0].cat, &c2->range.level[0].cat) && | 80 | ebitmap_cmp(&c1->range.level[0].cat, &c2->range.level[0].cat) && |
| 90 | (c1->range.level[1].sens == c2->range.level[1].sens) && | 81 | (c1->range.level[1].sens == c2->range.level[1].sens) && |
| @@ -93,9 +84,6 @@ static inline int mls_context_cmp(struct context *c1, struct context *c2) | |||
| 93 | 84 | ||
| 94 | static inline void mls_context_destroy(struct context *c) | 85 | static inline void mls_context_destroy(struct context *c) |
| 95 | { | 86 | { |
| 96 | if (!selinux_mls_enabled) | ||
| 97 | return; | ||
| 98 | |||
| 99 | ebitmap_destroy(&c->range.level[0].cat); | 87 | ebitmap_destroy(&c->range.level[0].cat); |
| 100 | ebitmap_destroy(&c->range.level[1].cat); | 88 | ebitmap_destroy(&c->range.level[1].cat); |
| 101 | mls_context_init(c); | 89 | mls_context_init(c); |
diff --git a/security/selinux/ss/mls.c b/security/selinux/ss/mls.c index 443ae7370144..372b773f8210 100644 --- a/security/selinux/ss/mls.c +++ b/security/selinux/ss/mls.c | |||
| @@ -39,7 +39,7 @@ int mls_compute_context_len(struct context *context) | |||
| 39 | struct ebitmap *e; | 39 | struct ebitmap *e; |
| 40 | struct ebitmap_node *node; | 40 | struct ebitmap_node *node; |
| 41 | 41 | ||
| 42 | if (!selinux_mls_enabled) | 42 | if (!policydb.mls_enabled) |
| 43 | return 0; | 43 | return 0; |
| 44 | 44 | ||
| 45 | len = 1; /* for the beginning ":" */ | 45 | len = 1; /* for the beginning ":" */ |
| @@ -93,7 +93,7 @@ void mls_sid_to_context(struct context *context, | |||
| 93 | struct ebitmap *e; | 93 | struct ebitmap *e; |
| 94 | struct ebitmap_node *node; | 94 | struct ebitmap_node *node; |
| 95 | 95 | ||
| 96 | if (!selinux_mls_enabled) | 96 | if (!policydb.mls_enabled) |
| 97 | return; | 97 | return; |
| 98 | 98 | ||
| 99 | scontextp = *scontext; | 99 | scontextp = *scontext; |
| @@ -200,7 +200,7 @@ int mls_context_isvalid(struct policydb *p, struct context *c) | |||
| 200 | { | 200 | { |
| 201 | struct user_datum *usrdatum; | 201 | struct user_datum *usrdatum; |
| 202 | 202 | ||
| 203 | if (!selinux_mls_enabled) | 203 | if (!p->mls_enabled) |
| 204 | return 1; | 204 | return 1; |
| 205 | 205 | ||
| 206 | if (!mls_range_isvalid(p, &c->range)) | 206 | if (!mls_range_isvalid(p, &c->range)) |
| @@ -253,7 +253,7 @@ int mls_context_to_sid(struct policydb *pol, | |||
| 253 | struct cat_datum *catdatum, *rngdatum; | 253 | struct cat_datum *catdatum, *rngdatum; |
| 254 | int l, rc = -EINVAL; | 254 | int l, rc = -EINVAL; |
| 255 | 255 | ||
| 256 | if (!selinux_mls_enabled) { | 256 | if (!pol->mls_enabled) { |
| 257 | if (def_sid != SECSID_NULL && oldc) | 257 | if (def_sid != SECSID_NULL && oldc) |
| 258 | *scontext += strlen(*scontext)+1; | 258 | *scontext += strlen(*scontext)+1; |
| 259 | return 0; | 259 | return 0; |
| @@ -387,7 +387,7 @@ int mls_from_string(char *str, struct context *context, gfp_t gfp_mask) | |||
| 387 | char *tmpstr, *freestr; | 387 | char *tmpstr, *freestr; |
| 388 | int rc; | 388 | int rc; |
| 389 | 389 | ||
| 390 | if (!selinux_mls_enabled) | 390 | if (!policydb.mls_enabled) |
| 391 | return -EINVAL; | 391 | return -EINVAL; |
| 392 | 392 | ||
| 393 | /* we need freestr because mls_context_to_sid will change | 393 | /* we need freestr because mls_context_to_sid will change |
| @@ -407,7 +407,7 @@ int mls_from_string(char *str, struct context *context, gfp_t gfp_mask) | |||
| 407 | /* | 407 | /* |
| 408 | * Copies the MLS range `range' into `context'. | 408 | * Copies the MLS range `range' into `context'. |
| 409 | */ | 409 | */ |
| 410 | static inline int mls_range_set(struct context *context, | 410 | int mls_range_set(struct context *context, |
| 411 | struct mls_range *range) | 411 | struct mls_range *range) |
| 412 | { | 412 | { |
| 413 | int l, rc = 0; | 413 | int l, rc = 0; |
| @@ -427,7 +427,7 @@ static inline int mls_range_set(struct context *context, | |||
| 427 | int mls_setup_user_range(struct context *fromcon, struct user_datum *user, | 427 | int mls_setup_user_range(struct context *fromcon, struct user_datum *user, |
| 428 | struct context *usercon) | 428 | struct context *usercon) |
| 429 | { | 429 | { |
| 430 | if (selinux_mls_enabled) { | 430 | if (policydb.mls_enabled) { |
| 431 | struct mls_level *fromcon_sen = &(fromcon->range.level[0]); | 431 | struct mls_level *fromcon_sen = &(fromcon->range.level[0]); |
| 432 | struct mls_level *fromcon_clr = &(fromcon->range.level[1]); | 432 | struct mls_level *fromcon_clr = &(fromcon->range.level[1]); |
| 433 | struct mls_level *user_low = &(user->range.level[0]); | 433 | struct mls_level *user_low = &(user->range.level[0]); |
| @@ -477,7 +477,7 @@ int mls_convert_context(struct policydb *oldp, | |||
| 477 | struct ebitmap_node *node; | 477 | struct ebitmap_node *node; |
| 478 | int l, i; | 478 | int l, i; |
| 479 | 479 | ||
| 480 | if (!selinux_mls_enabled) | 480 | if (!policydb.mls_enabled) |
| 481 | return 0; | 481 | return 0; |
