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
|
## <summary>Run shells with substitute user and group.</summary>
#######################################
## <summary>
## Restricted su domain template.
## </summary>
## <desc>
## <p>
## This template creates a derived domain which is allowed
## to change the linux user id, to run shells as a different
## user.
## </p>
## </desc>
## <param name="userdomain_prefix">
## <summary>
## The prefix of the user domain (e.g., user
## is the prefix for user_t).
## </summary>
## </param>
## <param name="user_domain">
## <summary>
## The type of the user domain.
## </summary>
## </param>
## <param name="user_role">
## <summary>
## The role associated with the user domain.
## </summary>
## </param>
#
template(`su_restricted_domain_template', `
gen_require(`
type su_exec_t;
')
type $1_su_t;
domain_entry_file($1_su_t, su_exec_t)
domain_type($1_su_t)
domain_interactive_fd($1_su_t)
role $3 types $1_su_t;
allow $2 $1_su_t:process signal;
allow $1_su_t $2:process { sigkill signal };
allow $1_su_t self:capability { audit_control audit_write chown dac_override fowner net_bind_service setgid setuid sys_nice sys_resource };
dontaudit $1_su_t self:capability sys_tty_config;
allow $1_su_t self:key { search write };
allow $1_su_t self:process { setexec setrlimit setsched signal };
allow $1_su_t self:fifo_file rw_fifo_file_perms;
allow $1_su_t self:netlink_audit_socket { create_netlink_socket_perms nlmsg_relay };
allow $1_su_t self:unix_stream_socket create_stream_socket_perms;
# Transition from the user domain to this domain.
domtrans_pattern($2, su_exec_t, $1_su_t)
# By default, revert to the calling domain when a shell is executed.
corecmd_shell_domtrans($1_su_t,$2)
allow $2 $1_su_t:fd use;
allow $2 $1_su_t:fifo_file rw_inherited_fifo_file_perms;
allow $2 $1_su_t:process sigchld;
kernel_read_system_state($1_su_t)
kernel_read_kernel_sysctls($1_su_t)
kernel_search_key($1_su_t)
kernel_link_key($1_su_t)
# for SSP
dev_read_urand($1_su_t)
files_read_etc_files($1_su_t)
files_read_etc_runtime_files($1_su_t)
files_search_var_lib($1_su_t)
files_dontaudit_getattr_tmp_dirs($1_su_t)
# for the rootok check
selinux_compute_access_vector($1_su_t)
auth_domtrans_chk_passwd($1_su_t)
auth_dontaudit_read_shadow($1_su_t)
auth_use_nsswitch($1_su_t)
auth_create_faillog_files($1_su_t)
auth_rw_faillog($1_su_t)
auth_setattr_faillog_files($1_su_t)
auth_rw_lastlog($1_su_t)
auth_write_login_records($1_su_t)
domain_use_interactive_fds($1_su_t)
init_dontaudit_use_fds($1_su_t)
init_dontaudit_use_script_ptys($1_su_t)
# Write to utmp.
init_rw_utmp($1_su_t)
init_search_script_keys($1_su_t)
logging_send_syslog_msg($1_su_t)
miscfiles_read_localization($1_su_t)
ifdef(`distro_redhat',`
# RHEL5 and possibly newer releases incl. Fedora
auth_domtrans_upd_passwd($1_su_t)
optional_policy(`
locallogin_search_keys($1_su_t)
')
')
optional_policy(`
cron_read_pipes($1_su_t)
')
optional_policy(`
kerberos_use($1_su_t)
')
optional_policy(`
# used when the password has expired
usermanage_read_crack_db($1_su_t)
')
ifdef(`distro_gentoo',`
# Fix bug 554080 - Allow su to query SELinux subsystem (netlink_selinux_socket)
allow $1_su_t self:netlink_selinux_socket { create bind read };
selinux_get_fs_mount($1_su_t)
')
')
#######################################
## <summary>
## The role template for the su module.
## </summary>
## <param name="role_prefix">
## <summary>
## The prefix of the user role (e.g., user
## is the prefix for user_r).
## </summary>
## </param>
## <param name="user_domain">
## <summary>
## User domain for the role.
## </summary>
## </param>
## <param name="user_exec_domain">
## <summary>
## User exec domain for execute and transition access.
## </summary>
## </param>
## <param name="role">
## <summary>
## Role allowed access
## </summary>
## </param>
#
template(`su_role_template',`
gen_require(`
type su_exec_t;
')
type $1_su_t;
userdom_user_application_domain($1_su_t, su_exec_t)
domain_interactive_fd($1_su_t)
role $4 types $1_su_t;
allow $1_su_t $2:process { sigkill signal };
allow $1_su_t self:capability { audit_control audit_write chown dac_override fowner net_bind_service setgid setuid sys_nice sys_resource };
dontaudit $1_su_t self:capability { net_admin sys_tty_config };
allow $1_su_t self:process { setexec setrlimit setsched signal };
allow $1_su_t self:fifo_file rw_fifo_file_perms;
allow $1_su_t self:netlink_audit_socket { create_netlink_socket_perms nlmsg_relay };
allow $1_su_t self:key { search write };
# By default, revert to the calling domain when a shell is executed.
corecmd_shell_domtrans($1_su_t, $2)
kernel_read_system_state($1_su_t)
kernel_read_kernel_sysctls($1_su_t)
kernel_search_key($1_su_t)
kernel_link_key($1_su_t)
kernel_dontaudit_getattr_proc($1_su_t)
# for SSP
dev_read_urand($1_su_t)
fs_search_auto_mountpoints($1_su_t)
# needed for pam_rootok
selinux_compute_access_vector($1_su_t)
selinux_use_status_page($1_su_t)
auth_domtrans_chk_passwd($1_su_t)
auth_dontaudit_read_shadow($1_su_t)
auth_use_nsswitch($1_su_t)
auth_create_faillog_files($1_su_t)
auth_rw_faillog($1_su_t)
auth_setattr_faillog_files($1_su_t)
auth_rw_lastlog($1_su_t)
auth_write_login_records($1_su_t)
corecmd_search_bin($1_su_t)
domain_use_interactive_fds($1_su_t)
files_read_etc_files($1_su_t)
files_read_etc_runtime_files($1_su_t)
files_search_var_lib($1_su_t)
files_dontaudit_getattr_tmp_dirs($1_su_t)
init_dontaudit_use_fds($1_su_t)
init_dontaudit_read_state($1_su_t)
# Write to utmp.
init_rw_utmp($1_su_t)
mls_file_write_all_levels($1_su_t)
logging_send_syslog_msg($1_su_t)
miscfiles_read_localization($1_su_t)
# pam_unix is linked against libselinux
seutil_libselinux_linked($1_su_t)
userdom_use_user_terminals($1_su_t)
userdom_search_user_home_dirs($1_su_t)
ifdef(`distro_redhat',`
# RHEL5 and possibly newer releases incl. Fedora
auth_domtrans_upd_passwd($1_su_t)
optional_policy(`
locallogin_search_keys($1_su_t)
')
')
optional_policy(`
auth_use_pam_systemd($1_su_t)
')
tunable_policy(`su_allow_user_exec_domains',`
allow $3 $1_su_t:process signal;
allow $1_su_t $3:key search;
# Transition from the user domain to this domain.
domtrans_pattern($3, su_exec_t, $1_su_t)
ps_process_pattern($3, $1_su_t)
allow $3 $1_su_t:fd use;
allow $3 $1_su_t:fifo_file rw_inherited_fifo_file_perms;
allow $3 $1_su_t:process sigchld;
',`
allow $2 $1_su_t:process signal;
allow $1_su_t $2:key search;
# Transition from the user domain to this domain.
domtrans_pattern($2, su_exec_t, $1_su_t)
ps_process_pattern($2, $1_su_t)
allow $2 $1_su_t:fd use;
allow $2 $1_su_t:fifo_file rw_inherited_fifo_file_perms;
allow $2 $1_su_t:process sigchld;
')
tunable_policy(`allow_polyinstantiation',`
fs_mount_xattr_fs($1_su_t)
fs_unmount_xattr_fs($1_su_t)
')
tunable_policy(`use_nfs_home_dirs',`
fs_search_nfs($1_su_t)
')
tunable_policy(`use_samba_home_dirs',`
fs_search_cifs($1_su_t)
')
optional_policy(`
cron_read_pipes($1_su_t)
')
optional_policy(`
kerberos_use($1_su_t)
')
optional_policy(`
# used when the password has expired
usermanage_read_crack_db($1_su_t)
')
# Modify .Xauthority file (via xauth program).
optional_policy(`
xserver_user_home_dir_filetrans_user_xauth($1_su_t)
xserver_domtrans_xauth($1_su_t)
')
ifdef(`distro_gentoo',`
selinux_get_fs_mount($1_su_t)
')
')
#######################################
## <summary>
## Execute su in the caller domain.
## </summary>
## <param name="domain">
## <summary>
## Domain allowed access.
## </summary>
## </param>
#
interface(`su_exec',`
gen_require(`
type su_exec_t;
')
corecmd_search_bin($1)
can_exec($1, su_exec_t)
')
|