tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
/* Authors: Joshua Brindle <jbrindle@tresys.com>
 *         Jason Tang <jtang@tresys.com>
 *
 * Updates: KaiGai Kohei <kaigai@ak.jp.nec.com>
 *          adds checks based on newer boundary facility.
 *
 * A set of utility functions that aid policy decision when dealing
 * with hierarchal namespaces.
 *
 * Copyright (C) 2005 Tresys Technology, LLC
 *
 * Copyright (c) 2008 NEC Corporation
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <sepol/policydb/policydb.h>
#include <sepol/policydb/conditional.h>
#include <sepol/policydb/hierarchy.h>
#include <sepol/policydb/expand.h>
#include <sepol/policydb/util.h>
 
#include "debug.h"
 
#define BOUNDS_AVTAB_SIZE 1024
 
static int bounds_insert_helper(sepol_handle_t *handle, avtab_t *avtab,
               avtab_key_t *avtab_key, avtab_datum_t *datum)
{
   int rc = avtab_insert(avtab, avtab_key, datum);
   if (rc) {
       if (rc == SEPOL_ENOMEM)
           ERR(handle, "Insufficient memory");
       else
           ERR(handle, "Unexpected error (%d)", rc);
   }
   return rc;
}
 
 
static int bounds_insert_rule(sepol_handle_t *handle, avtab_t *avtab,
                 avtab_t *global, avtab_t *other,
                 avtab_key_t *avtab_key, avtab_datum_t *datum)
{
   int rc = 0;
   avtab_datum_t *dup = avtab_search(avtab, avtab_key);
 
   if (!dup) {
       rc = bounds_insert_helper(handle, avtab, avtab_key, datum);
       if (rc) goto exit;
   } else {
       dup->data |= datum->data;
   }
 
   if (other) {
       /* Search the other conditional avtab for the key and
        * add any common permissions to the global avtab
        */
       uint32_t data = 0;
       dup = avtab_search(other, avtab_key);
       if (dup) {
           data = dup->data & datum->data;
           if (data) {
               dup = avtab_search(global, avtab_key);
               if (!dup) {
                   avtab_datum_t d;
                   d.data = data;
                   rc = bounds_insert_helper(handle, global,
                                 avtab_key, &d);
                   if (rc) goto exit;
               } else {
                   dup->data |= data;
               }
           }
       }
   }
 
exit:
   return rc;
}
 
static int bounds_expand_rule(sepol_handle_t *handle, policydb_t *p,
                 avtab_t *avtab, avtab_t *global, avtab_t *other,
                 uint32_t parent, uint32_t src, uint32_t tgt,
                 uint32_t class, uint32_t data)
{
   int rc = 0;
   avtab_key_t avtab_key;
   avtab_datum_t datum;
   ebitmap_node_t *tnode;
   unsigned int i;
 
   avtab_key.specified = AVTAB_ALLOWED;
   avtab_key.target_class = class;
   datum.data = data;
 
   if (ebitmap_get_bit(&p->attr_type_map[src - 1], parent - 1)) {
       avtab_key.source_type = parent;
       ebitmap_for_each_bit(&p->attr_type_map[tgt - 1], tnode, i) {
           if (!ebitmap_node_get_bit(tnode, i))
               continue;
           avtab_key.target_type = i + 1;
           rc = bounds_insert_rule(handle, avtab, global, other,
                       &avtab_key, &datum);
           if (rc) goto exit;
       }
   }
 
exit:
   return rc;
}
 
static int bounds_expand_cond_rules(sepol_handle_t *handle, policydb_t *p,
                   cond_av_list_t *cur, avtab_t *avtab,
                   avtab_t *global, avtab_t *other,
                   uint32_t parent)
{
   int rc = 0;
 
   for (; cur; cur = cur->next) {
       avtab_ptr_t n = cur->node;
       rc = bounds_expand_rule(handle, p, avtab, global, other, parent,
                   n->key.source_type, n->key.target_type,
                   n->key.target_class, n->datum.data);
       if (rc) goto exit;
   }
 
exit:
   return rc;
}
 
struct bounds_expand_args {
   sepol_handle_t *handle;
   policydb_t *p;
   avtab_t *avtab;
   uint32_t parent;
};
 
