Skip to content

Commit efecdd0

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

File tree

3 files changed

+142
-27
lines changed

3 files changed

+142
-27
lines changed

virt.if

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ template(`virt_driver_template',`
144144
read_files_pattern($1_t, virt_etc_t, virt_etc_t)
145145
manage_dirs_pattern($1_t, virt_etc_rw_t, virt_etc_rw_t)
146146
manage_files_pattern($1_t, virt_etc_rw_t, virt_etc_rw_t)
147+
filetrans_pattern($1_t, virt_etc_t, virt_etc_rw_t, dir)
147148

148149
allow virt_driver_domain virtqemud_t:unix_stream_socket connectto;
149150
read_files_pattern(virt_driver_domain, virtqemud_t, virtqemud_t)
@@ -164,6 +165,11 @@ template(`virt_driver_template',`
164165
miscfiles_read_generic_certs($1_t)
165166

166167
optional_policy(`
168+
dbus_system_bus_client($1_t)
169+
')
170+
171+
optional_policy(`
172+
systemd_dbus_chat_logind($1_t)
167173
systemd_write_inhibit_pipes($1_t)
168174
')
169175
')
@@ -202,6 +208,7 @@ interface(`virt_image',`
202208
#
203209
interface(`virt_getattr_exec',`
204210
gen_require(`
211+
attribute virt_driver_executable;
205212
type virtd_exec_t;
206213
')
207214

@@ -239,6 +246,7 @@ interface(`virt_domtrans',`
239246
#
240247
interface(`virt_exec',`
241248
gen_require(`
249+
attribute virt_driver_executable;
242250
type virtd_exec_t;
243251
')
244252

@@ -268,6 +276,26 @@ interface(`virt_stream_connect',`
268276
stream_connect_pattern($1, virt_driver_var_run, virt_driver_var_run, virt_driver_domain)
269277
')
270278

279+
########################################
280+
## <summary>
281+
## Read and write to virt_domain unix
282+
## stream sockets.
283+
## </summary>
284+
## <param name="domain">
285+
## <summary>
286+
## Domain allowed access.
287+
## </summary>
288+
## </param>
289+
#
290+
interface(`virt_rw_stream_sockets_virt_domain',`
291+
gen_require(`
292+
attribute virt_domain;
293+
')
294+
295+
allow $1 virt_domain:unix_stream_socket { read write };
296+
')
297+
298+
271299
#######################################
272300
## <summary>
273301
## Connect to svirt process over a unix domain stream socket.
@@ -1252,7 +1280,7 @@ interface(`virt_signal',`
12521280
#
12531281
interface(`virt_signull',`
12541282
gen_require(`
1255-
virt_driver_domain;
1283+
attribute virt_driver_domain;
12561284
type virtd_t;
12571285
')
12581286

@@ -1402,6 +1430,43 @@ interface(`virt_dontaudit_read_chr_dev',`
14021430
dontaudit $1 virt_image_type:chr_file read_chr_file_perms;
14031431
')
14041432

1433+
########################################
1434+
## <summary>
1435+
## Make the specified type usable as a virt file type
1436+
## </summary>
1437+
## <param name="type">
1438+
## <summary>
1439+
## Type to be used as a virt file type
1440+
## </summary>
1441+
## </param>
1442+
#
1443+
interface(`virt_file_types',`
1444+
gen_require(`
1445+
attribute virt_file_type;
1446+
')
1447+
1448+
typeattribute $1 virt_file_type;
1449+
')
1450+
1451+
########################################
1452+
## <summary>
1453+
## Make the specified type usable as a svirt file type
1454+
## </summary>
1455+
## <param name="type">
1456+
## <summary>
1457+
## Type to be used as a svirt file type
1458+
## </summary>
1459+
## </param>
1460+
#
1461+
interface(`svirt_file_types',`
1462+
gen_require(`
1463+
attribute svirt_file_type;
1464+
')
1465+
1466+
typeattribute $1 svirt_file_type;
1467+
')
1468+
1469+
14051470
########################################
14061471
## <summary>
14071472
## Creates types and rules for a basic
@@ -1472,6 +1537,24 @@ template(`virt_sandbox_net_domain',`
14721537
typeattribute $1 sandbox_net_domain;
14731538
')
14741539

1540+
########################################
1541+
## <summary>
1542+
## Make the specified type usable as a virt system domain
1543+
## </summary>
1544+
## <param name="type">
1545+
## <summary>
1546+
## Type to be used as a virt system domain
1547+
## </summary>
1548+
## </param>
1549+
#
1550+
interface(`virt_system_domain_type',`
1551+
gen_require(`
1552+
attribute virt_system_domain;
1553+
')
1554+
1555+
typeattribute $1 virt_system_domain;
1556+
')
1557+
14751558
########################################
14761559
## <summary>
14771560
## Execute a qemu_exec_t in the callers domain
@@ -1802,6 +1885,26 @@ interface(`virt_dgram_send',`
18021885
dgram_send_pattern($1, virt_var_run_t, virt_var_run_t, virtd_t)
18031886
')
18041887

1888+
########################################
1889+
## <summary>
1890+
## Manage svirt home files,dirs and sockfiles.
1891+
## </summary>
1892+
## <param name="domain">
1893+
## <summary>
1894+
## Domain allowed access.
1895+
## </summary>
1896+
## </param>
1897+
#
1898+
interface(`virt_svirt_manage_home',`
1899+
gen_require(`
1900+
type svirt_home_t;
1901+
')
1902+
1903+
manage_files_pattern($1, svirt_home_t, svirt_home_t)
1904+
manage_dirs_pattern($1, svirt_home_t, svirt_home_t)
1905+
manage_sock_files_pattern($1, svirt_home_t, svirt_home_t)
1906+
')
1907+
18051908
########################################
18061909
## <summary>
18071910
## Manage svirt tmp files,dirs and sockfiles.

virt.te

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,8 +1762,12 @@ optional_policy(`
17621762
#
17631763
# virtproxyd local policy
17641764
#
1765+
allow virtproxyd_t self:tcp_socket create_stream_socket_perms;
17651766
allow virtproxyd_t self:udp_socket create_socket_perms;
17661767

1768+
corenet_tcp_bind_generic_node(virtproxyd_t)
1769+
corenet_tcp_bind_virt_port(virtproxyd_t)
1770+
17671771
userdom_read_all_users_state(virtproxyd_t)
17681772

17691773
#######################################

virt_supplementary.te

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,14 @@ gen_require(`
99
class passwd passwd;
1010
')
1111

12-
attribute virt_system_domain;
13-
attribute virt_domain;
14-
attribute virt_file_type;
15-
attribute svirt_file_type;
16-
17-
type virtd_exec_t, virt_file_type;
18-
19-
type svirt_home_t, svirt_file_type;
20-
21-
type virt_qmf_t, virt_system_domain;
22-
type virt_qmf_exec_t, virt_file_type;
12+
type virt_qmf_t;
13+
type virt_qmf_exec_t;
2314
init_daemon_domain(virt_qmf_t, virt_qmf_exec_t)
2415

25-
type virt_bridgehelper_t, virt_system_domain;
16+
type virt_bridgehelper_t;
2617
domain_type(virt_bridgehelper_t)
2718

28-
type virt_bridgehelper_exec_t, virt_file_type;
19+
type virt_bridgehelper_exec_t;
2920
domain_entry_file(virt_bridgehelper_t, virt_bridgehelper_exec_t)
3021
role system_r types virt_bridgehelper_t;
3122

@@ -51,25 +42,34 @@ gen_tunable(virt_rw_qemu_ga_data, false)
5142
gen_tunable(virt_qemu_ga_read_nonsecurity_files, false)
5243

5344
# policy for qemu_ga
54-
type virt_qemu_ga_t, virt_system_domain;
55-
type virt_qemu_ga_exec_t, virt_file_type;
45+
type virt_qemu_ga_t;
46+
type virt_qemu_ga_exec_t;
5647
init_daemon_domain(virt_qemu_ga_t, virt_qemu_ga_exec_t)
5748

58-
type virt_qemu_ga_var_run_t, virt_file_type;
49+
type virt_qemu_ga_var_run_t;
5950
files_pid_file(virt_qemu_ga_var_run_t)
6051

61-
type virt_qemu_ga_log_t, virt_file_type;
52+
type virt_qemu_ga_log_t;
6253
logging_log_file(virt_qemu_ga_log_t)
6354

64-
type virt_qemu_ga_tmp_t, virt_file_type;
55+
type virt_qemu_ga_tmp_t;
6556
files_tmp_file(virt_qemu_ga_tmp_t)
6657

67-
type virt_qemu_ga_data_t, virt_file_type;
58+
type virt_qemu_ga_data_t;
6859
files_type(virt_qemu_ga_data_t)
6960

70-
type virt_qemu_ga_unconfined_exec_t, virt_file_type;
61+
type virt_qemu_ga_unconfined_exec_t;
7162
application_executable_file(virt_qemu_ga_unconfined_exec_t)
7263

64+
optional_policy(`
65+
virt_file_types(virt_qemu_ga_exec_t)
66+
virt_file_types(virt_qemu_ga_var_run_t)
67+
virt_file_types(virt_qemu_ga_log_t)
68+
virt_file_types(virt_qemu_ga_tmp_t)
69+
virt_file_types(virt_qemu_ga_data_t)
70+
virt_file_types(virt_qemu_ga_unconfined_exec_t)
71+
')
72+
7373
########################################
7474
#
7575
# virt_qmf local policy
@@ -81,8 +81,6 @@ allow virt_qmf_t self:unix_stream_socket create_stream_socket_perms;
8181
allow virt_qmf_t self:tcp_socket create_stream_socket_perms;
8282
allow virt_qmf_t self:netlink_route_socket create_netlink_socket_perms;
8383

84-
can_exec(virt_qmf_t, virtd_exec_t)
85-
8684
kernel_read_system_state(virt_qmf_t)
8785
kernel_read_network_state(virt_qmf_t)
8886

@@ -103,7 +101,10 @@ optional_policy(`
103101
')
104102

105103
optional_policy(`
104+
virt_exec(virt_qmf_t)
105+
virt_file_types(virt_qmf_exec_t)
106106
virt_stream_connect(virt_qmf_t)
107+
virt_system_domain_type(virt_qmf_t)
107108
')
108109

109110
########################################
@@ -117,10 +118,6 @@ allow virt_bridgehelper_t self:tcp_socket create_stream_socket_perms;
117118
allow virt_bridgehelper_t self:tun_socket create_socket_perms;
118119
allow virt_bridgehelper_t self:unix_dgram_socket create_socket_perms;
119120

120-
allow virt_bridgehelper_t virt_domain:unix_stream_socket { read write };
121-
122-
manage_files_pattern(virt_bridgehelper_t, svirt_home_t, svirt_home_t)
123-
124121
kernel_read_network_state(virt_bridgehelper_t)
125122
kernel_read_system_state(virt_bridgehelper_t)
126123

@@ -132,6 +129,13 @@ corenet_rw_tun_tap_dev(virt_bridgehelper_t)
132129

133130
userdom_use_inherited_user_ptys(virt_bridgehelper_t)
134131

132+
optional_policy(`
133+
virt_file_types(virt_bridgehelper_exec_t)
134+
virt_rw_stream_sockets_virt_domain(virt_bridgehelper_t)
135+
virt_svirt_manage_home(virt_bridgehelper_t)
136+
virt_system_domain_type(virt_bridgehelper_t)
137+
')
138+
135139
#######################################
136140
#
137141
# virt_qemu_ga local policy
@@ -254,6 +258,10 @@ optional_policy(`
254258
udev_read_pid_files(virt_qemu_ga_t)
255259
')
256260

261+
optional_policy(`
262+
virt_system_domain_type(virt_qemu_ga_t)
263+
')
264+
257265
#######################################
258266
#
259267
# qemu-ga unconfined hook script local policy

0 commit comments

Comments
 (0)