summaryrefslogtreecommitdiff
path: root/src/fs.cil
blob: 3ea719b133ab3c4d2b4212fa3eee20e81699e8a9 (plain)
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
;; SPDX-FileCopyrightText: © 2023 Dominick Grift <dominick.grift@defensec.nl>
;; SPDX-License-Identifier: Unlicense

(class filesystem
       (associate getattr mount quotaget quotamod relabelfrom relabelto remount
		  unmount watch))
(classorder (unordered filesystem))

(in ibac

    (constrain (filesystem (relabelto))
	       (or (or (or (eq u1 u2)
			   (and (eq t1 objchangesys.typeattr) (eq u2 .sys.id)))
		       (eq t1 objchange.typeattr))
		   (eq t1 exempt.typeattr))))

(in mcs

    (mlsconstrain (filesystem (relabelto))
		  (or (neq t1 constrained.typeattr)
		      (and (dom h1 h2) (eq l2 h2))))

    (mlsconstrain (filesystem (associate getattr mount remount))
		  (or (dom h1 h2)
		      (neq t1 constrained.typeattr))))

(in rbac

    (constrain (filesystem (relabelto))
	       (or (or (or (eq r1 r2)
			   (and (eq t1 objchangesys.typeattr)
				(eq r2 .sys.role)))
		       (eq t1 objchange.typeattr))
		   (eq t1 exempt.typeattr))))

(in rbacsep

    (constrain (filesystem (getattr))
	       (or (or (or (or (or (eq r1 r2)
				   (and (eq r1 exempt.roleattr)
					(neq t1 constrained.typeattr)))
			       (eq t1 exempt.subj.typeattr))
			   (eq t2 exempt.obj.typeattr))
		       (and (eq r2 exempt.roleattr) (eq t2 typeattr)))
		   (and (eq t1 readstatesource.typeattr)
			(eq t2 readstatetarget.typeattr)))))

(macro associate_invalid_fs ((type ARG1))
       (allow ARG1 invalid (filesystem (associate))))

(macro getattr_invalid_fs ((type ARG1))
       (allow ARG1 invalid (filesystem (getattr))))

(macro mount_invalid_fs ((type ARG1))
       (allow ARG1 invalid (filesystem (mount))))

(macro quotaget_invalid_fs ((type ARG1))
       (allow ARG1 invalid (filesystem (quotaget))))

(macro quotamod_invalid_fs ((type ARG1))
       (allow ARG1 invalid (filesystem (quotamod))))

(macro relabel_invalid_fs ((type ARG1))
       (allow ARG1 invalid (filesystem (relabelfrom relabelto))))

(macro relabelfrom_invalid_fs ((type ARG1))
       (allow ARG1 invalid (filesystem (relabelfrom))))

(macro relabelto_invalid_fs ((type ARG1))
       (allow ARG1 invalid (filesystem (relabelto))))

(macro remount_invalid_fs ((type ARG1))
       (allow ARG1 invalid (filesystem (remount))))

(macro unmount_invalid_fs ((type ARG1))
       (allow ARG1 invalid (filesystem (unmount))))

(macro watch_invalid_fs ((type ARG1))
       (allow ARG1 invalid (filesystem (watch))))

(allow invalid self (filesystem (associate)))