static int bounds_expand_rule_callback(avtab_key_t *k, avtab_datum_t *d,
                      void *args)
{
   struct bounds_expand_args *a = (struct bounds_expand_args *)args;
 
   if (!(k->specified & AVTAB_ALLOWED))
       return 0;
 
   return bounds_expand_rule(a->handle, a->p, a->avtab, NULL, NULL,
                 a->parent, k->source_type, k->target_type,
                 k->target_class, d->data);
}
 
struct bounds_cond_info {
   avtab_t true_avtab;
   avtab_t false_avtab;
   cond_list_t *cond_list;
   struct bounds_cond_info *next;
};
 
static void bounds_destroy_cond_info(struct bounds_cond_info *cur)
{
   struct bounds_cond_info *next;
 
   for (; cur; cur = next) {
       next = cur->next;
       avtab_destroy(&cur->true_avtab);
       avtab_destroy(&cur->false_avtab);
       cur->next = NULL;
       free(cur);
   }
}
 
static int bounds_expand_parent_rules(sepol_handle_t *handle, policydb_t *p,
                     avtab_t *global_avtab,
                     struct bounds_cond_info **cond_info,
                     uint32_t parent)
{
   int rc = 0;
   struct bounds_expand_args args;
   cond_list_t *cur;
 
   avtab_init(global_avtab);
   rc = avtab_alloc(global_avtab, BOUNDS_AVTAB_SIZE);
   if (rc) goto oom;
 
   args.handle = handle;
   args.p = p;
   args.avtab = global_avtab;
   args.parent = parent;
   rc = avtab_map(&p->te_avtab, bounds_expand_rule_callback, &args);
   if (rc) goto exit;
 
   *cond_info = NULL;
   for (cur = p->cond_list; cur; cur = cur->next) {
       struct bounds_cond_info *ci;
       ci = malloc(sizeof(struct bounds_cond_info));
       if (!ci) goto oom;
       avtab_init(&ci->true_avtab);
       avtab_init(&ci->false_avtab);
       ci->cond_list = cur;
       ci->next = *cond_info;
       *cond_info = ci;
       if (cur->true_list) {
           rc = avtab_alloc(&ci->true_avtab, BOUNDS_AVTAB_SIZE);
           if (rc) goto oom;
           rc = bounds_expand_cond_rules(handle, p, cur->true_list,
                             &ci->true_avtab, NULL,
                             NULL, parent);
           if (rc) goto exit;
       }
       if (cur->false_list) {
           rc = avtab_alloc(&ci->false_avtab, BOUNDS_AVTAB_SIZE);
           if (rc) goto oom;
           rc = bounds_expand_cond_rules(handle, p, cur->false_list,
                             &ci->false_avtab,
                             global_avtab,
                             &ci->true_avtab, parent);
           if (rc) goto exit;
       }
   }
 
   return 0;
 
oom:
   ERR(handle, "Insufficient memory");
 
exit:
   ERR(handle,"Failed to expand parent rules\n");
   avtab_destroy(global_avtab);
   bounds_destroy_cond_info(*cond_info);
   *cond_info = NULL;
   return rc;
}
 
static int bounds_not_covered(avtab_t *global_avtab, avtab_t *cur_avtab,
                 avtab_key_t *avtab_key, uint32_t data)
{
   avtab_datum_t *datum = avtab_search(cur_avtab, avtab_key);
   if (datum)
       data &= ~datum->data;
   if (global_avtab && data) {
       datum = avtab_search(global_avtab, avtab_key);
       if (datum)
           data &= ~datum->data;
   }
 
   return data;
}
 
static int bounds_add_bad(sepol_handle_t *handle, uint32_t src, uint32_t tgt,
             uint32_t class, uint32_t data, avtab_ptr_t *bad)
{
   struct avtab_node *new = malloc(sizeof(struct avtab_node));
   if (new == NULL) {
       ERR(handle, "Insufficient memory");
       return SEPOL_ENOMEM;
   }
   memset(new, 0, sizeof(struct avtab_node));
   new->key.source_type = src;
   new->key.target_type = tgt;
   new->key.target_class = class;
   new->datum.data = data;
   new->next = *bad;
   *bad = new;
 
   return 0;
}
 
