Skip to content

Commit 63b2ad8

Browse files
committed
fixup! fixup! fixup! Introduce SELinux policy for libvirt drivers
1 parent 394a8d9 commit 63b2ad8

File tree

4 files changed

+235
-44
lines changed

4 files changed

+235
-44
lines changed

virt.fc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ HOME_DIR/\.local/share/libvirt/boot(/.*)? gen_context(system_u:object_r:svirt_
3838
/usr/sbin/virtxend -- gen_context(system_u:object_r:virtxend_exec_t,s0)
3939

4040
/var/cache/libvirt(/.*)? gen_context(system_u:object_r:virt_cache_t,s0-mls_systemhigh)
41+
/var/cache/libvirt-tck(/.*)? gen_context(system_u:object_r:virt_cache_t,s0-mls_systemhigh)
4142

4243
/var/lib/libvirt(/.*)? gen_context(system_u:object_r:virt_var_lib_t,s0)
4344
/var/lib/libvirt/boot(/.*)? gen_context(system_u:object_r:virt_content_t,s0)
@@ -49,9 +50,16 @@ HOME_DIR/\.local/share/libvirt/boot(/.*)? gen_context(system_u:object_r:svirt_
4950
/var/log/log(/.*)? gen_context(system_u:object_r:virt_log_t,s0)
5051
/var/log/libvirt(/.*)? gen_context(system_u:object_r:virt_log_t,s0)
5152
/var/run/libvirtd\.pid -- gen_context(system_u:object_r:virt_var_run_t,s0)
53+
# Avoid calling m4's "interface" by using en empty string
54+
/var/run/libvirt/interfac(e)(/.*)? gen_context(system_u:object_r:virtinterfaced_var_run_t,s0)
55+
/var/run/libvirt/nodedev(/.*)? gen_context(system_u:object_r:virtnodedevd_var_run_t,s0)
56+
/var/run/libvirt/nwfilter(/.*)? gen_context(system_u:object_r:virtnwfilterd_var_run_t,s0)
57+
/var/run/libvirt/secrets(/.*)? gen_context(system_u:object_r:virtsecretd_var_run_t,s0)
58+
/var/run/libvirt/storage(/.*)? gen_context(system_u:object_r:virtstoraged_var_run_t,s0)
59+
5260
/var/run/virtlogd\.pid -- gen_context(system_u:object_r:virtlogd_var_run_t,s0)
5361
/var/run/virtlxcd\.pid -- gen_context(system_u:object_r:virt_lxc_var_run_t,s0)
54-
/var/run/virtqemud\.pid -- gen_context(system_u:object_r:qemu_var_run_t,s0)
62+
/var/run/virtqemud\.pid -- gen_context(system_u:object_r:virtqemud_var_run_t,s0)
5563
/var/run/virtvboxd\.pid -- gen_context(system_u:object_r:virtvboxd_var_run_t,s0)
5664
/var/run/virtproxyd\.pid -- gen_context(system_u:object_r:virtproxyd_var_run_t,s0)
5765
/var/run/virtinterfaced\.pid -- gen_context(system_u:object_r:virtinterfaced_var_run_t,s0)
@@ -61,9 +69,10 @@ HOME_DIR/\.local/share/libvirt/boot(/.*)? gen_context(system_u:object_r:svirt_
6169
/var/run/virtsecretd\.pid -- gen_context(system_u:object_r:virtsecretd_var_run_t,s0)
6270
/var/run/virtstoraged\.pid -- gen_context(system_u:object_r:virtstoraged_var_run_t,s0)
6371

64-
/var/run/libvirt(/.*)? gen_context(system_u:object_r:virt_var_run_t,s0)
72+
/var/run/libvirt(/.*)? gen_context(system_u:object_r:virt_var_run_t,s0)
6573
/var/run/libvirt/qemu(/.*)? gen_context(system_u:object_r:qemu_var_run_t,s0-mls_systemhigh)
6674
/var/run/libvirt/lxc(/.*)? gen_context(system_u:object_r:virt_lxc_var_run_t,s0)
75+
/var/run/libvirt/libvirt-sock -s gen_context(system_u:object_r:virt_var_run_t,s0)
6776
/var/run/libvirt/virtlogd-sock -s gen_context(system_u:object_r:virtlogd_var_run_t,s0)
6877
/var/run/libvirt/virtinterfaced-admin-sock -s gen_context(system_u:object_r:virtinterfaced_var_run_t,s0)
6978
/var/run/libvirt/virtinterfaced-sock -s gen_context(system_u:object_r:virtinterfaced_var_run_t,s0)
@@ -83,9 +92,9 @@ HOME_DIR/\.local/share/libvirt/boot(/.*)? gen_context(system_u:object_r:svirt_
8392
/var/run/libvirt/virtproxyd-admin-sock -s gen_context(system_u:object_r:virtproxyd_var_run_t,s0)
8493
/var/run/libvirt/virtproxyd-sock -s gen_context(system_u:object_r:virtproxyd_var_run_t,s0)
8594
/var/run/libvirt/virtproxyd-sock-ro -s gen_context(system_u:object_r:virtproxyd_var_run_t,s0)
86-
/var/run/libvirt/virtqemud-admin-sock -s gen_context(system_u:object_r:qemu_var_run_t,s0)
87-
/var/run/libvirt/virtqemud-sock -s gen_context(system_u:object_r:qemu_var_run_t,s0)
88-
/var/run/libvirt/virtqemud-sock-ro -s gen_context(system_u:object_r:qemu_var_run_t,s0)
95+
/var/run/libvirt/virtqemud-admin-sock -s gen_context(system_u:object_r:virtqemud_var_run_t,s0)
96+
/var/run/libvirt/virtqemud-sock -s gen_context(system_u:object_r:virtqemud_var_run_t,s0)
97+
/var/run/libvirt/virtqemud-sock-ro -s gen_context(system_u:object_r:virtqemud_var_run_t,s0)
8998
/var/run/libvirt/virtsecretd-admin-sock -s gen_context(system_u:object_r:virtsecretd_var_run_t,s0)
9099
/var/run/libvirt/virtsecretd-sock -s gen_context(system_u:object_r:virtsecretd_var_run_t,s0)
91100
/var/run/libvirt/virtsecretd-sock-ro -s gen_context(system_u:object_r:virtsecretd_var_run_t,s0)

virt.if

Lines changed: 119 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ template(`virt_driver_template',`
114114
gen_require(`
115115
attribute virt_driver_domain;
116116
attribute virt_driver_executable;
117+
attribute virt_driver_var_run;
117118
')
118119

119120
type $1_t, virt_driver_domain;
121+
120122
type $1_exec_t, virt_driver_executable;
121123
init_daemon_domain($1_t, $1_exec_t)
122124

123-
type $1_var_run_t;
125+
type $1_var_run_t, virt_driver_var_run;
124126
files_pid_file($1_var_run_t)
125127

126128
##################################
@@ -139,11 +141,11 @@ template(`virt_driver_template',`
139141
manage_files_pattern($1_t, $1_var_run_t, $1_var_run_t)
140142
manage_sock_files_pattern($1_t, virt_var_run_t, $1_var_run_t)
141143
files_pid_filetrans($1_t, $1_var_run_t, { dir file sock_file } )
142-
filetrans_pattern($1_t, virt_var_run_t, $1_var_run_t, { dir file sock_file } )
143144

144145
read_files_pattern($1_t, virt_etc_t, virt_etc_t)
145146
manage_dirs_pattern($1_t, virt_etc_rw_t, virt_etc_rw_t)
146147
manage_files_pattern($1_t, virt_etc_rw_t, virt_etc_rw_t)
148+
filetrans_pattern($1_t, virt_etc_t, virt_etc_rw_t, dir)
147149

148150
allow virt_driver_domain virtqemud_t:unix_stream_socket connectto;
149151
read_files_pattern(virt_driver_domain, virtqemud_t, virtqemud_t)
@@ -157,13 +159,28 @@ template(`virt_driver_template',`
157159

158160
dev_read_sysfs($1_t)
159161

162+
files_read_non_security_files($1_t)
160163
init_read_utmp($1_t)
161164

162165
logging_send_syslog_msg($1_t)
163166

164167
miscfiles_read_generic_certs($1_t)
165168

169+
virt_manage_cache($1_t)
170+
virt_manage_pid_files($1_t)
171+
virt_stream_connect($1_t)
172+
173+
optional_policy(`
174+
dbus_system_bus_client($1_t)
175+
')
176+
166177
optional_policy(`
178+
dnsmasq_filetrans_named_content_fromdir($1_t, $1_var_run_t)
179+
')
180+
181+
optional_policy(`
182+
systemd_dbus_chat_logind($1_t)
183+
systemd_machined_stream_connect($1_t)
167184
systemd_write_inhibit_pipes($1_t)
168185
')
169186
')
@@ -202,6 +219,7 @@ interface(`virt_image',`
202219
#
203220
interface(`virt_getattr_exec',`
204221
gen_require(`
222+
attribute virt_driver_executable;
205223
type virtd_exec_t;
206224
')
207225

@@ -239,6 +257,7 @@ interface(`virt_domtrans',`
239257
#
240258
interface(`virt_exec',`
241259
gen_require(`
260+
attribute virt_driver_executable;
242261
type virtd_exec_t;
243262
')
244263

@@ -261,13 +280,33 @@ interface(`virt_stream_connect',`
261280
attribute virt_driver_domain;
262281
attribute virt_driver_var_run;
263282
type virtd_t, virt_var_run_t;
264-
')
283+
')
265284

266285
files_search_pids($1)
267286
stream_connect_pattern($1, virt_var_run_t, virt_var_run_t, virtd_t)
268-
stream_connect_pattern($1, virt_driver_var_run, virt_driver_var_run, virt_driver_domain)
287+
stream_connect_pattern($1, virt_driver_var_run, virt_driver_var_run, virt_driver_domain)
269288
')
270289

290+
########################################
291+
## <summary>
292+
## Read and write to virt_domain unix
293+
## stream sockets.
294+
## </summary>
295+
## <param name="domain">
296+
## <summary>
297+
## Domain allowed access.
298+
## </summary>
299+
## </param>
300+
#
301+
interface(`virt_rw_stream_sockets_virt_domain',`
302+
gen_require(`
303+
attribute virt_domain;
304+
')
305+
306+
allow $1 virt_domain:unix_stream_socket { read write };
307+
')
308+
309+
271310
#######################################
272311
## <summary>
273312
## Connect to svirt process over a unix domain stream socket.
@@ -1252,7 +1291,7 @@ interface(`virt_signal',`
12521291
#
12531292
interface(`virt_signull',`
12541293
gen_require(`
1255-
virt_driver_domain;
1294+
attribute virt_driver_domain;
12561295
type virtd_t;
12571296
')
12581297

@@ -1402,6 +1441,43 @@ interface(`virt_dontaudit_read_chr_dev',`
14021441
dontaudit $1 virt_image_type:chr_file read_chr_file_perms;
14031442
')
14041443

1444+
########################################
1445+
## <summary>
1446+
## Make the specified type usable as a virt file type
1447+
## </summary>
1448+
## <param name="type">
1449+
## <summary>
1450+
## Type to be used as a virt file type
1451+
## </summary>
1452+
## </param>
1453+
#
1454+
interface(`virt_file_types',`
1455+
gen_require(`
1456+
attribute virt_file_type;
1457+
')
1458+
1459+
typeattribute $1 virt_file_type;
1460+
')
1461+
1462+
########################################
1463+
## <summary>
1464+
## Make the specified type usable as a svirt file type
1465+
## </summary>
1466+
## <param name="type">
1467+
## <summary>
1468+
## Type to be used as a svirt file type
1469+
## </summary>
1470+
## </param>
1471+
#
1472+
interface(`svirt_file_types',`
1473+
gen_require(`
1474+
attribute svirt_file_type;
1475+
')
1476+
1477+
typeattribute $1 svirt_file_type;
1478+
')
1479+
1480+
14051481
########################################
14061482
## <summary>
14071483
## Creates types and rules for a basic
@@ -1472,6 +1548,24 @@ template(`virt_sandbox_net_domain',`
14721548
typeattribute $1 sandbox_net_domain;
14731549
')
14741550

1551+
########################################
1552+
## <summary>
1553+
## Make the specified type usable as a virt system domain
1554+
## </summary>
1555+
## <param name="type">
1556+
## <summary>
1557+
## Type to be used as a virt system domain
1558+
## </summary>
1559+
## </param>
1560+
#
1561+
interface(`virt_system_domain_type',`
1562+
gen_require(`
1563+
attribute virt_system_domain;
1564+
')
1565+
1566+
typeattribute $1 virt_system_domain;
1567+
')
1568+
14751569
########################################
14761570
## <summary>
14771571
## Execute a qemu_exec_t in the callers domain
@@ -1802,6 +1896,26 @@ interface(`virt_dgram_send',`
18021896
dgram_send_pattern($1, virt_var_run_t, virt_var_run_t, virtd_t)
18031897
')
18041898

1899+
########################################
1900+
## <summary>
1901+
## Manage svirt home files,dirs and sockfiles.
1902+
## </summary>
1903+
## <param name="domain">
1904+
## <summary>
1905+
## Domain allowed access.
1906+
## </summary>
1907+
## </param>
1908+
#
1909+
interface(`virt_svirt_manage_home',`
1910+
gen_require(`
1911+
type svirt_home_t;
1912+
')
1913+
1914+
manage_files_pattern($1, svirt_home_t, svirt_home_t)
1915+
manage_dirs_pattern($1, svirt_home_t, svirt_home_t)
1916+
manage_sock_files_pattern($1, svirt_home_t, svirt_home_t)
1917+
')
1918+
18051919
########################################
18061920
## <summary>
18071921
## Manage svirt tmp files,dirs and sockfiles.

0 commit comments

Comments
 (0)