23
23
*/
24
24
static int cond_evaluate_expr (struct policydb * p , struct cond_expr * expr )
25
25
{
26
-
27
- struct cond_expr * cur ;
26
+ u32 i ;
28
27
int s [COND_EXPR_MAXDEPTH ];
29
28
int sp = -1 ;
30
29
31
- for (cur = expr ; cur ; cur = cur -> next ) {
32
- switch (cur -> expr_type ) {
30
+ for (i = 0 ; i < expr -> len ; i ++ ) {
31
+ struct cond_expr_node * node = & expr -> nodes [i ];
32
+
33
+ switch (node -> expr_type ) {
33
34
case COND_BOOL :
34
35
if (sp == (COND_EXPR_MAXDEPTH - 1 ))
35
36
return -1 ;
36
37
sp ++ ;
37
- s [sp ] = p -> bool_val_to_struct [cur -> bool - 1 ]-> state ;
38
+ s [sp ] = p -> bool_val_to_struct [node -> bool - 1 ]-> state ;
38
39
break ;
39
40
case COND_NOT :
40
41
if (sp < 0 )
@@ -91,7 +92,7 @@ void evaluate_cond_node(struct policydb *p, struct cond_node *node)
91
92
int new_state ;
92
93
u32 i ;
93
94
94
- new_state = cond_evaluate_expr (p , node -> expr );
95
+ new_state = cond_evaluate_expr (p , & node -> expr );
95
96
if (new_state != node -> cur_state ) {
96
97
node -> cur_state = new_state ;
97
98
if (new_state == -1 )
@@ -133,12 +134,7 @@ int cond_policydb_init(struct policydb *p)
133
134
134
135
static void cond_node_destroy (struct cond_node * node )
135
136
{
136
- struct cond_expr * cur_expr , * next_expr ;
137
-
138
- for (cur_expr = node -> expr ; cur_expr ; cur_expr = next_expr ) {
139
- next_expr = cur_expr -> next ;
140
- kfree (cur_expr );
141
- }
137
+ kfree (node -> expr .nodes );
142
138
/* the avtab_ptr_t nodes are destroyed by the avtab */
143
139
kfree (node -> true_list .nodes );
144
140
kfree (node -> false_list .nodes );
@@ -355,7 +351,7 @@ static int cond_read_av_list(struct policydb *p, void *fp,
355
351
return 0 ;
356
352
}
357
353
358
- static int expr_isvalid (struct policydb * p , struct cond_expr * expr )
354
+ static int expr_node_isvalid (struct policydb * p , struct cond_expr_node * expr )
359
355
{
360
356
if (expr -> expr_type <= 0 || expr -> expr_type > COND_LAST ) {
361
357
pr_err ("SELinux: conditional expressions uses unknown operator.\n" );
@@ -372,43 +368,37 @@ static int expr_isvalid(struct policydb *p, struct cond_expr *expr)
372
368
static int cond_read_node (struct policydb * p , struct cond_node * node , void * fp )
373
369
{
374
370
__le32 buf [2 ];
375
- u32 len , i ;
371
+ u32 i , len ;
376
372
int rc ;
377
- struct cond_expr * expr = NULL , * last = NULL ;
378
373
379
374
rc = next_entry (buf , fp , sizeof (u32 ) * 2 );
380
375
if (rc )
381
- goto err ;
376
+ return rc ;
382
377
383
378
node -> cur_state = le32_to_cpu (buf [0 ]);
384
379
385
380
/* expr */
386
381
len = le32_to_cpu (buf [1 ]);
382
+ node -> expr .nodes = kcalloc (len , sizeof (* node -> expr .nodes ), GFP_KERNEL );
383
+ if (!node -> expr .nodes )
384
+ return - ENOMEM ;
385
+
386
+ node -> expr .len = len ;
387
387
388
388
for (i = 0 ; i < len ; i ++ ) {
389
+ struct cond_expr_node * expr = & node -> expr .nodes [i ];
390
+
389
391
rc = next_entry (buf , fp , sizeof (u32 ) * 2 );
390
392
if (rc )
391
393
goto err ;
392
394
393
- rc = - ENOMEM ;
394
- expr = kzalloc (sizeof (* expr ), GFP_KERNEL );
395
- if (!expr )
396
- goto err ;
397
-
398
395
expr -> expr_type = le32_to_cpu (buf [0 ]);
399
396
expr -> bool = le32_to_cpu (buf [1 ]);
400
397
401
- if (!expr_isvalid (p , expr )) {
398
+ if (!expr_node_isvalid (p , expr )) {
402
399
rc = - EINVAL ;
403
- kfree (expr );
404
400
goto err ;
405
401
}
406
-
407
- if (i == 0 )
408
- node -> expr = expr ;
409
- else
410
- last -> next = expr ;
411
- last = expr ;
412
402
}
413
403
414
404
rc = cond_read_av_list (p , fp , & node -> true_list , NULL );
@@ -513,27 +503,23 @@ static int cond_write_av_list(struct policydb *p,
513
503
static int cond_write_node (struct policydb * p , struct cond_node * node ,
514
504
struct policy_file * fp )
515
505
{
516
- struct cond_expr * cur_expr ;
517
506
__le32 buf [2 ];
518
507
int rc ;
519
- u32 len = 0 ;
508
+ u32 i ;
520
509
521
510
buf [0 ] = cpu_to_le32 (node -> cur_state );
522
511
rc = put_entry (buf , sizeof (u32 ), 1 , fp );
523
512
if (rc )
524
513
return rc ;
525
514
526
- for (cur_expr = node -> expr ; cur_expr != NULL ; cur_expr = cur_expr -> next )
527
- len ++ ;
528
-
529
- buf [0 ] = cpu_to_le32 (len );
515
+ buf [0 ] = cpu_to_le32 (node -> expr .len );
530
516
rc = put_entry (buf , sizeof (u32 ), 1 , fp );
531
517
if (rc )
532
518
return rc ;
533
519
534
- for (cur_expr = node -> expr ; cur_expr != NULL ; cur_expr = cur_expr -> next ) {
535
- buf [0 ] = cpu_to_le32 (cur_expr -> expr_type );
536
- buf [1 ] = cpu_to_le32 (cur_expr -> bool );
520
+ for (i = 0 ; i < node -> expr . len ; i ++ ) {
521
+ buf [0 ] = cpu_to_le32 (node -> expr . nodes [ i ]. expr_type );
522
+ buf [1 ] = cpu_to_le32 (node -> expr . nodes [ i ]. bool );
537
523
rc = put_entry (buf , sizeof (u32 ), 2 , fp );
538
524
if (rc )
539
525
return rc ;
0 commit comments