static int bounds_check_rule(sepol_handle_t *handle, policydb_t *p,
                avtab_t *global_avtab, avtab_t *cur_avtab,
                uint32_t child, uint32_t parent, uint32_t src,
                uint32_t tgt, uint32_t class, uint32_t data,
                avtab_ptr_t *bad, int *numbad)
{
   int rc = 0;
   avtab_key_t avtab_key;
   type_datum_t *td;
   ebitmap_node_t *tnode;
   unsigned int i;
   uint32_t d;
 
   avtab_key.specified = AVTAB_ALLOWED;
   avtab_key.target_class = class;
 
   if (ebitmap_get_bit(&p->attr_type_map[src - 1], child - 1)) {
       avtab_key.source_type = parent;
       ebitmap_for_each_bit(&p->attr_type_map[tgt - 1], tnode, i) {
           if (!ebitmap_node_get_bit(tnode, i))
               continue;
           td = p->type_val_to_struct[i];
           if (td && td->bounds) {
               avtab_key.target_type = td->bounds;
               d = bounds_not_covered(global_avtab, cur_avtab,
                              &avtab_key, data);
           } else {
               avtab_key.target_type = i + 1;
               d = bounds_not_covered(global_avtab, cur_avtab,
                              &avtab_key, data);
           }
           if (d) {
               (*numbad)++;
               rc = bounds_add_bad(handle, child, i+1, class, d, bad);
               if (rc) goto exit;
           }
       }
   }
 
exit:
   return rc;
}
 
static int bounds_check_cond_rules(sepol_handle_t *handle, policydb_t *p,
                  avtab_t *global_avtab, avtab_t *cond_avtab,
                  cond_av_list_t *rules, uint32_t child,
                  uint32_t parent, avtab_ptr_t *bad,
                  int *numbad)
{
   int rc = 0;
   cond_av_list_t *cur;
 
   for (cur = rules; cur; cur = cur->next) {
       avtab_ptr_t ap = cur->node;
       avtab_key_t *key = &ap->key;
       avtab_datum_t *datum = &ap->datum;
       if (!(key->specified & AVTAB_ALLOWED))
           continue;
       rc = bounds_check_rule(handle, p, global_avtab, cond_avtab,
                      child, parent, key->source_type,
                      key->target_type, key->target_class,
                      datum->data, bad, numbad);
       if (rc) goto exit;
   }
 
exit:
   return rc;
}
 
struct bounds_check_args {
   sepol_handle_t *handle;
   policydb_t *p;
   avtab_t *cur_avtab;
   uint32_t child;
   uint32_t parent;
   avtab_ptr_t bad;
   int numbad;
};
 
static int bounds_check_rule_callback(avtab_key_t *k, avtab_datum_t *d,
                     void *args)
{
   struct bounds_check_args *a = (struct bounds_check_args *)args;
 
   if (!(k->specified & AVTAB_ALLOWED))
       return 0;
 
   return bounds_check_rule(a->handle, a->p, NULL, a->cur_avtab, a->child,
                a->parent, k->source_type, k->target_type,
                k->target_class, d->data, &a->bad, &a->numbad);
}
 
static int bounds_check_child_rules(sepol_handle_t *handle, policydb_t *p,
                   avtab_t *global_avtab,
                   struct bounds_cond_info *cond_info,
                   uint32_t child, uint32_t parent,
                   avtab_ptr_t *bad, int *numbad)
{
   int rc;
   struct bounds_check_args args;
   struct bounds_cond_info *cur;
 
   args.handle = handle;
   args.p = p;
   args.cur_avtab = global_avtab;
   args.child = child;
   args.parent = parent;
   args.bad = NULL;
   args.numbad = 0;
   rc = avtab_map(&p->te_avtab, bounds_check_rule_callback, &args);
   if (rc) goto exit;
 
   for (cur = cond_info; cur; cur = cur->next) {
       cond_list_t *node = cur->cond_list;
       rc = bounds_check_cond_rules(handle, p, global_avtab,
                        &cur->true_avtab,
                        node->true_list, child, parent,
                        &args.bad, &args.numbad);
       if (rc) goto exit;
 
       rc = bounds_check_cond_rules(handle, p, global_avtab,
                        &cur->false_avtab,
                        node->false_list, child, parent,
                        &args.bad, &args.numbad);
       if (rc) goto exit;
   }
 
   *numbad += args.numbad;
   *bad = args.bad;
 
exit:
   return rc;
}
 