(block fs

  (macro type ((type ARG1))
	 (typeattributeset typeattr ARG1))

  (typeattribute typeattr)

  (blockinherit all_macro_template_fs)

  (blockinherit .file.all_macro_template_all_files)
  (blockinherit .file.all_macro_template_blk_files)
  (blockinherit .file.all_macro_template_chr_files)
  (blockinherit .file.all_macro_template_dirs)
  (blockinherit .file.all_macro_template_fifo_files)
  (blockinherit .file.all_macro_template_files)
  (blockinherit .file.all_macro_template_lnk_files)
  (blockinherit .file.all_macro_template_sock_files)

  (call .obj.type (typeattr))

  (block all_macro_template_fs

    (blockabstract all_macro_template_fs)

    (macro associate_all_fs ((type ARG1))
	   (allow ARG1 typeattr (filesystem (associate))))

    (macro getattr_all_fs ((type ARG1))
	   (allow ARG1 typeattr (filesystem (getattr))))

    (macro mount_all_fs ((type ARG1))
	   (allow ARG1 typeattr (filesystem (mount))))

    (macro quotaget_all_fs ((type ARG1))
	   (allow ARG1 typeattr (filesystem (quotaget))))

    (macro quotamod_all_fs ((type ARG1))
	   (allow ARG1 typeattr (filesystem (quotamod))))

    (macro relabel_all_fs ((type ARG1))
	   (allow ARG1 typeattr (filesystem (relabelfrom relabelto))))

    (macro relabelfrom_all_fs ((type ARG1))
	   (allow ARG1 typeattr (filesystem (relabelfrom))))

    (macro relabelto_all_fs ((type ARG1))
	   (allow ARG1 typeattr (filesystem (relabelto))))

    (macro remount_all_fs ((type ARG1))
	   (allow ARG1 typeattr (filesystem (remount))))

    (macro unmount_all_fs ((type ARG1))
	   (allow ARG1 typeattr (filesystem (unmount))))

    (macro watch_all_fs ((type ARG1))
	   (allow ARG1 typeattr (filesystem (watch)))))

  (block base_template

    (blockabstract base_template)

    (context fs_context (.sys.id .sys.role fs lowlevelrange))

    (type fs)
    (call .fs.type (fs)))

  (block macro_template_all_files

    (blockabstract macro_template_all_files)

    (macro create_fs_file ((type ARG1))
	   (allow ARG1 fs (files (create))))

    (macro delete_fs_file ((type ARG1))
	   (allow ARG1 fs (files (delete))))

    (macro manage_fs_file ((type ARG1))
	   (allow ARG1 fs (files (manage))))

    (macro read_fs_file ((type ARG1))
	   (allow ARG1 fs (files (read))))

    (macro readwrite_fs_file ((type ARG1))
	   (allow ARG1 fs (files (readwrite))))

    (macro relabel_fs_file ((type ARG1))
	   (allow ARG1 fs (files (relabel))))

    (macro relabelfrom_fs_file ((type ARG1))
	   (allow ARG1 fs (files (relabelfrom))))

    (macro relabelto_fs_file ((type ARG1))
	   (allow ARG1 fs (files (relabelto))))

    (macro rename_fs_file ((type ARG1))
	   (allow ARG1 fs (files (rename))))

    (macro write_fs_file ((type ARG1))
	   (allow ARG1 fs (files (write)))))

  (block macro_template_blk_files

    (blockabstract macro_template_blk_files)

    (macro append_blk_fs_files ((type ARG1))
	   (allow ARG1 fs append_blk_file))

    (macro appendinherited_fs_blk_files ((type ARG1))
	   (allow ARG1 fs appendinherited_blk_file))

    (macro create_fs_blk_files ((type ARG1))
	   (allow ARG1 fs create_blk_file))

    (macro delete_fs_blk_files ((type ARG1))
	   (allow ARG1 fs delete_blk_file))

    (macro manage_fs_blk_files ((type ARG1))
	   (allow ARG1 fs manage_blk_file))

    (macro read_fs_blk_files ((type ARG1))
	   (allow ARG1 fs read_blk_file))

    (macro readinherited_fs_blk_files ((type ARG1))
	   (allow ARG1 fs readinherited_blk_file))

    (macro readwrite_fs_blk_files ((type ARG1))
	   (allow ARG1 fs readwrite_blk_file))

    (macro readwriteinherited_fs_blk_files ((type ARG1))
	   (allow ARG1 fs readwriteinherited_blk_file))

    (macro relabel_fs_blk_files ((type ARG1))
	   (allow ARG1 fs relabel_blk_file))

    (macro relabelfrom_fs_blk_files ((type ARG1))
	   (allow ARG1 fs relabelfrom_blk_file))

    (macro relabelto_fs_blk_files ((type ARG1))
	   (allow ARG1 fs relabelto_blk_file))

    (macro rename_fs_blk_files ((type ARG1))
	   (allow ARG1 fs rename_blk_file))

    (macro write_fs_blk_files ((type ARG1))
	   (allow ARG1 fs write_blk_file))

    (macro writeinherited_fs-blk_files ((type ARG1))
	   (allow ARG1 fs writeinherited_blk_file)))

  (block macro_template_chr_files

    (blockabstract macro_template_chr_files)

    (macro append_fs_chr_files ((type ARG1))
	   (allow ARG1 fs append_chr_file))

    (macro appendinherited_fs_chr_files ((type ARG1))
	   (allow ARG1 fs appendinherited_chr_file))

    (macro create_fs_chr_files ((type ARG1))
	   (allow ARG1 fs create_chr_file))

    (macro delete_fs_chr_files ((type ARG1))
	   (allow ARG1 fs delete_chr_file))

    (macro manage_fs_chr_files ((type ARG1))
	   (allow ARG1 fs manage_chr_file))

    (macro mapexecute_fs_chr_files ((type ARG1))
	   (allow ARG1 fs mapexecute_chr_file))

    (macro read_fs_chr_files ((type ARG1))
	   (allow ARG1 fs read_chr_file))

    (macro readinherited_fs_chr_files ((type ARG1))
	   (allow ARG1 fs readinherited_chr_file))

    (macro readwrite_fs_chr_files ((type ARG1))
	   (allow ARG1 fs readwrite_chr_file))

    (macro readwriteinherited_fs_chr_files ((type ARG1))
	   (allow ARG1 fs readwriteinherited_chr_file))

    (macro relabel_fs_chr_files ((type ARG1))
	   (allow ARG1 fs relabel_chr_file))

    (macro relabelfrom_fs_chr_files ((type ARG1))
	   (allow ARG1 fs relabelfrom_chr_file))

    (macro relabelto_fs_chr_files ((type ARG1))
	   (allow ARG1 fs relabelto_chr_file))

    (macro rename_fs_chr_files ((type ARG1))
	   (allow ARG1 fs rename_chr_file))

    (macro write_fs_chr_files ((type ARG1))
	   (allow ARG1 fs write_chr_file))

    (macro writeinherited_fs_chr_files ((type ARG1))
	   (allow ARG1 fs writeinherited_chr_file)))

  (block macro_template_dirs

    (blockabstract macro_template_dirs)

    (macro addname_fs_dirs ((type ARG1))
	   (allow ARG1 fs addname_dir))

    (macro create_fs_dirs ((type ARG1))
	   (allow ARG1 fs create_dir))

    (macro delete_fs_dirs ((type ARG1))
	   (allow ARG1 fs delete_dir))

    (macro deletename_fs_dirs ((type ARG1))
	   (allow ARG1 fs deletename_dir))

    (macro fs_type_transition ((type ARG1)(type ARG2)(class ARG3)(name ARG4))
	   (typetransition ARG1 fs ARG3 ARG4 ARG2)
	   (call addname_fs_dirs (ARG1)))

    (macro list_fs_dirs ((type ARG1))
	   (allow ARG1 fs list_dir))

    (macro listinherited_fs_dirs ((type ARG1))
	   (allow ARG1 fs listinherited_dir))

    (macro manage_fs_dirs ((type ARG1))
	   (allow ARG1 fs manage_dir))

    (macro mounton_fs_dirs ((type ARG1))
	   (allow ARG1 fs mounton_dir))

    (macro readwrite_fs_dirs ((type ARG1))
	   (allow ARG1 fs readwrite_dir))

    (macro readwriteinherited_fs_dirs ((type ARG1))
	   (allow ARG1 fs readwriteinherited_dir))

    (macro relabel_fs_dirs ((type ARG1))
	   (allow ARG1 fs relabel_dir))

    (macro relabelfrom_fs_dirs ((type ARG1))
	   (allow ARG1 fs relabelfrom_dir))

    (macro relabelto_fs_dirs ((type ARG1))
	   (allow ARG1 fs relabelto_dir))

    (macro rename_fs_dirs ((type ARG1))
	   (allow ARG1 fs rename_dir))

    (macro search_fs_dirs ((type ARG1))
	   (allow ARG1 fs search_dir))

    (macro write_fs_dirs ((type ARG1))
	   (allow ARG1 fs write_dir))

    (macro writeinherited_fs_dirs ((type ARG1))
	   (allow ARG1 fs writeinherited_dir)))

  (block macro_template_fifo_files

    (blockabstract macro_template_fifo_files)

    (macro append_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs append_fifo_file))

    (macro appendinherited_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs appendinherited_fifo_file))

    (macro create_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs create_fifo_file))

    (macro delete_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs delete_fifo_file))

    (macro manage_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs manage_fifo_file))

    (macro read_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs read_fifo_file))

    (macro readinherited_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs readinherited_fifo_file))

    (macro readwrite_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs readwrite_fifo_file))

    (macro readwriteinherited_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs readwriteinherited_fifo_file))

    (macro relabel_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs relabel_fifo_file))

    (macro relabelfrom_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs relabelfrom_fifo_file))

    (macro relabelto_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs relabelto_fifo_file))

    (macro rename_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs rename_fifo_file))

    (macro write_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs write_fifo_file))

    (macro writeinherited_fs_fifo_files ((type ARG1))
	   (allow ARG1 fs writeinherited_fifo_file)))

  (block macro_template_files

    (blockabstract macro_template_files)

    (macro append_fs_files ((type ARG1))
	   (allow ARG1 fs append_file))

    (macro appendinherited_fs_files ((type ARG1))
	   (allow ARG1 fs appendinherited_file))

    (macro create_fs_files ((type ARG1))
	   (allow ARG1 fs create_file))

    (macro delete_fs_files ((type ARG1))
	   (allow ARG1 fs delete_file))

    (macro execute_fs_files ((type ARG1))
	   (allow ARG1 fs execute_file))

    (macro manage_fs_files ((type ARG1))
	   (allow ARG1 fs manage_file))

    (macro mapexecute_fs_files ((type ARG1))
	   (allow ARG1 fs mapexecute_file))

    (macro mounton_fs_files ((type ARG1))
	   (allow ARG1 fs mounton_file))

    (macro read_fs_files ((type ARG1))
	   (allow ARG1 fs read_file))

    (macro readinherited_fs_files ((type ARG1))
	   (allow ARG1 fs readinherited_file))

    (macro readwrite_fs_files ((type ARG1))
	   (allow ARG1 fs readwrite_file))

    (macro readwriteinherited_fs_files ((type ARG1))
	   (allow ARG1 fs readwriteinherited_file))

    (macro relabel_fs_files ((type ARG1))
	   (allow ARG1 fs relabel_file))

    (macro relabelfrom_fs_files ((type ARG1))
	   (allow ARG1 fs relabelfrom_file))

    (macro relabelto_fs_files ((type ARG1))
	   (allow ARG1 fs relabelto_file))

    (macro rename_fs_files ((type ARG1))
	   (allow ARG1 fs rename_file))

    (macro write_fs_files ((type ARG1))
	   (allow ARG1 fs write_file))

    (macro writeinherited_fs_files ((type ARG1))
	   (allow ARG1 fs writeinherited_file)))

  (block macro_template_lnk_files

    (blockabstract macro_template_lnk_files)

    (macro create_fs_lnk_files ((type ARG1))
	   (allow ARG1 fs create_lnk_file))

    (macro delete_fs_lnk_files ((type ARG1))
	   (allow ARG1 fs delete_lnk_file))

    (macro manage_fs_lnk_files ((type ARG1))
	   (allow ARG1 fs manage_lnk_file))

    (macro read_fs_lnk_files ((type ARG1))
	   (allow ARG1 fs read_lnk_file))

    (macro readwrite_fs_lnk_files ((type ARG1))
	   (allow ARG1 fs readwrite_lnk_file))

    (macro relabel_fs_lnk_files ((type ARG1))
	   (allow ARG1 fs relabel_lnk_file))

    (macro relabelfrom_fs_lnk_files ((type ARG1))
	   (allow ARG1 fs relabelfrom_lnk_file))

    (macro relabelto_fs_lnk_files ((type ARG1))
	   (allow ARG1 fs relabelto_lnk_file))

    (macro rename_fs_lnk_files ((type ARG1))
	   (allow ARG1 fs rename_lnk_file))

    (macro write_fs_lnk_files ((type ARG1))
	   (allow ARG1 fs write_lnk_file)))

  (block macro_template_sock_files

    (blockabstract macro_template_sock_files)

    (macro create_fs_sock_files ((type ARG1))
	   (allow ARG1 fs create_sock_file))

    (macro delete_fs_sock_files ((type ARG1))
	   (allow ARG1 fs delete_sock_file))

    (macro manage_fs_sock_files ((type ARG1))
	   (allow ARG1 fs manage_sock_file))

    (macro read_fs_sock_files ((type ARG1))
	   (allow ARG1 fs read_sock_file))

    (macro readinherited_fs_sock_files ((type ARG1))
	   (allow ARG1 fs readinherited_sock_file))

    (macro readwrite_fs_sock_files ((type ARG1))
	   (allow ARG1 fs readwrite_sock_file))

    (macro readwriteinherited_fs_sock_files ((type ARG1))
	   (allow ARG1 fs readwriteinherited_sock_file))

    (macro relabel_fs_sock_files ((type ARG1))
	   (allow ARG1 fs relabel_sock_file))

    (macro relabelfrom_fs_sock_files ((type ARG1))
	   (allow ARG1 fs relabelfrom_sock_file))

    (macro relabelto_fs_sock_files ((type ARG1))
	   (allow ARG1 fs relabelto_sock_file))

    (macro rename_fs_sock_files ((type ARG1))
	   (allow ARG1 fs rename_sock_file))

    (macro write_fs_sock_files ((type ARG1))
	   (allow ARG1 fs write_sock_file))

    (macro writeinherited_fs_sock_files ((type ARG1))
	   (allow ARG1 fs writeinherited_sock_file)))

  (block macro_template_fs

    (blockabstract macro_template_fs)

    (macro associate_fs ((type ARG1))
	   (allow ARG1 fs (filesystem (associate))))

    (macro getattr_fs ((type ARG1))
	   (allow ARG1 fs (filesystem (getattr))))

    (macro mount_fs ((type ARG1))
	   (allow ARG1 fs (filesystem (mount))))

    (macro quotaget_fs ((type ARG1))
	   (allow ARG1 fs (filesystem (quotaget))))

    (macro quotamod_fs ((type ARG1))
	   (allow ARG1 fs (filesystem (quotamod))))

    (macro relabel_fs ((type ARG1))
	   (allow ARG1 fs (filesystem (relabelfrom relabelto))))

    (macro relabelfrom_fs ((type ARG1))
	   (allow ARG1 fs (filesystem (relabelfrom))))

    (macro relabelto_fs ((type ARG1))
	   (allow ARG1 fs (filesystem (relabelto))))

    (macro remount_fs ((type ARG1))
	   (allow ARG1 fs (filesystem (remount))))

    (macro unmount_fs ((type ARG1))
	   (allow ARG1 fs (filesystem (unmount))))

    (macro watch_fs ((type ARG1))
	   (allow ARG1 fs (filesystem (watch)))))

  (block template

    (blockabstract template)

    (blockabstract .fs.base_template)
    (blockabstract .fs.macro_template_fs))

  (block unconfined

    (macro type ((type ARG1))
	   (typeattributeset typeattr ARG1))

    (typeattribute typeattr)

    (allow typeattr fs.typeattr
	   (blk_file (not (audit_access execmod map mounton))))
    (allow typeattr fs.typeattr (chr_file (not (audit_access execmod mounton))))
    (allow typeattr fs.typeattr (dir (not (audit_access execmod))))
    (allow typeattr fs.typeattr
	   (fifo_file (not (audit_access execmod map mounton))))
    (allow typeattr fs.typeattr (file (not (audit_access entrypoint execmod))))
    (allow typeattr fs.typeattr (filesystem (not associate)))
    (allow typeattr fs.typeattr
	   (lnk_file (not (audit_access execmod map mounton))))
    (allow typeattr fs.typeattr
	   (sock_file (not (audit_access execmod map mounton))))))

(in invalid.unconfined

    (allow typeattr .invalid (filesystem (not (associate relabelto)))))

(in unconfined

    (call .fs.unconfined.type (typeattr)))