Skip to content

Commit 0fa96eb

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

File tree

2 files changed

+131
-26
lines changed

2 files changed

+131
-26
lines changed

virt.if

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ interface(`virt_image',`
202202
#
203203
interface(`virt_getattr_exec',`
204204
gen_require(`
205+
attribute virt_driver_executable;
205206
type virtd_exec_t;
206207
')
207208

@@ -239,6 +240,7 @@ interface(`virt_domtrans',`
239240
#
240241
interface(`virt_exec',`
241242
gen_require(`
243+
attribute virt_driver_executable;
242244
type virtd_exec_t;
243245
')
244246

@@ -268,6 +270,26 @@ interface(`virt_stream_connect',`
268270
stream_connect_pattern($1, virt_driver_var_run, virt_driver_var_run, virt_driver_domain)
269271
')
270272

273+
########################################
274+
## <summary>
275+
## Read and write to virt_domain unix
276+
## stream sockets.
277+
## </summary>
278+
## <param name="domain">
279+
## <summary>
280+
## Domain allowed access.
281+
## </summary>
282+
## </param>
283+
#
284+
interface(`virt_rw_stream_sockets_virt_domain',`
285+
gen_require(`
286+
attribute virt_domain;
287+
')
288+
289+
allow $1 virt_domain:unix_stream_socket { read write };
290+
')
291+
292+
271293
#######################################
272294
## <summary>
273295
## Connect to svirt process over a unix domain stream socket.
@@ -1402,6 +1424,43 @@ interface(`virt_dontaudit_read_chr_dev',`
14021424
dontaudit $1 virt_image_type:chr_file read_chr_file_perms;
14031425
')
14041426

1427+
########################################
1428+
## <summary>
1429+
## Make the specified type usable as a virt file type
1430+
## </summary>
1431+
## <param name="type">
1432+
## <summary>
1433+
## Type to be used as a virt file type
1434+
## </summary>
1435+
## </param>
1436+
#
1437+
interface(`virt_file_types',`
1438+
gen_require(`
1439+
attribute virt_file_type;
1440+
')
1441+
1442+
typeattribute $1 virt_file_type;
1443+
')
1444+
1445+
########################################
1446+
## <summary>
1447+
## Make the specified type usable as a svirt file type
1448+
## </summary>
1449+
## <param name="type">
1450+
## <summary>
1451+
## Type to be used as a svirt file type
1452+
## </summary>
1453+
## </param>
1454+
#
1455+
interface(`svirt_file_types',`
1456+
gen_require(`
1457+
attribute svirt_file_type;
1458+
')
1459+
1460+
typeattribute $1 svirt_file_type;
1461+
')
1462+
1463+
14051464
########################################
14061465
## <summary>
14071466
## Creates types and rules for a basic
@@ -1472,6 +1531,24 @@ template(`virt_sandbox_net_domain',`
14721531
typeattribute $1 sandbox_net_domain;
14731532
')
14741533

1534+
########################################
1535+
## <summary>
1536+
## Make the specified type usable as a virt system domain
1537+
## </summary>
1538+
## <param name="type">
1539+
## <summary>
1540+
## Type to be used as a virt system domain
1541+
## </summary>
1542+
## </param>
1543+
#
1544+
interface(`virt_system_domain_type',`
1545+
gen_require(`
1546+
attribute virt_system_domain;
1547+
')
1548+
1549+
typeattribute $1 virt_system_domain;
1550+
')
1551+
14751552
########################################
14761553
## <summary>
14771554
## Execute a qemu_exec_t in the callers domain
@@ -1802,6 +1879,26 @@ interface(`virt_dgram_send',`
18021879
dgram_send_pattern($1, virt_var_run_t, virt_var_run_t, virtd_t)
18031880
')
18041881

1882+
########################################
1883+
## <summary>
1884+
## Manage svirt home files,dirs and sockfiles.
1885+
## </summary>
1886+
## <param name="domain">
1887+
## <summary>
1888+
## Domain allowed access.
1889+
## </summary>
1890+
## </param>
1891+
#
1892+
interface(`virt_svirt_manage_home',`
1893+
gen_require(`
1894+
type svirt_home_t;
1895+
')
1896+
1897+
manage_files_pattern($1, svirt_home_t, svirt_home_t)
1898+
manage_dirs_pattern($1, svirt_home_t, svirt_home_t)
1899+
manage_sock_files_pattern($1, svirt_home_t, svirt_home_t)
1900+
')
1901+
18051902
########################################
18061903
## <summary>
18071904
## Manage svirt tmp files,dirs and sockfiles.

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)