int bounds_check_type(sepol_handle_t *handle, policydb_t *p, uint32_t child,
             uint32_t parent, avtab_ptr_t *bad, int *numbad)
{
   int rc = 0;
   avtab_t global_avtab;
   struct bounds_cond_info *cond_info = NULL;
 
   rc = bounds_expand_parent_rules(handle, p, &global_avtab, &cond_info, parent);
   if (rc) goto exit;
 
   rc = bounds_check_child_rules(handle, p, &global_avtab, cond_info,
                     child, parent, bad, numbad);
 
   bounds_destroy_cond_info(cond_info);
   avtab_destroy(&global_avtab);
 
exit:
   return rc;
}
 
struct bounds_args {
   sepol_handle_t *handle;
   policydb_t *p;
   int numbad;
};
 
static void bounds_report(sepol_handle_t *handle, policydb_t *p, uint32_t child,
             uint32_t parent, avtab_ptr_t cur)
{
   ERR(handle, "Child type %s exceeds bounds of parent %s in the following rules:",
       p->p_type_val_to_name[child - 1],
       p->p_type_val_to_name[parent - 1]);
   for (; cur; cur = cur->next) {
       ERR(handle, "    %s %s : %s { %s }",
           p->p_type_val_to_name[cur->key.source_type - 1],
           p->p_type_val_to_name[cur->key.target_type - 1],
           p->p_class_val_to_name[cur->key.target_class - 1],
           sepol_av_to_string(p, cur->key.target_class,
                      cur->datum.data));
   }
}
 
void bounds_destroy_bad(avtab_ptr_t cur)
{
   avtab_ptr_t next;
 
   for (; cur; cur = next) {
       next = cur->next;
       cur->next = NULL;
       free(cur);
   }
}
 
static int bounds_check_type_callback(hashtab_key_t k __attribute__ ((unused)),
                     hashtab_datum_t d, void *args)
{
   int rc = 0;
   struct bounds_args *a = (struct bounds_args *)args;
   type_datum_t *t = (type_datum_t *)d;
   avtab_ptr_t bad = NULL;
 
   if (t->bounds) {
       rc = bounds_check_type(a->handle, a->p, t->s.value, t->bounds,
                      &bad, &a->numbad);
       if (bad) {
           bounds_report(a->handle, a->p, t->s.value, t->bounds,
                     bad);
           bounds_destroy_bad(bad);
       }
   }
 
   return rc;
}
 
int bounds_check_types(sepol_handle_t *handle, policydb_t *p)
{
   int rc;
   struct bounds_args args;
 
   args.handle = handle;
   args.p = p;
   args.numbad = 0;
 
   rc = hashtab_map(p->p_types.table, bounds_check_type_callback, &args);
   if (rc) goto exit;
 
   if (args.numbad > 0) {
       ERR(handle, "%d errors found during type bounds check",
           args.numbad);
       rc = SEPOL_ERR;
   }
 
exit:
   return rc;
}
 
/* The role bounds is defined as: a child role cannot have a type that
 * its parent doesn't have.
 */
static int bounds_check_role_callback(hashtab_key_t k,
                     hashtab_datum_t d, void *args)
{
   struct bounds_args *a = (struct bounds_args *)args;
   role_datum_t *r = (role_datum_t *) d;
   role_datum_t *rp = NULL;
 
   if (!r->bounds)
       return 0;
 
   rp = a->p->role_val_to_struct[r->bounds - 1];
 
   if (rp && !ebitmap_contains(&rp->types.types, &r->types.types)) {
       ERR(a->handle, "Role bounds violation, %s exceeds %s",
           (char *)k, a->p->p_role_val_to_name[rp->s.value - 1]);
       a->numbad++;
   }
 
   return 0;
}
 
int bounds_check_roles(sepol_handle_t *handle, policydb_t *p)
{
   struct bounds_args args;
 
   args.handle = handle;
   args.p = p;
   args.numbad = 0;
 
   hashtab_map(p->p_roles.table, bounds_check_role_callback, &args);
 
   if (args.numbad > 0) {
       ERR(handle, "%d errors found during role bounds check",
           args.numbad);
       return SEPOL_ERR;
   }
 
   return 0;
}
 
/* The user bounds is defined as: a child user cannot have a role that
 * its parent doesn't have.
 */
