diff options
Diffstat (limited to 'security/selinux/ss/conditional.c')
-rw-r--r-- | security/selinux/ss/conditional.c | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c index 4a4e35cac22..c91e150c308 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c | |||
@@ -117,10 +117,14 @@ int evaluate_cond_node(struct policydb *p, struct cond_node *node) | |||
117 | 117 | ||
118 | int cond_policydb_init(struct policydb *p) | 118 | int cond_policydb_init(struct policydb *p) |
119 | { | 119 | { |
120 | int rc; | ||
121 | |||
120 | p->bool_val_to_struct = NULL; | 122 | p->bool_val_to_struct = NULL; |
121 | p->cond_list = NULL; | 123 | p->cond_list = NULL; |
122 | if (avtab_init(&p->te_cond_avtab)) | 124 | |
123 | return -1; | 125 | rc = avtab_init(&p->te_cond_avtab); |
126 | if (rc) | ||
127 | return rc; | ||
124 | 128 | ||
125 | return 0; | 129 | return 0; |
126 | } | 130 | } |
@@ -219,34 +223,37 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp) | |||
219 | 223 | ||
220 | booldatum = kzalloc(sizeof(struct cond_bool_datum), GFP_KERNEL); | 224 | booldatum = kzalloc(sizeof(struct cond_bool_datum), GFP_KERNEL); |
221 | if (!booldatum) | 225 | if (!booldatum) |
222 | return -1; | 226 | return -ENOMEM; |
223 | 227 | ||
224 | rc = next_entry(buf, fp, sizeof buf); | 228 | rc = next_entry(buf, fp, sizeof buf); |
225 | if (rc < 0) | 229 | if (rc) |
226 | goto err; | 230 | goto err; |
227 | 231 | ||
228 | booldatum->value = le32_to_cpu(buf[0]); | 232 | booldatum->value = le32_to_cpu(buf[0]); |
229 | booldatum->state = le32_to_cpu(buf[1]); | 233 | booldatum->state = le32_to_cpu(buf[1]); |
230 | 234 | ||
235 | rc = -EINVAL; | ||
231 | if (!bool_isvalid(booldatum)) | 236 | if (!bool_isvalid(booldatum)) |
232 | goto err; | 237 | goto err; |
233 | 238 | ||
234 | len = le32_to_cpu(buf[2]); | 239 | len = le32_to_cpu(buf[2]); |
235 | 240 | ||
241 | rc = -ENOMEM; | ||
236 | key = kmalloc(len + 1, GFP_KERNEL); | 242 | key = kmalloc(len + 1, GFP_KERNEL); |
237 | if (!key) | 243 | if (!key) |
238 | goto err; | 244 | goto err; |
239 | rc = next_entry(key, fp, len); | 245 | rc = next_entry(key, fp, len); |
240 | if (rc < 0) | 246 | if (rc) |
241 | goto err; | 247 | goto err; |
242 | key[len] = '\0'; | 248 | key[len] = '\0'; |
243 | if (hashtab_insert(h, key, booldatum)) | 249 | rc = hashtab_insert(h, key, booldatum); |
250 | if (rc) | ||
244 | goto err; | 251 | goto err; |
245 | 252 | ||
246 | return 0; | 253 | return 0; |
247 | err: | 254 | err: |
248 | cond_destroy_bool(key, booldatum, NULL); | 255 | cond_destroy_bool(key, booldatum, NULL); |
249 | return -1; | 256 | return rc; |
250 | } | 257 | } |
251 | 258 | ||
252 | struct cond_insertf_data { | 259 | struct cond_insertf_data { |
@@ -263,7 +270,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum | |||
263 | struct cond_av_list *other = data->other, *list, *cur; | 270 | struct cond_av_list *other = data->other, *list, *cur; |
264 | struct avtab_node *node_ptr; | 271 | struct avtab_node *node_ptr; |
265 | u8 found; | 272 | u8 found; |
266 | 273 | int rc = -EINVAL; | |
267 | 274 | ||
268 | /* | 275 | /* |
269 | * For type rules we have to make certain there aren't any | 276 | * For type rules we have to make certain there aren't any |
@@ -313,12 +320,15 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum | |||
313 | node_ptr = avtab_insert_nonunique(&p->te_cond_avtab, k, d); | 320 | node_ptr = avtab_insert_nonunique(&p->te_cond_avtab, k, d); |
314 | if (!node_ptr) { | 321 | if (!node_ptr) { |
315 | printk(KERN_ERR "SELinux: could not insert rule.\n"); | 322 | printk(KERN_ERR "SELinux: could not insert rule.\n"); |
323 | rc = -ENOMEM; | ||
316 | goto err; | 324 | goto err; |
317 | } | 325 | } |
318 | 326 | ||
319 | list = kzalloc(sizeof(struct cond_av_list), GFP_KERNEL); | 327 | list = kzalloc(sizeof(struct cond_av_list), GFP_KERNEL); |
320 | if (!list) | 328 | if (!list) { |
329 | rc = -ENOMEM; | ||
321 | goto err; | 330 | goto err; |
331 | } | ||
322 | 332 | ||
323 | list->node = node_ptr; | 333 | list->node = node_ptr; |
324 | if (!data->head) | 334 | if (!data->head) |
@@ -331,7 +341,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum | |||
331 | err: | 341 | err: |
332 | cond_av_list_destroy(data->head); | 342 | cond_av_list_destroy(data->head); |
333 | data->head = NULL; | 343 | data->head = NULL; |
334 | return -1; | 344 | return rc; |
335 | } | 345 | } |
336 | 346 | ||
337 | static int cond_read_av_list(struct policydb *p, void *fp, struct cond_av_list **ret_list, struct cond_av_list *other) | 347 | static int cond_read_av_list(struct policydb *p, void *fp, struct cond_av_list **ret_list, struct cond_av_list *other) |
@@ -345,8 +355,8 @@ static int cond_read_av_list(struct policydb *p, void *fp, struct cond_av_list * | |||
345 | 355 | ||
346 | len = 0; | 356 | len = 0; |
347 | rc = next_entry(buf, fp, sizeof(u32)); | 357 | rc = next_entry(buf, fp, sizeof(u32)); |
348 | if (rc < 0) | 358 | if (rc) |
349 | return -1; | 359 | return rc; |
350 | 360 | ||
351 | len = le32_to_cpu(buf[0]); | 361 | len = le32_to_cpu(buf[0]); |
352 | if (len == 0) | 362 | if (len == 0) |
@@ -361,7 +371,6 @@ static int cond_read_av_list(struct policydb *p, void *fp, struct cond_av_list * | |||
361 | &data); | 371 | &data); |
362 | if (rc) | 372 | if (rc) |
363 | return rc; | 373 | return rc; |
364 | |||
365 | } | 374 | } |
366 | 375 | ||
367 | *ret_list = data.head; | 376 | *ret_list = data.head; |
@@ -390,24 +399,25 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp) | |||
390 | struct cond_expr *expr = NULL, *last = NULL; | 399 | struct cond_expr *expr = NULL, *last = NULL; |
391 | 400 | ||
392 | rc = next_entry(buf, fp, sizeof(u32)); | 401 | rc = next_entry(buf, fp, sizeof(u32)); |
393 | if (rc < 0) | 402 | if (rc) |
394 | return -1; | 403 | return rc; |
395 | 404 | ||
396 | node->cur_state = le32_to_cpu(buf[0]); | 405 | node->cur_state = le32_to_cpu(buf[0]); |
397 | 406 | ||
398 | len = 0; | 407 | len = 0; |
399 | rc = next_entry(buf, fp, sizeof(u32)); | 408 | rc = next_entry(buf, fp, sizeof(u32)); |
400 | if (rc < 0) | 409 | if (rc) |
401 | return -1; | 410 | return rc; |
402 | 411 | ||
403 | /* expr */ | 412 | /* expr */ |
404 | len = le32_to_cpu(buf[0]); | 413 | len = le32_to_cpu(buf[0]); |
405 | 414 | ||
406 | for (i = 0; i < len; i++) { | 415 | for (i = 0; i < len; i++) { |
407 | rc = next_entry(buf, fp, sizeof(u32) * 2); | 416 | rc = next_entry(buf, fp, sizeof(u32) * 2); |
408 | if (rc < 0) | 417 | if (rc) |
409 | goto err; | 418 | goto err; |
410 | 419 | ||
420 | rc = -ENOMEM; | ||
411 | expr = kzalloc(sizeof(struct cond_expr), GFP_KERNEL); | 421 | expr = kzalloc(sizeof(struct cond_expr), GFP_KERNEL); |
412 | if (!expr) | 422 | if (!expr) |
413 | goto err; | 423 | goto err; |
@@ -416,6 +426,7 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp) | |||
416 | expr->bool = le32_to_cpu(buf[1]); | 426 | expr->bool = le32_to_cpu(buf[1]); |
417 | 427 | ||
418 | if (!expr_isvalid(p, expr)) { | 428 | if (!expr_isvalid(p, expr)) { |
429 | rc = -EINVAL; | ||
419 | kfree(expr); | 430 | kfree(expr); |
420 | goto err; | 431 | goto err; |
421 | } | 432 | } |
@@ -427,14 +438,16 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp) | |||
427 | last = expr; | 438 | last = expr; |
428 | } | 439 | } |
429 | 440 | ||
430 | if (cond_read_av_list(p, fp, &node->true_list, NULL) != 0) | 441 | rc = cond_read_av_list(p, fp, &node->true_list, NULL); |
442 | if (rc) | ||
431 | goto err; | 443 | goto err; |
432 | if (cond_read_av_list(p, fp, &node->false_list, node->true_list) != 0) | 444 | rc = cond_read_av_list(p, fp, &node->false_list, node->true_list); |
445 | if (rc) | ||
433 | goto err; | 446 | goto err; |
434 | return 0; | 447 | return 0; |
435 | err: | 448 | err: |
436 | cond_node_destroy(node); | 449 | cond_node_destroy(node); |
437 | return -1; | 450 | return rc; |
438 | } | 451 | } |
439 | 452 | ||
440 | int cond_read_list(struct policydb *p, void *fp) | 453 | int cond_read_list(struct policydb *p, void *fp) |
@@ -445,8 +458,8 @@ int cond_read_list(struct policydb *p, void *fp) | |||
445 | int rc; | 458 | int rc; |
446 | 459 | ||
447 | rc = next_entry(buf, fp, sizeof buf); | 460 | rc = next_entry(buf, fp, sizeof buf); |
448 | if (rc < 0) | 461 | if (rc) |
449 | return -1; | 462 | return rc; |
450 | 463 | ||
451 | len = le32_to_cpu(buf[0]); | 464 | len = le32_to_cpu(buf[0]); |
452 | 465 | ||
@@ -455,11 +468,13 @@ int cond_read_list(struct policydb *p, void *fp) | |||
455 | goto err; | 468 | goto err; |
456 | 469 | ||
457 | for (i = 0; i < len; i++) { | 470 | for (i = 0; i < len; i++) { |
471 | rc = -ENOMEM; | ||
458 | node = kzalloc(sizeof(struct cond_node), GFP_KERNEL); | 472 | node = kzalloc(sizeof(struct cond_node), GFP_KERNEL); |
459 | if (!node) | 473 | if (!node) |
460 | goto err; | 474 | goto err; |
461 | 475 | ||
462 | if (cond_read_node(p, node, fp) != 0) | 476 | rc = cond_read_node(p, node, fp); |
477 | if (rc) | ||
463 | goto err; | 478 | goto err; |
464 | 479 | ||
465 | if (i == 0) | 480 | if (i == 0) |
@@ -472,7 +487,7 @@ int cond_read_list(struct policydb *p, void *fp) | |||
472 | err: | 487 | err: |
473 | cond_list_destroy(p->cond_list); | 488 | cond_list_destroy(p->cond_list); |
474 | p->cond_list = NULL; | 489 | p->cond_list = NULL; |
475 | return -1; | 490 | return rc; |
476 | } | 491 | } |
477 | 492 | ||
478 | /* Determine whether additional permissions are granted by the conditional | 493 | /* Determine whether additional permissions are granted by the conditional |