|
32 | 32 | int mls_compute_context_len(struct policydb *p, struct context *context) |
33 | 33 | { |
34 | 34 | int i, l, len, head, prev; |
35 | | - char *nm; |
| 35 | + const char *nm; |
36 | 36 | struct ebitmap *e; |
37 | 37 | struct ebitmap_node *node; |
38 | 38 |
|
@@ -86,7 +86,8 @@ int mls_compute_context_len(struct policydb *p, struct context *context) |
86 | 86 | void mls_sid_to_context(struct policydb *p, struct context *context, |
87 | 87 | char **scontext) |
88 | 88 | { |
89 | | - char *scontextp, *nm; |
| 89 | + const char *nm; |
| 90 | + char *scontextp; |
90 | 91 | int i, l, head, prev; |
91 | 92 | struct ebitmap *e; |
92 | 93 | struct ebitmap_node *node; |
@@ -155,60 +156,77 @@ void mls_sid_to_context(struct policydb *p, struct context *context, |
155 | 156 | *scontext = scontextp; |
156 | 157 | } |
157 | 158 |
|
158 | | -int mls_level_isvalid(struct policydb *p, struct mls_level *l) |
| 159 | +bool mls_level_isvalid(const struct policydb *p, const struct mls_level *l) |
159 | 160 | { |
160 | | - struct level_datum *levdatum; |
| 161 | + const char *name; |
| 162 | + const struct level_datum *levdatum; |
| 163 | + struct ebitmap_node *node; |
| 164 | + u32 bit; |
| 165 | + int rc; |
161 | 166 |
|
162 | 167 | if (!l->sens || l->sens > p->p_levels.nprim) |
163 | | - return 0; |
164 | | - levdatum = symtab_search(&p->p_levels, |
165 | | - sym_name(p, SYM_LEVELS, l->sens - 1)); |
| 168 | + return false; |
| 169 | + |
| 170 | + name = sym_name(p, SYM_LEVELS, l->sens - 1); |
| 171 | + if (!name) |
| 172 | + return false; |
| 173 | + |
| 174 | + levdatum = symtab_search(&p->p_levels, name); |
166 | 175 | if (!levdatum) |
167 | | - return 0; |
| 176 | + return false; |
168 | 177 |
|
169 | 178 | /* |
170 | | - * Return 1 iff all the bits set in l->cat are also be set in |
| 179 | + * Validate that all bits set in l->cat are also be set in |
171 | 180 | * levdatum->level->cat and no bit in l->cat is larger than |
172 | 181 | * p->p_cats.nprim. |
173 | 182 | */ |
174 | | - return ebitmap_contains(&levdatum->level.cat, &l->cat, |
175 | | - p->p_cats.nprim); |
| 183 | + rc = ebitmap_contains(&levdatum->level.cat, &l->cat, |
| 184 | + p->p_cats.nprim); |
| 185 | + if (!rc) |
| 186 | + return false; |
| 187 | + |
| 188 | + ebitmap_for_each_positive_bit(&levdatum->level.cat, node, bit) { |
| 189 | + if (!sym_name(p, SYM_CATS, bit)) |
| 190 | + return false; |
| 191 | + } |
| 192 | + |
| 193 | + return true; |
176 | 194 | } |
177 | 195 |
|
178 | | -int mls_range_isvalid(struct policydb *p, struct mls_range *r) |
| 196 | +bool mls_range_isvalid(const struct policydb *p, const struct mls_range *r) |
179 | 197 | { |
180 | 198 | return (mls_level_isvalid(p, &r->level[0]) && |
181 | 199 | mls_level_isvalid(p, &r->level[1]) && |
182 | 200 | mls_level_dom(&r->level[1], &r->level[0])); |
183 | 201 | } |
184 | 202 |
|
185 | 203 | /* |
186 | | - * Return 1 if the MLS fields in the security context |
| 204 | + * Return true if the MLS fields in the security context |
187 | 205 | * structure `c' are valid. Return 0 otherwise. |
188 | 206 | */ |
189 | | -int mls_context_isvalid(struct policydb *p, struct context *c) |
| 207 | +bool mls_context_isvalid(const struct policydb *p, const struct context *c) |
190 | 208 | { |
191 | | - struct user_datum *usrdatum; |
| 209 | + const struct user_datum *usrdatum; |
192 | 210 |
|
193 | 211 | if (!p->mls_enabled) |
194 | | - return 1; |
| 212 | + return true; |
195 | 213 |
|
196 | 214 | if (!mls_range_isvalid(p, &c->range)) |
197 | | - return 0; |
| 215 | + return false; |
198 | 216 |
|
199 | 217 | if (c->role == OBJECT_R_VAL) |
200 | | - return 1; |
| 218 | + return true; |
201 | 219 |
|
202 | 220 | /* |
203 | 221 | * User must be authorized for the MLS range. |
204 | 222 | */ |
205 | 223 | if (!c->user || c->user > p->p_users.nprim) |
206 | | - return 0; |
| 224 | + return false; |
207 | 225 | usrdatum = p->user_val_to_struct[c->user - 1]; |
208 | | - if (!mls_range_contains(usrdatum->range, c->range)) |
209 | | - return 0; /* user may not be associated with range */ |
| 226 | + if (!usrdatum || !mls_range_contains(usrdatum->range, c->range)) |
| 227 | + return false; /* user may not be associated with range */ |
210 | 228 |
|
211 | | - return 1; |
| 229 | + return true; |
212 | 230 | } |
213 | 231 |
|
214 | 232 | /* |
@@ -449,8 +467,8 @@ int mls_convert_context(struct policydb *oldp, struct policydb *newp, |
449 | 467 | return 0; |
450 | 468 |
|
451 | 469 | for (l = 0; l < 2; l++) { |
452 | | - char *name = sym_name(oldp, SYM_LEVELS, |
453 | | - oldc->range.level[l].sens - 1); |
| 470 | + const char *name = sym_name(oldp, SYM_LEVELS, |
| 471 | + oldc->range.level[l].sens - 1); |
454 | 472 |
|
455 | 473 | levdatum = symtab_search(&newp->p_levels, name); |
456 | 474 |
|
|
0 commit comments