-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_SElinux.txt
666 lines (624 loc) · 76.8 KB
/
linux_SElinux.txt
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
## Apropos:
Content is versioned in git. commits, issues and pull-requests welcome!
@[https://www.github.com/earizon/DevOps]
# SElinux Summary [[{linux.security.selinux,security.aaa,linux.kernel.101]] #[selinux_summary]
- Ext.Refs
- https://github.com/SELinuxProject/selinux/wiki
- https://github.com/SELinuxProject/setools/wiki
- https://github.com/SELinuxProject/cil/wiki
- https://github.com/SELinuxProject/refpolicy
- (Book) http://selinuxbyexample.com/
- (Book) http://www.freetechbooks.com/the-selinux-notebook-the-foundations-t785.html
- https://www.youtube.com/watch?v=cNoVgDqqJmM&feature=youtu.be">[Stop disabling SELinux]
┌──────────────────────────┬──────────────────────────────────────┐┌─────────────────────┬────────────────────────────────────────┐
│*SE─LINUX GLOBAL SUMMARY*:│ ││ DAC+MAC FLOW SUMMARY│ │
│──────────────────────────┘ │├─────────────────────┘ │
│ * KERNEL * ││ USER ┌─────────→ ┌─────────┐ │
│ *OBJECTS CLASSES* ││ SPACE │ ┌───────→ │ PROCESS │ ←─────────────────┐ │
│ ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ││ │ │ ┌─────→ │"SUBJECT"│ │ │
│Represent type─of─resources ││ │ │ │ │*type1* │ │ │
│handled by kernel(vs app) Each type─of─resource has a set of ││ │ │ │ └─────────┘ │ │
│that must be protected *HARDCODED* list of *actions* defined ││ │ │ │ *1)* ↓ │ │
│by Mandatory access Rules for each se─linux kernel object class ││ ───────────── │ │ │ ───── system─call ───────────────── │ ───│
│ ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ││ KERNEL │ │ │ │☝request(hardcoded) │ │
│ *File class* ←→ [append, create, lock, ... ] ││ SPACE │ │ │ │ *action1*over targeted │ │
│ *Process class* ←→ [dyntransition, ptrace, fork, ... ] ││ │ │ │ │object (labeled with │ │
│ *INET Socket class* ←→ [bind, read, ... ... ] ││ │ │ │ │SEContext *type2*) │ │
│ *login class* ←→ [action1, action2, ... ... ] ││ │ │ │ *2)* ↓ │ │
│ *user class* ←→ [action1, action2, ... ... ] ││ │ │ │ Lookup │ │
│ ... ││ │ │ │ data *8)*│Sys.│
│ ││ │ │ │ │ ┌────────┐ │call│
│─TheG*Process objects*differ from the rest in the sense that ││ │ │ │ *KO**3)* ↓ │target │ │Res.│
│they are the "active" kernel object triggering a new system call,││ │ │ └───────── Error ┌────│object ├──┘ │
│probably as a result of a user intention to access some other ││ │ │ Checks │ │ *type2*│ │
│resource (kernel object instance in SELinux parlance) ││ │ │ │ │ └────────┘ │
│ ││ │ │ │ *OK* │*7)* │
│─ *File*alike objects (Files, directories,...) must be first ││ │ │ *4)* ↓ │ *OK*:exec *gaction1*│
│ "manually" labelled through extended file─system attributes. ││ │ │ *KO* DAC │on target object │
│ Other object labelling is done by kernel automatically ││ │ └───────── permission │ │
│ ││ │ checks │ │
│*KERNEL─OBJECT─INSTANCE CONTEXT* ││ │ *KO* │ │ │
│ ││ │ *(audit)**7)* ↓ │ │
│ ┌── SELinux context ────┐ ││ └───────────── LSM ────┘ │
│ user:role:" *type*":level ││ hooks │
│ ☝ ││ *5)* │ ^ *6)* │
│ ─ *All* Kernel Object *instances* are*labeled*with ││ *type1* is allowed│ │ *OK* ☜ *MAC* │
│ a 4─tuple *SELINUX─CONTEXT* (user:role:type:level) ││ *action1* over│ │ *KO* *TYPE* │
│ ││ *type2*?↓ │ *ENFORCEMENT* │
│ ─The *type* is the core data used for MACO*TYPE─ENFORCEMENT* ││ ┌───────────┐ │
└─────────────────────────────────────────────────────────────────┘│ │ Security │ │
┌────────────────────────────┬───────────────────────────────┐ │ │Enhance(SE)│ │
│*INITIAL PRE─SETUP SUMMARY:*│ │ │ │ Server │ │
├────────────────────────────┘ │ │ └───────────┘ │
│ Define SE-Linux System policy with a flow similar to: │ │ ☝ │
│ │ │ The server will first query the AVC(ache) and return │
│ create modules → load into → Init bitmap─"matrix" │ │ OK/KO if a match is found. │
│ kernel context1─to─[context2,action] │ │ If nothing is found the server will: │
│ ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ │ │ 1) work over the AV─hash table for matching rules │
│ Access Vector (AV) │ │ 2) calculate the result, │
└────────────────────────────────────────────────────────────┘ │ 3) put the result back in AVC(ache) │
│ 4) Return with OK/KO │
└──────────────────────────────────────────────────────────────┘
┌──────────────────────────┬───────┐ ┌─────────────────────┬───────────────────────────────────────────────────────┐
│ *SELinux bootup sequence*│ │ │*/etc/selinux/config*│ │
├──────────────────────────┘ │ ├─────────────────────┘ │
│ kernel start → │ │SELINUX=enforcing ← ─ *enforcing * (Enables MAC) │
│ load policy into memory │ │ ─ *permissive* (Use for tracing/debugging new apps) │
│ (organized in modules) │ │ ─ "some other value that you must never use" │
│ │ │SELINUXTYPE=targeted ← ─ *targeted * Apply MAC to targeted processes │
│*semodule* command manages the │ │ (listening for remote connections)│
│install, remove, reload, upgrade, │ │ *minimum * Subset of targeted: │
│enable or disable fo modules │ │ Only selected processes are protected. │
│Ex. lists modules currently loaded│ │ *mls * Multi Level Security protection. │
│~ sudo semodule ─l │ │ (Rarely used) │
│→abrt 1.2.0 │ └─────────────────────────────────────────────────────────────────────────────┘
│→accountsd 1.0.6 │
│... │
└──────────────────────────────────┘
┌─────────────────────────────────┐
│QUERY SOURCE TO TARGET RELATIONS:│
├─────────────────────────────────┴─────────────────────────────────────────────────────┐
│#~ sesearch --allow \ ← Show allowed │
│ --source *httpd_t * │
│ --target *httpd_sys_content_t* │
│ --class *file * ← kernel selinux object class │
│ → Found 4 semantic av rules: │
│ → allow *httpd_t httpd_sys_content_t* : *file* *{ ioctl read getattr lock open }* ;│
│ → allow *httpd_t httpd_content_type * : *file* *{ ioctl read getattr lock open }* ;│
│ → allow *httpd_t httpd_content_type * : *file* *{ ioctl read getattr lock open }* ;│
│ → allow *httpd_t httpdcontent * : *file* *{ ioctl read write create .... }* ;│
└─────────────────────────────────┴─────────────────────────────────────────────────────┘
┌────────────────────────────────────────┬──────┐ ┌─────────────┬────────────────────────────────────┐
│*DISPLAYING SELINUX CONTEXT ATTRIBUTES:*│ │ │*sestatus(8)*│ │
├────────────────────────────────────────┘ │ ├─────────────┘ │
│- Use "-Z" flag to shell commands │ │ Return various status info, such as enforcing │
│┌────────────────────────────────────────────┐ │ │ mode, current policy version and name, ... │
││FILE SYSTEM OBJECT (files, dirs,..) │ │ │ $ sudo *sestatus* │
││$ ls -ldZ │ │ │ → SELinux status: enabled │
││ /usr/sbin/httpd → *httpd_exec_t *│ │ │ → SELinuxfs mount: /sys/fs/selinux│
││ /var/www/html/ → *httpd_sys_content_t*│ │ │ → SELinux root directory: /etc/selinux │
││ /etc/apache2/ → *httpd_config_t *│ │ │ → Loaded policy name: targeted │
││ /var/log/httpd/ → *httpd_log_t *│ │ │ → Current mode: permissive │
││ /etc/init.d/httpd → *httpd_initrc_exec_t*│ │ │ → Mode from config file: error (Success)│
│├────────────────────────────────────────────┤ │ │ → Policy MLS status: enabled │
││SUBJECTS (running processes) │ │ │ → Policy deny_unknown status: allowed │
││$*ps axZ │ grep [h]ttpd* │ │ │ → Max kernel policy version: 28 │
││unconfined_u:system_r: *httpd_*t:s0 ... │ │ └──────────────────────────────────────────────────┘
│├────────────────────────────────────────────┤ │ ┌───────────────┬─────────────────────────────────┐
││SOCKET │ │ │show AVC stats:│ │
││$ sudo netstat ─tnlpZ │ grep httpd │ │ ├───────────────┘ │
││.... unconfined_u:system_r: *httpd_*t:s0 ..│ │ │$ sudO*avcstat* │
│├────────────────────────────────────────────┤ │ │lookups hits misses allocs reclaims frees │
││PORT │ │ │6688846 5637360 1051486 051486 968960 1050979 │
││$ sudo semanage port ─l │ grep http │ │ └─────────────────────────────────────────────────┘
││http_cache_port_t tcp 3128,8080, ... │ │ ┌──────────────────────┬────────────────────────┐
││ ... │ │ │ SHELL SCRIPTS SUPORT:│ │
││ *http_port_t* tcp 80, 443 │ │ ├──────────────────────┘ │
│└────────────────────────────────────────────┘ │ │*getenforce(8)* Returns status like: │
└───────────────────────────────────────────────┘ │ "permissive" │ "enforcing" │
│ │
│*selinuxenabled(1)* exits with 0 if enabled │
│ 1 if not │
└───────────────────────────────────────────────┘
┌─────────────────┬────────┬────────────────────────────────────────────────────────────────────────┐
│ TERMINOLOGY │ACRONYM │ DESCRIPTION │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Access Vector │AV │ - bit map representing a set of permissions such as open, read, ... │
│ │ │ - Each policy defines a different AV. │
│ │ │ - Actually is implemented as a hash table where the key is the tuple │
│ │ │ (source-type, targeted-type, targeted-kernel-object-class) │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Access Vector │AVC │ ─ SELinux Security Server can take a time to calculate │
│ Cache │ │ access decissions based on SE─rules. │
│ │ │ ─ The AVC stores such decissions to speed up following │
│ │ │ access avoiding to recompute. │
│ │ │ ─ two AVCs exists: │
│ │ │ ─ 1.kernel AVC caching decisions from Security Server │
│ │ │ on behalf of kernel based object managers. │
│ │ │ ─ 2.userspace AVC built into libselinux that caches │
│ │ │ decisions when SELinux─aware applications use │
│ │ │ avc_open(3) with avc_has_perm (3) or avc_has_perm_noaudit(3) │
│ │ │ function calls saving kernel calls after first │
│ │ │ decision has been made. │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Bell─La Padula │BLP │ │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Common Criteria│CC │ │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Common │CIL │ │
│ Intermediate │ │ │
│ Language │ │ │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Discretionary │DAC │ │
│ Access │ │ │
│ Control │ │ │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ SELinux │ │ ─ consists of one or more processes associated │
│ Domain │ │ to the type component of a Security Context. │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Flux Advanced │FLASK │ ─ See Flux Research Group (http://www.cs.utah.edu/flux/) │
│ Security Kernel │ │ μ─kernel Environment (Fluke) │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Linux Security │LSM │ ─ framework providing hooks into kernel components │
│ Module │ │ (e.g. disk, net─services,...) used by │
│ │ │ security modules (SELinux, ....) to perform │
│ │ │ access control checks. │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Mandatory Access│MAC │ ─ access control mechanism enforced by the system, │
│ Control │ │ e.g. 'hard─wiring' the OS and applications or │
│ │ │ via policies enforced by the administrator. │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Multi─Category │MCS │ │
│ Security │ │ │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Multi─Level │MLS │ ─ Based on Bell─La Padula model for │
│ Security │ │ confidentiality in that (for example) a │
│ │ │ process running at a 'Confidential' level │
│ │ │ can read / write at their current level but │
│ │ │ only read down levels or write up levels. │
│ │ │ ─ "Today" it is more commonly used for │
│ │ │ application separation utilising the │
│ │ │ Multi─Category Security variant. │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ SELinux Policy │ │ - Set of (thousands of) rules that define the type-enforcement rules │
│ │ │ in the AV bitmap matrix/hashtable │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Object Manager │OM │ ─ Userspace&kernel components responsible │
│ │ │ management (object labeling, creation, access, destruction) │
│ │ │ of SELinux object under their control. │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Security │SID │ │
│ Identifier │ │ │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Simplified │SMACK │ │
│ Mandatory │ │ │
│ Access Control │ │ │
│ Kernel │ │ │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Super─user │SUID │ │
│ Identifier │ │ │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Type Enforcement│TE │ ─ set of rules declared in Policy describe │
│ │ │ how the domain will interact with objects │
│ │ │ ─ In practice: the AV bit─map used to check │
│ │ │ where type1 is allowed actionN over type2 │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ User Identifier│UID │ │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ X(window) Access│XACE │ │
│ Control │ │ │
│ Extension │ │ │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Security Server │ │ A sub─system in the Linux kernel that makes access decisions │
│ │ │ and computes security contexts based on Policy on behalf of │
│ │ │ SELinux─aware applications and Object Managers. │
│ │ │ The Security Server does not enforce a decision, it merely │
│ │ │ states whether the operation is allowed or not according to the │
│ │ │ Policy. It is the SELinux─aware application or Object │
│ │ │ Manager responsibility to enforce the decision. │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Security Context│ │ An SELinux Security Context is a variable length string that │
│ │ │ consists of the following mandatory components │
│ │ │ user:role:type and an optional [:range] component. │
│ │ │ Generally abbreviated to 'context', and sometimes called a │
│ │ │ 'label'. │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Security │SID │ SIDs are unique opaque integer values mapped by the kernel │
│ Identifier │ │ Security Server and userspace AVC that represent a Security Context. │
│ │ │ The SIDs generated by the kernel Security Server are u32 │
│ │ │ values that are passed via the Linux Security Module │
│ │ │ hooks to/from the kernel Object Managers. │
│─────────────────┼────────┼────────────────────────────────────────────────────────────────────────│
│ Type Enforcement│ │ SELinux makes use of a specific style of type enforcement │
│ │ │ (TE) to enforce Mandatory Access Control. This is where all │
│ │ │ subjects and objects have a type identifier associated to them │
│ │ │ that can then be used to enforce rules laid down by │
│ │ │ Policy │
└─────────────────┴────────┴────────────────────────────────────────────────────────────────────────┘
# SELinux Kernel Object Classes:
Reminder:
- For nearly every linux (kernel) object that must be protected there is a matching SELInux kernel class.
- This class has a defined set of hardcoded actions that will be allowed/denied by a running policy.
- Type enforcement will determine which "source"-context has which list of allowed-actions over
a given class labeled with a "target"-context
- Next follows a summary of classes and actions extracted from
<a href="https://github.com/SELinuxProject/refpolicy/blob/master/policy/fl ask/access_vectors">https://github.com/SELinuxProject/refpolicy/blob/master/policy/fl ask/access_vectors</a>
┌────────────────────────────┐
│*FILE─ALIKE RELATED OBJECTS*│
├────────────────────────────┴───────────────────────────────────────────────────────┐
│*│common file │class dir │class file │class lnk_file │class chr_file *│
│ │ │inherits file │inherits file │inherits file │inherits file │
│ │ │ │ │ │ │
│ │ioctl │add_name │execute_no_trans │open │execute_no_trans │
│ │read │remove_name │entrypoint │audit_access │entrypoint │
│ │write │reparent │execmod │execmod │execmod │
│ │create │search │open │ │open │
│ │getattr │rmdir │audit_access │audit_access │
│ │setattr │open │ │ │
│ │lock │audit_access │
│ │relabelfrom │execmod │
│ │relabelto │ │
│ │append │
│ │map *│class sock_file │class fifo_file │class fd* *│class blk_file* │
│ │unlink │inherits file │inherits file │ │inherits file │
│ │link │ │ │use │ │
│ │rename │open │open │ │open │
│ │execute │audit_access │audit_access │audit_access │
│ │swapon │execmod │execmod │execmod │
│ │quotaon │ │ │ │
│ │mounton │
│ │ │
└────────────────────────────────────────────────────────────────────────────────────┘
┌──────────────────────────┐
│*NETWORK─RELATED OBJECTS.*│
├──────────────────────────┴────────────────────────────────────────────────────┐
│ *│common socket │class socket │class rawip_socket * │
│ │ │ inherits socket │inherits socket │
│ │ *│class netlink_socket* │ │
│ │# inherited from file │inherits socket │node_bind │
│ │ioctl *│class packet_socket │
│ │read │inherits socket *│class unix_stream_socket*│
│ │write *│class key_socket* │inherits socket │
│ │create │inherits socket │ │
│ │getattr *│class unix_dgram_socket* │connectto │
│ │setattr │inherits socket │newconn │
│ │lock │acceptfrom │
│ │relabelfrom *│class tcp_socket │class node │class netif* │
│ │relabelto │inherits socket │ │ │
│ │append │ │tcp_recv │tcp_recv │
│ │map │connectto │tcp_send │tcp_send │
│ │# socket─specific │newconn │udp_recv │udp_recv │
│ │bind │acceptfrom │udp_send │udp_send │
│ │connect │node_bind │rawip_recv │rawip_recv │
│ │listen │name_connect │rawip_send │rawip_send │
│ │accept │enforce_dest │dccp_recv │
│ │getopt *│class udp_socket* │dccp_recv │dccp_send │
│ │setopt │inherits socket │dccp_send │ingress │
│ │shutdown │ │recvfrom │egress │
│ │recvfrom │node_bind │sendto │
│ │sendto │ │
│ │recv_msg │
│ │send_msg │
│ │name_bind │
└───────────────────────────────────────────────────────────────────────────────┘
┌──────────────────────────┐ ┌─────────────────────┐ ┌───────────────────┐
│ *PROCESS─RELATED OBJECTS*│ │ *CAPABILITY RELATED*│ │*SYSTEM OPERATIONS*│
├──────────────────────────┤ ├──────────────────┬──┘ ├───────────────────┤
│ │ │ │ │ │
│ *│class process* │ │*│common cap* │ │*│class system* │
│ │ │ │ │ │ │ │ │
│ │fork │ │ │chown │ │ │ipc_info │
│ │transition │ │ │dac_override │ │ │syslog_read │
│ │sigchld │ │ │dac_read_search │ │ │syslog_mod │
│ │sigkill │ │ │fowner │ │ │syslog_console │
│ │sigstop │ │ │fsetid │ │ │module_request │
│ │signull │ │ │kill │ │ │module_load │
│ │signal │ │ │setgid │ │ │halt │
│ │ptrace │ │ │setuid │ │ │reboot │
│ │getsched │ │ │setpcap │ │ │status │
│ │setsched │ │ │linux_immutable │ │ │start │
│ │getsession │ │ │net_bind_service│ │ │stop │
│ │getpgid │ │ │net_broadcast │ │ │enable │
│ │setpgid │ │ │net_admin │ │ │disable │
│ │getcap │ │ │net_raw │ │ │reload │
│ │setcap │ │ │ipc_lock │ └───────────────────┘
│ │share │ │ │ipc_owner │
│ │getattr │ │ │sys_module │
│ │setexec │ │ │sys_rawio │
│ │setfscreate │ │ │sys_chroot │
│ │noatsecure │ │ │sys_ptrace │
│ │siginh │ │ │sys_pacct │
│ │setrlimit │ │ │sys_admin │
│ │rlimitinh │ │ │sys_boot │
│ │dyntransition │ │ │sys_nice │
│ │setcurrent │ │ │sys_resource │
│ │execmem │ │ │sys_time │
│ │execstack │ │ │sys_tty_config │
│ │execheap │ │ │mknod │
│ │setkeycreate │ │ │lease │
│ │setsockcreate │ │ │audit_write │
│ │getrlimit │ │ │audit_control │
└──────────────────────────┘ │ │setfcap │
└──────────────────┘
┌──────────────┐
│*OTHERS* │
├──────────────┴───────────────────────────────────────────────────────────────────┐
│*│common ipc │common database │common x_device │class filesystem*│
│ │ │ │ │ │
│ │create │create │/*pointer,keyboard*/ │mount │
│ │destroy │drop │getattr │remount │
│ │getattr │getattr │setattr │unmount │
│ │setattr │setattr │use │getattr │
│ │read │relabelfrom │read │relabelfrom │
│ │write │relabelto │write │relabelto │
│ │associate │ │getfocus │transition │
│ │unix_read │setfocus │associate │
│ │unix_write │bell │quotamod │
│ │ │force_cursor │quotaget │
│ │freeze │
│ │grab │
│ │manage │
│ │list_property │
│ │get_property │
│ │set_property │
│ │add │
│ │remove │
│ │create │
│ │destroy │
│ │
│ │
│ *OTHERS* │
│ security, capability, X─Windows, Netlink, D─BUS, nscd, IPSEC, dccp,memprotect│
│ db_database/db_table/db_column/..., (network) peer, tun_socket, binder │
│ infiniband*, ... │
└──────────────────────────────────────────────────────────────────────────────────┘
# SELINUX FS-LABELING:
- When a new file-alike object is created its contexts
is copied (by default) from its parent's directory
by default.
- This behaviour can be modified with a type_transition rule
in the policy.
$ sudo chcon --type var_t index.html ← Changes context *temporarely*
└─────┘ └─────┘ (FS relabel will revert changes)
$ sudo restorecon -v index.html
$ sudo restorecon reset index.html ← similar to fixfiles(8) suited
unconfined_u:object_r: var_t:s0 -> for individual file or dir. relabeling
unconfined_u:object_r: httpd_sys_content_t*:s0
OTHERS:
*fixfiles(8) * Relabels FS objects. By default
relabel all mounted FSs that support
SELinux unless mounted with the
context mount option, automatically
detemining the file sec.ctx specs
to use for the labeling.
*genhomedircon(8)* Script for generating correct file ctx
specs for user's home directories.
See also:[[Troubleshooting+restorecon?]]
NOTE: SELinux context for remote FS can be specified *at mount time*.
*Verify a file context against file_context(.local) ddbb (active policy) *
#~*matchpathcon* -V /www/html/index.html #
^^
In case of mismatch an error similar to next one will be displayed:
/www/html/index.html has context unconfined_u:object_r:default_t:s0,
should be system_u:object_r:httpd_sys_content_t:s0
# SELINUX login objects:
- SELinux users are not created with a command,
nor does they have its own login access to the server.
- SELinux users are*defined in the policy*loaded into
memory at boot time, and*there are only a few of these users*
- Standard Linux Users are mapped to SElinux users upon login
according to selinux-login-objects defined by policy and
customizable through semanage login.
┌──────────────────────────┐
│ Show 1─to─N relationship:│
├──────────────────────────┴─────────────────────────────────────────────┐
│ #~*semanage user ─ * │
│ (Example CentOS 7 output) │
│ → Labeling ... │
│ → SELinux User Prefix ... SELinux Roles │
│ → │
│ → guest_u user ... guest_r │
│ → root user ... staff_r sysadm_r system_r unconfined_r │
│ → staff_u user ... staff_r sysadm_r system_r unconfined_r │
│ → sysadm_u user ... sysadm_r │
│ → system_u user ... system_r unconfined_r │
│ → unconfined_u user ... system_r unconfined_r │
│ → user_u user ... user_r │
│ → xguest_u user ... xguest_r │
└─────────────────┬──────────────────────────────────────────────────────┘
│
┌──────────┐ ┌────────────┐ ↓ ┌─────┐ ┌────────────────────┐
│Linux User│← N─to─1 →│SELinux user│ ← 1─to─N → │roles│ → │process domain (*_t)│
└──────────┘ ↑ └────────────┘ ↑ └─────┘ ↑ └────────────────────┘
│ │ └─ A role "access a process domain" when policy grants it.
┌──┴──────────────────────┐ └─────────────── A user "enters a roll" when policy grants it.
│show N─to─1 relationship:│
├─────────────────────────┴──────────────────────────────────────┐
│#~*semanage login ─ * │
│(Example CentOS 7 output) │
│→ Login Name SELinux User MLS/MCS Range Service│
│→ │
│→ __default__ unconfined_u s0─s0:c0.c1023 * │
│→ root unconfined_u s0─s0:c0.c1023 * │
│→ system_u system_u s0─s0:c0.c1023 * │
│→ ^^^^^^^^^^^ ^^^^^^^^^^^^ ^^^^^^^^^^^ │
│→ ^ linux user 1 ←→ 1 SE user Multi Level/Category Sec. │
└────────────────────────────────────────────────────────────────┘
┌─────────────────────────┐
│*semanage login [opts]* │
├─────────────────────────┴──────────────────────────────────────────┐
│map linux user to selinux user upon login by │
│Adding/modifying/deleting(and listing) login object types │
│ │
│semanage login [opts] │
│ *──add * ─s "SEUSER" "linuxUser" [─r "MLC/MCS range"] │
│ *──modify * ─s "SEUSER" [─r "MLC/MCS range"] │
│ *──delete "linuxUser" │
│ *──deleteall* # (all = local/non─policy─defined) │
│ *──extract * # ← (for use within TX) │
│ *──list * [──locallist] │
│ ^^^^^^^^^^^ │
│ show local │
│ (non─defined─by─policy) │
│ customizations │
│OTHER OPTIONS: │
│ ──noreload ← Do NOT reload policy after commit │
│ ──store STORE ← Select alternate SELinux Policy Store │
└────────────────────────────────────────────────────────────────────┘
Examples:
┌──────────────────────┐ ┌──────────────────────────┐
│*Restricting su/sudo *│ │*disable script execution*│
├──────────────────────┴───────────────────────┐ ├──────────────────────────┴────────────────────┐
│ [regularuser@localhost ~]$*id ─ * │ │By default, SELinux allows users mapped to the │
│*unconfined_u:unconfined_r:unconfined_t:s0* │ │guest_t account to exec $HOME/* scripts │
│ │ │ │
│ regularuser@localhost ~]$ su ─ switcheduser │ │#~*getsebool* *allow_guest_exec_content* │
│ Password: XXXX │ │→ guest_exec_content ─ → hon │
│ → [switcheduser@localhost ~]$ │ │ │
│ │ │[guestuser@localhost ~]$ ~/myscript.sh │
│ #~*semanage login ─a ─s user_u regularuser* │ │→ This is a test script │
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ │ │ │
│ Remap linux_user to selinux user │ │#~*setsebool* *allow_guest_exec_content* off │
│ │ │[guestuser@localhost ~]$ ~/myscript.sh │
│ [regularuser@localhost ~]$*id ─ * │ │→ bash: myscript.sh: *Permission denied* │
│*user_u:user_r:user_t:s0* │ └───────────────────────────────────────────────┘
│ │
│ [regularuser@localhost ~]$ su ─ switcheduser │
│ Password: XXXX │
│ → su: *Authentication failure* │
└──────────────────────────────────────────────┘
# SELINUX PROCESS CONTEXT-SWITCH
- Kernel takes care of automatic process-context-labeling once
a policy has been loaded.
- Next commands can be used to alter or display the process labeling:
*runcon(1)* run command with given ctx (user, role and domain)
*secon(1) * See ctx from a file|program|user-input
*newrole(1)* creates new shell running with new sec.ctx.
Use must specify new role and/or type.
type is derived from role if not specified.
*run_init(9)* Runs initrc script using the sec.ctx.
found in current policy's ctx/initrc_context
file. Ussually used to restart system
services in new intended domain
*PROCESS LABELING FLOW AT LOGIN:* TODO
- Login process sets a default context (unconfined for targeted policy)
Policy defined Context transitions will change children process context
at runtime.
*PROCESS CONTEXT TRANSITION*
- A default context is given upon login defined by the
policy login-objects (see [[semanage login?]] )
- Context Transtion Flow:
app_1 → Execute /usr/bin/app_2 → app_2
domain/type *src_t* *app_exec_t* *target_t*
↑ ↑
Requirements 1)- policy must define 2)- policy must define
exec permission to *app_exec_t* as entrypoint
*app_exec_t* entry-point to *target_t*
3)- policy must allow
transition from *src_t*
to *target_t*
Check 1): Check 2): Check 3):
#~ sesearch #~ sesearch #~ sesearch
-s *src_t* -s *target_t* -s *src_t*
-t *app_exec_t* -t *target_t* -t *target_t*
-c file -c file -c process ← (selinux-kernel)class
-p execute -p entrypoint -p transition ← action requite for class
-Ad -Ad -Ad (See [[selinux object classes?]])
# SELINUX Booleans
<a href="https://linux.die.net/man/8/booleans">man 8 booleans</a>
- Allow to customize a given policy at runtime.
- Common to-many-apps actions that can be allowed/denied are "grouped"
into booleans
Ex:
- """ Do we allow the ftp server access to home directories? """
- """ Can httpd use mod_auth_ntlm_winbind ? """
- ...
┌───────────────────┐ ┌─────────────────┐
│*List Booleans Set*│ │*Change Booleans*│
├───────────────────┴─────────────────────────────┐ ├─────────────────┴──────────────────────────────┐
│ ─ Take a look at the "booleans.local" file under│ │$ sudO*getsebool - * ← Show all booleans│
│ /etc/selinux/targeted/modules/active/ │ │ │
│ Ex: │ │$ sudO*setsebool* \ ← Set boolean │
│ # This file is auto─generated by libsemanage │ │ ─P "mySELinuxBoolean" 0│1 │
│ # Do not edit directly. │ │ ☝(opt.flag.) │
│ │ │ Persist reboot │
│ httpd_read_user_content=1 │ │ │
│ httpd_enable_homedirs=1 │ │$ sudo *togglesebool* \ ← toggle 1⇿0 value │
└─────────────────────────────────────────────────┘ │ ─P "mySELinuxBoolean" │
└────────────────────────────────────────────────┘
<a href="http://stackoverflow.com/questions/23851452/cant-resolve-domain-names-in-php-under-apache/24019910#24019910">Ex@Stackoverflow: Fix Apache DNS problem:</a>
$ sudO*setsebool* -P nis_enabled 0
$ sudO*setsebool* -P httpd_can_network_connect 1
# SELINUX TROUBLESHOOTING:
┌─────────────────────────────────┐ ┌──────────────────────────────┐
│*Q: What an SELinux error means?*│ │*BUG FIXING GENERAL PROCEDURE*│
├─────────────────────────────────┴────────────────────────────────┐ ├──────────────────────────────┴───────────────────────────────┐
║ A: It can means: ║ │ *STEP 01: Check /var/log/messages* for messages like │
║ ┌────────────────────────────────────┐ ║ │ ... │
║ │*A.1: file─system labeling is wrong*│ ║ │ ... setroubleshoot: SELinux is preventing /usr/bin/httpd \ │
║ ├────────────────────────────────────┴────────────────────────┐ ║ │ from getattr access on the directory /home/fred. \ │
║ │Fix examples: │ ║ │ *For complet SELinux messages, run \ │
║ │Ex 1: │ ║ │ sealert ─l 37acc7d8─e955─4333─123a─1d027dbcea72* │
║ │ # sudo *chcon* ──reference /var/www/html ..../index.html │ ║ │ │
║ │Ex 2: │ ║ │ *STEP 02: Run the indicated command* │
║ │ #*restorecon*─vR /var/www/html │ ║ │ ~# sealert ─l 37acc7d8─e955─4333─123a─1d027dbcea72 │
║ │ ^^^^^^^^^^ │ ║ │ → SELinux is preventing /usr/sbin/httpd from search access \│
║ │ uses info from │ ║ │ on the directory /home/fred │
║ │ /etc/selinux/targeted/contexts/files/file_contexts, ... │ ║ │ → ... │
║ │ to determine what a file or dir's ctx should be │ ║ │ → *Do * │
║ │Ex 3: │ ║ │ → *setsebool ─P httpd_read_user_content 1 * │
║ │ #*semanage* fcontext ─a ─e /var/www/ /my/alternative/www/ │ ║ │ → *... * │
║ │ ^^^^^^^^ │ ║ │ → *setsebool ─P httpd_enable_homedirs 1 * │
║ │ WARN: we are just defining what the context is, │ ║ └──────────────────────────────────────────────────────────────┘
║ │ we are not writing what the │ ║ ┌──────────────────────────────────┐
║ │ extended attributes are. It just means: │ ║ │*AUDITING SELINUX ERROR MESSAGES.*│
║ │ "On relable it must look like this" │ ║ ├──────────────────────────────────┴─────────────────────────────────────────────────────────┐
║ │ # restorecon ─vR /my/alternative/www │ ║ │ #~ ausearch ─m *avc* ─c httpd │
║ │ ^^^^^^^^^^ │ ║ │ └──────┘ └──┘ │
║ │ must be run to actually proceed with relabeling │ ║ │ standard filter by │
║ └─────────────────────────────────────────────────────────────┘ ║ │ linux AVC related │
║ ┌────────────────────────────────────┐ ║ │ audit messaged │
║ │ *A.2: Policy needs to be tweaked* │ ║ │ framework │
║ ├────────────────────────────────────┴────────────────────────┐ ║ │ tool │
║ │ ─ booleans │ ║ │ (auditd daemon │
║ │ ─ policy modules │ ║ │ must be running) │
║ └─────────────────────────────────────────────────────────────┘ ║ │ → ... │
║ ┌────────────────────────────────────┐ ║ │ → time → Thu Aug 21 16:42:17 2014 │
║ │ *A.3: A bug in the policy* │ ║ │ → type=AVC msg=audit(1408603337.115:914): avc: denied { getattr } for \ │
║ ├────────────────────────────────────┴─────────────────────────┐ ║ │ pid=10204 comm="httpd" path="/www/html/index.html" dev="dm─0" ino=8445484 \ │
║ │ App vendors must supply policy modules for SELinux systems. │ ║ │ scontext=system_u:system_r:httpd_t:s0 \ │
║ │ You must submit a ticket to the app vendor following steps: │ ║ │ tcontext=unconfined_u:object_r:default_t:s0 tclass=file │
║ │─ STEP 1: │ ║ │ └ translates to: │
║ │ # setenforce 0 ← change to "permissive" mode and run │ ║ │ type=AVC: ...: avc: The message comes from the AVC log and it's an AVC event │
║ │ the application through all its paces │ ║ │ denied { getattr }: The permission that was attempted and the result it got. │
║ │ to log *all SELinux denials* │ ║ │ In this case the get attribute operation was denied. │
║ │─ STEP 2: │ ║ │ pid=10204 process id of the process that attempted the access. │
║ │ From /var/log/messages Copy and Paste the proposed solution:│ ║ │ comm="httpd" shows the process command for the pid │
║ │ # grep httpd /var/log/audit/audit.log │ \ │ ║ │ path: resource trying to be accessed. │
║ │ *audit2allow* ─MO*quirrellocal* │ ║ │ dev : device │
║ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ │ ║ │ ino : inode │
║ │ generate new policy file │ ║ │ scontext: source security context of the process. │
║ │ (See also audit2why(1) │ ║ │ tcontext: target security context of the resource. │
║ │─ STEP 3: │ ║ │ tclass: target resource class. │
║ │ #*semodule ─ * *squirrellocal.pp* ← Import the new module │ ║ │ │
║ │ │ ║ │ *sealert tool* │
║ │─ STEP 4: │ ║ │ #~ cat /var/log/messages │ grep "SELinux is preventing" │
║ │ # setenforce 1 ← Re─enable enforcement │ ║ │ → ... │
║ └──────────────────────────────────────────────────────────────┘ ║ │ → ... setroubleshoot: SELinux is preventing /usr/bin/su from using the setuid capability \ │
║ ║ │ For complete SELinux messages. run sealert ─l *e9e6c6d8─f217─414c─a14e─4bccb70cfbce*│
║ ┌───────────────────────────────────────────────────┐ ║ │ #~ sealert ─l *e9e6c6d8─f217─414c─a14e─4bccb70cfbce* │
║ │ *A.4: You have been, or are being, broken into!!* │ ║ │ → SELinux is preventing /usr/bin/su from using the setuid capability. │
║ ├───────────────────────────────────────────────────┴──────────┐ ║ │ → ... │
║ │ ─ HOUSTON: We have a problem │ ║ │ → Raw Audit Messages │
║ └──────────────────────────────────────────────────────────────┘ ║ │ → type=AVC msg=audit(1408931985.387:850): avc: denied { setuid } for pid=5855 \ │
╚══════════════════════════════════════════════════════════════════╝ │ comm="sudo" capability=7 scontext=user_u:user_r:user_t:s0 \ │
│ tcontext=user_u:user_r:user_t:s0 tclass=capability │
│ → type=SYSCALL msg=audit(1408931985.387:850): arch=x86_64 syscall=setresuid success=no \ │
│ exit=EPERM a0=ffffffff a1=1 a2=ffffffff a3=7fae591b92e0 items=0 ppid=5739 pid=5855 \ │
│ auid=1008 uid=0 gid=1008 euid=0 suid=0 fsuid=0 egid=0 sgid=1008 fsgid=0 tty=pts2 ses=22 \│
│ comm=sudo exe=/usr/bin/sudo subj=user_u:user_r:user_t:s0 key=(null) │
│ → │
│ → Hash: su,user_t,user_t,capability,setuid │
│ → │
└────────────────────────────────────────────────────────────────────────────────────────────┘
[[linux.security.selinux}]]