aboutsummaryrefslogtreecommitdiff
blob: 06655e11f2b02186cc301c97126aef4dcb6266da (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
## <summary>Package Management System.</summary>

########################################
## <summary>
##	Execute emerge in the portage domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
#
interface(`portage_domtrans',`
	gen_require(`
		type portage_t, portage_exec_t;
	')

	corecmd_search_bin($1)
	domtrans_pattern($1, portage_exec_t, portage_t)
')

########################################
## <summary>
##	Execute emerge in the portage domain,
##	and allow the specified role the
##	portage domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`portage_run',`
	gen_require(`
		attribute_role portage_roles;
	')

	portage_domtrans($1)
	roleattribute $2 portage_roles;
')

########################################
## <summary>
##	Template for portage sandbox.
## </summary>
## <desc>
##	<p>
##	Template for portage sandbox.  Portage
##	does all compiling in the sandbox.
##	</p>
## </desc>
## <param name="domain">
##	<summary>
##	Domain Allowed Access
##	</summary>
## </param>
#
interface(`portage_compile_domain',`
	gen_require(`
		class dbus send_msg;
		type portage_devpts_t, portage_log_t, portage_srcrepo_t, portage_tmp_t;
		type portage_tmpfs_t;
	')

	allow $1 self:capability { fowner fsetid mknod setgid setuid chown dac_override net_raw };
	dontaudit $1 self:capability sys_chroot;
	allow $1 self:process { setpgid setsched setrlimit signal_perms execmem setfscreate };
	allow $1 self:process ~{ ptrace setcurrent setexec setrlimit execmem execstack execheap };
	allow $1 self:fd use;
	allow $1 self:fifo_file rw_fifo_file_perms;
	allow $1 self:shm create_shm_perms;
	allow $1 self:sem create_sem_perms;
	allow $1 self:msgq create_msgq_perms;
	allow $1 self:msg { send receive };
	allow $1 self:unix_dgram_socket create_socket_perms;
	allow $1 self:unix_stream_socket create_stream_socket_perms;
	allow $1 self:unix_dgram_socket sendto;
	allow $1 self:unix_stream_socket connectto;
	# really shouldnt need this
	allow $1 self:tcp_socket create_stream_socket_perms;
	allow $1 self:udp_socket create_socket_perms;
	# misc networking stuff (esp needed for compiling perl):
	allow $1 self:rawip_socket { create ioctl };
	# needed for merging dbus:
	allow $1 self:netlink_selinux_socket { bind create read };
	allow $1 self:dbus send_msg;

	allow $1 portage_devpts_t:chr_file { rw_chr_file_perms setattr_chr_file_perms };
	term_create_pty($1, portage_devpts_t)

	# write compile logs
	allow $1 portage_log_t:dir setattr_dir_perms;
	allow $1 portage_log_t:file { write_file_perms setattr_file_perms };

	# Support live ebuilds (-9999)
	manage_dirs_pattern($1, portage_srcrepo_t, portage_srcrepo_t)
	manage_files_pattern($1, portage_srcrepo_t, portage_srcrepo_t)
	manage_lnk_files_pattern($1, portage_srcrepo_t, portage_srcrepo_t)

	# run scripts out of the build directory
	can_exec(portage_sandbox_t, portage_tmp_t)

	manage_dirs_pattern($1, portage_tmp_t, portage_tmp_t)
	manage_files_pattern($1, portage_tmp_t, portage_tmp_t)
	manage_lnk_files_pattern($1, portage_tmp_t, portage_tmp_t)
	manage_fifo_files_pattern($1, portage_tmp_t, portage_tmp_t)
	manage_sock_files_pattern($1, portage_tmp_t, portage_tmp_t)
	files_tmp_filetrans($1, portage_tmp_t, { dir file lnk_file sock_file fifo_file })
	# SELinux-enabled programs running in the sandbox
	allow $1 portage_tmp_t:file relabel_file_perms;

	manage_files_pattern($1, portage_tmpfs_t, portage_tmpfs_t)
	manage_lnk_files_pattern($1, portage_tmpfs_t, portage_tmpfs_t)
	manage_fifo_files_pattern($1, portage_tmpfs_t, portage_tmpfs_t)
	manage_sock_files_pattern($1, portage_tmpfs_t, portage_tmpfs_t)
	fs_tmpfs_filetrans($1, portage_tmpfs_t, { dir file lnk_file sock_file fifo_file })

	kernel_read_system_state($1)
	kernel_read_network_state($1)
	kernel_read_software_raid_state($1)
	kernel_getattr_core_if($1)
	kernel_getattr_message_if($1)
	kernel_read_kernel_sysctls($1)

	corecmd_exec_all_executables($1)

	# really shouldnt need this but some packages test
	# network access, such as during configure
	# also distcc--need to reinvestigate confining distcc client
	corenet_all_recvfrom_unlabeled($1)
	corenet_all_recvfrom_netlabel($1)
	corenet_tcp_sendrecv_generic_if($1)
	corenet_udp_sendrecv_generic_if($1)
	corenet_raw_sendrecv_generic_if($1)
	corenet_tcp_sendrecv_generic_node($1)
	corenet_udp_sendrecv_generic_node($1)
	corenet_raw_sendrecv_generic_node($1)
	corenet_tcp_sendrecv_all_ports($1)
	corenet_udp_sendrecv_all_ports($1)
	corenet_tcp_connect_all_reserved_ports($1)
	corenet_tcp_connect_distccd_port($1)
	corenet_tcp_connect_git_port($1)

	dev_read_sysfs($1)
	dev_read_rand($1)
	dev_read_urand($1)

	domain_use_interactive_fds($1)
	domain_dontaudit_read_all_domains_state($1)
	# SELinux-aware installs doing relabels in the sandbox
	domain_obj_id_change_exemption($1)

	files_exec_etc_files($1)
	files_exec_usr_src_files($1)

	fs_getattr_xattr_fs($1)
	fs_list_noxattr_fs($1)
	fs_read_noxattr_fs_files($1)
	fs_read_noxattr_fs_symlinks($1)
	fs_search_auto_mountpoints($1)

	selinux_validate_context($1)
	# needed for merging dbus:
	selinux_compute_access_vector($1)

	files_list_non_auth_dirs($1)
	files_read_non_auth_files($1)
	files_read_non_auth_symlinks($1)

	libs_exec_lib_files($1)
	# some config scripts use ldd
	libs_exec_ld_so($1)
	libs_exec_ldconfig($1)

	logging_send_syslog_msg($1)

	userdom_use_user_terminals($1)

	# SELinux-enabled programs running in the sandbox
	seutil_libselinux_linked($1)

	tunable_policy(`portage_use_nfs',`
		fs_getattr_nfs($1)
		fs_manage_nfs_dirs($1)
		fs_manage_nfs_files($1)
		fs_manage_nfs_symlinks($1)
	')

	ifdef(`TODO',`
	# some gui ebuilds want to interact with X server, like xawtv
	optional_policy(`
		allow $1 xdm_xserver_tmp_t:dir { add_entry_dir_perms del_entry_dir_perms };
		allow $1 xdm_xserver_tmp_t:sock_file { create_file_perms delete_file_perms write_file_perms };
	')
	') dnl end TODO
')

########################################
## <summary>
##	Execute tree management functions
##	(fetching, layman, ...) in the
##	portage fetch domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
#
interface(`portage_domtrans_fetch',`
	gen_require(`
		type portage_fetch_t, portage_fetch_exec_t;
	')

	corecmd_search_bin($1)
	domtrans_pattern($1, portage_fetch_exec_t, portage_fetch_t)
')

########################################
## <summary>
##	Execute tree management functions
##	(fetching, layman, ...) in the
##	portage fetch domain, and allow
##	the specified role the portage
##	fetch domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`portage_run_fetch',`
	gen_require(`
		attribute_role portage_fetch_roles;
	')

	portage_domtrans_fetch($1)
	roleattribute $2 portage_fetch_roles;
')

########################################
## <summary>
##	Execute gcc-config in the gcc config domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
#
interface(`portage_domtrans_gcc_config',`
	gen_require(`
		type gcc_config_t, gcc_config_exec_t;
	')

	corecmd_search_bin($1)
	domtrans_pattern($1, gcc_config_exec_t, gcc_config_t)
')

########################################
## <summary>
##	Execute gcc-config in the gcc config
##	domain, and allow the specified role
##	the gcc_config domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`portage_run_gcc_config',`
	gen_require(`
		attribute_role gcc_config_roles;
	')

	portage_domtrans_gcc_config($1)
	roleattribute $2 gcc_config_roles;
')

########################################
## <summary>
##	Do not audit attempts to use
##	portage file descriptors.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`portage_dontaudit_use_fds',`
	gen_require(`
		type portage_t;
	')

	dontaudit $1 portage_t:fd use;
')

########################################
## <summary>
##	Do not audit attempts to search the
##	portage temporary directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`portage_dontaudit_search_tmp',`
	gen_require(`
		type portage_tmp_t;
	')

	dontaudit $1 portage_tmp_t:dir search_dir_perms;
')

########################################
## <summary>
##	Do not audit attempts to read and write
##	the portage temporary files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`portage_dontaudit_rw_tmp_files',`
	gen_require(`
		type portage_tmp_t;
	')

	dontaudit $1 portage_tmp_t:file rw_file_perms;
')

########################################
## <summary>
##   Allow the domain to run within an eselect module script. 
## </summary>
## <param name="domain">
##     <summary>
##     Domain to allow within an eselect module
##     </summary>
## </param>
#   Specific to Gentoo,
#   eselect modules allow users to switch between different flavors or versions
#   of underlying components. In return, eselect makes a wrapper binary which 
#   makes the proper selections. If this binary is different from bin_t, it might
#   not hold the necessary privileges for the wrapper to function. However, just
#   marking the target binaries doesn't always work, since for python scripts the
#   wrapper doesn't execute it, but treats the target as a library.
#
interface(`portage_eselect_module',`
       gen_require(`
               attribute portage_eselect_domain;
       ')

       typeattribute $1 portage_eselect_domain;
')

########################################
## <summary>
##	Read portage cache files
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access
##	</summary>
## </param>
#
interface(`portage_read_cache',`
	gen_require(`
		type portage_cache_t;
	')

	files_search_var($1)
	list_dirs_pattern($1, portage_cache_t, portage_cache_t)
	read_files_pattern($1, portage_cache_t, portage_cache_t)
	read_lnk_files_pattern($1, portage_cache_t, portage_cache_t)
')

########################################
## <summary>
##	Read portage configuration files
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access
##	</summary>
## </param>
#
interface(`portage_read_config',`
	gen_require(`
		type portage_conf_t;
	')

	files_search_etc($1)
	list_dirs_pattern($1, portage_conf_t, portage_conf_t)
	read_files_pattern($1, portage_conf_t, portage_conf_t)
	read_lnk_files_pattern($1, portage_conf_t, portage_conf_t)
')

########################################
## <summary>
##	Read portage ebuild files
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access
##	</summary>
## </param>
#
interface(`portage_read_ebuild',`
	gen_require(`
		type portage_ebuild_t;
	')

	files_search_usr($1)
	list_dirs_pattern($1, portage_ebuild_t, portage_ebuild_t)
	read_files_pattern($1, portage_ebuild_t, portage_ebuild_t)
	read_lnk_files_pattern($1, portage_ebuild_t, portage_ebuild_t)
')