static int bounds_check_user_callback(hashtab_key_t k,
                     hashtab_datum_t d, void *args)
{
   struct bounds_args *a = (struct bounds_args *)args;
   user_datum_t *u = (user_datum_t *) d;
   user_datum_t *up = NULL;
 
   if (!u->bounds)
       return 0;
 
   up = a->p->user_val_to_struct[u->bounds - 1];
 
   if (up && !ebitmap_contains(&up->roles.roles, &u->roles.roles)) {
       ERR(a->handle, "User bounds violation, %s exceeds %s",
           (char *) k, a->p->p_user_val_to_name[up->s.value - 1]);
       a->numbad++;
   }
 
   return 0;
}
 
int bounds_check_users(sepol_handle_t *handle, policydb_t *p)
{
   struct bounds_args args;
 
   args.handle = handle;
   args.p = p;
   args.numbad = 0;
 
   hashtab_map(p->p_users.table, bounds_check_user_callback, &args);
 
   if (args.numbad > 0) {
       ERR(handle, "%d errors found during user bounds check",
           args.numbad);
       return SEPOL_ERR;
   }
 
   return 0;
}
 
#define add_hierarchy_callback_template(prefix)                \
   int hierarchy_add_##prefix##_callback(hashtab_key_t k __attribute__ ((unused)), \
                       hashtab_datum_t d, void *args) \
{                                \
   struct bounds_args *a = (struct bounds_args *)args;        \
   sepol_handle_t *handle = a->handle;                \
   policydb_t *p = a->p;                        \
   prefix##_datum_t *datum = (prefix##_datum_t *)d;        \
   prefix##_datum_t *parent;                    \
   char *parent_name, *datum_name, *tmp;                \
                                   \
   if (!datum->bounds) {                        \
       datum_name = p->p_##prefix##_val_to_name[datum->s.value - 1]; \
                                   \
       tmp = strrchr(datum_name, '.');                \
       /* no '.' means it has no parent */            \
       if (!tmp) return 0;                    \
                                   \
       parent_name = strdup(datum_name);            \
       if (!parent_name) {                    \
           ERR(handle, "Insufficient memory");        \
           return SEPOL_ENOMEM;                \
       }                            \
       parent_name[tmp - datum_name] = '\0';            \
                                   \
       parent = hashtab_search(p->p_##prefix##s.table, parent_name); \
       if (!parent) {                        \
           /* Orphan type/role/user */            \
           ERR(handle, "%s doesn't exist, %s is an orphan",\
               parent_name,                \
               p->p_##prefix##_val_to_name[datum->s.value - 1]); \
           free(parent_name);                \
           a->numbad++;                    \
           return 0;                    \
       }                            \
       datum->bounds = parent->s.value;            \
       free(parent_name);                    \
   }                                \
                                   \
   return 0;                            \
}                                \
 
static add_hierarchy_callback_template(type)
static add_hierarchy_callback_template(role)
static add_hierarchy_callback_template(user)
 
int hierarchy_add_bounds(sepol_handle_t *handle, policydb_t *p)
{
   int rc = 0;
   struct bounds_args args;
 
   args.handle = handle;
   args.p = p;
   args.numbad = 0;
 
   rc = hashtab_map(p->p_users.table, hierarchy_add_user_callback, &args);
   if (rc) goto exit;
 
   rc = hashtab_map(p->p_roles.table, hierarchy_add_role_callback, &args);
   if (rc) goto exit;
 
   rc = hashtab_map(p->p_types.table, hierarchy_add_type_callback, &args);
   if (rc) goto exit;
 
   if (args.numbad > 0) {
       ERR(handle, "%d errors found while adding hierarchies",
           args.numbad);
       rc = SEPOL_ERR;
   }
 
exit:
   return rc;
}
 
int hierarchy_check_constraints(sepol_handle_t * handle, policydb_t * p)
{
   int rc = 0;
   int violation = 0;
 
   rc = hierarchy_add_bounds(handle, p);
   if (rc) goto exit;
 
   rc = bounds_check_users(handle, p);
   if (rc)
       violation = 1;
 
   rc = bounds_check_roles(handle, p);
   if (rc)
       violation = 1;
 
   rc = bounds_check_types(handle, p);
   if (rc) {
       if (rc == SEPOL_ERR)
           violation = 1;
       else
           goto exit;
   }
 
   if (violation)
       rc = SEPOL_ERR;
 
exit:
   return rc;
}