blob: 955c27b00ff5c9ba6f25d6f8c2df3b5fd37d16a0 [file] [log] [blame]
Stephen Smalley2dd4e512012-01-04 12:33:27 -05001#################################################
2# MLS policy constraints
3#
4
5#
6# Process constraints
7#
8
9# Process transition: Require equivalence unless the subject is trusted.
10mlsconstrain process { transition dyntransition }
11 ((h1 eq h2 and l1 eq l2) or t1 == mlstrustedsubject);
12
13# Process read operations: No read up unless trusted.
14mlsconstrain process { getsched getsession getpgid getcap getattr ptrace share }
15 (l1 dom l2 or t1 == mlstrustedsubject);
16
Stephen Smalley025b7df2015-03-13 17:07:39 -040017# Process write operations: Require equivalence unless trusted.
Stephen Smalley2dd4e512012-01-04 12:33:27 -050018mlsconstrain process { sigkill sigstop signal setsched setpgid setcap setrlimit ptrace share }
Stephen Smalley025b7df2015-03-13 17:07:39 -040019 (l1 eq l2 or t1 == mlstrustedsubject);
Stephen Smalley2dd4e512012-01-04 12:33:27 -050020
21#
22# Socket constraints
23#
24
Stephen Smalleye8848722012-11-13 13:00:05 -050025# Create/relabel operations: Subject must be equivalent to object unless
26# the subject is trusted. Sockets inherit the range of their creator.
27mlsconstrain socket_class_set { create relabelfrom relabelto }
28 ((h1 eq h2 and l1 eq l2) or t1 == mlstrustedsubject);
Stephen Smalley2dd4e512012-01-04 12:33:27 -050029
Stephen Smalley025b7df2015-03-13 17:07:39 -040030# Datagram send: Sender must be equivalent to the receiver unless one of them
31# is trusted.
Stephen Smalley2dd4e512012-01-04 12:33:27 -050032mlsconstrain unix_dgram_socket { sendto }
Stephen Smalley025b7df2015-03-13 17:07:39 -040033 (l1 eq l2 or t1 == mlstrustedsubject or t2 == mlstrustedsubject);
Stephen Smalley2dd4e512012-01-04 12:33:27 -050034
35# Stream connect: Client must be equivalent to server unless one of them
36# is trusted.
37mlsconstrain unix_stream_socket { connectto }
38 (l1 eq l2 or t1 == mlstrustedsubject or t2 == mlstrustedsubject);
39
40#
41# Directory/file constraints
42#
43
44# Create/relabel operations: Subject must be equivalent to object unless
45# the subject is trusted. Also, files should always be single-level.
46# Do NOT exempt mlstrustedobject types from this constraint.
47mlsconstrain dir_file_class_set { create relabelfrom relabelto }
48 (l2 eq h2 and (l1 eq l2 or t1 == mlstrustedsubject));
49
dcashman60cfe792015-03-04 09:50:34 -080050#
Lokesh Gidra06edcd82021-03-11 11:32:47 -080051# Userfaultfd constraints
52#
53# To enforce that anonymous inodes are self contained in the application's process.
54mlsconstrain anon_inode { ioctl read write create getattr setattr lock relabelfrom relabelto append map unlink link rename execute open execmod }
55 (l1 eq l2);
56
57#
dcashman60cfe792015-03-04 09:50:34 -080058# Constraints for app data files only.
59#
60
Alan Stokesc5773a92020-11-09 16:53:01 +000061# Only constrain open, not read/write, so already open fds can be used.
dcashman60cfe792015-03-04 09:50:34 -080062# Also constrain other forms of manipulation, e.g. chmod/chown, unlink, rename, etc.
Jeff Vander Stoep3aa7ca52018-04-03 11:22:38 -070063# Subject must dominate object unless the subject is trusted.
Alan Stokes9443b2e2020-07-16 10:42:58 +010064mlsconstrain dir { open search getattr setattr rename add_name remove_name reparent rmdir }
Alan Stokesc5773a92020-11-09 16:53:01 +000065 (t2 != app_data_file_type or l1 dom l2 or t1 == mlstrustedsubject);
Jeff Vander Stoepbed2e162019-01-24 09:48:57 -080066mlsconstrain { file sock_file } { open setattr unlink link rename }
Alan Stokesc5773a92020-11-09 16:53:01 +000067 ( (t2 != app_data_file_type and t2 != appdomain_tmpfs) or l1 dom l2 or t1 == mlstrustedsubject);
68
69# For symlinks in app data files, require equivalence in order to manipulate or follow (read).
Jeff Vander Stoepbed2e162019-01-24 09:48:57 -080070mlsconstrain { lnk_file } { open setattr unlink link rename read }
Alan Stokesc5773a92020-11-09 16:53:01 +000071 ( (t2 != app_data_file_type or t2 == privapp_data_file) or l1 eq l2 or t1 == mlstrustedsubject);
72# But for priv_app_data_file, continue to use dominance for symlinks because dynamite relies on this.
Jeff Vander Stoepbed2e162019-01-24 09:48:57 -080073# TODO: Migrate to equivalence when it's no longer needed.
74mlsconstrain { lnk_file } { open setattr unlink link rename read }
Jeff Vander Stoep9f5d0d92019-01-29 14:43:45 -080075 ( (t2 != privapp_data_file and t2 != appdomain_tmpfs) or l1 dom l2 or t1 == mlstrustedsubject);
dcashman60cfe792015-03-04 09:50:34 -080076
77#
78# Constraints for file types other than app data files.
79#
80
Stephen Smalley2dd4e512012-01-04 12:33:27 -050081# Read operations: Subject must dominate object unless the subject
82# or the object is trusted.
83mlsconstrain dir { read getattr search }
Alan Stokes8bf8a262020-11-16 18:10:33 +000084 (t2 == app_data_file_type or l1 dom l2 or t1 == mlstrustedsubject or t2 == mlstrustedobject
Alan Stokes7aa40412020-12-04 14:07:52 +000085 or (t1 == mlsvendorcompat and (t2 == system_data_file or t2 == user_profile_root_file) ) );
Stephen Smalley2dd4e512012-01-04 12:33:27 -050086
dcashman60cfe792015-03-04 09:50:34 -080087mlsconstrain { file lnk_file sock_file chr_file blk_file } { read getattr execute }
Alan Stokesc5773a92020-11-09 16:53:01 +000088 (t2 == app_data_file_type or t2 == appdomain_tmpfs or l1 dom l2 or t1 == mlstrustedsubject or t2 == mlstrustedobject);
Stephen Smalley2dd4e512012-01-04 12:33:27 -050089
Stephen Smalley025b7df2015-03-13 17:07:39 -040090# Write operations: Subject must be equivalent to the object unless the
Stephen Smalley2dd4e512012-01-04 12:33:27 -050091# subject or the object is trusted.
92mlsconstrain dir { write setattr rename add_name remove_name reparent rmdir }
Alan Stokesc5773a92020-11-09 16:53:01 +000093 (t2 == app_data_file_type or l1 eq l2 or t1 == mlstrustedsubject or t2 == mlstrustedobject);
Stephen Smalley2dd4e512012-01-04 12:33:27 -050094
95mlsconstrain { file lnk_file sock_file chr_file blk_file } { write setattr append unlink link rename }
Alan Stokesc5773a92020-11-09 16:53:01 +000096 (t2 == app_data_file_type or t2 == appdomain_tmpfs or l1 eq l2 or t1 == mlstrustedsubject or t2 == mlstrustedobject);
Stephen Smalley2dd4e512012-01-04 12:33:27 -050097
98# Special case for FIFOs.
99# These can be unnamed pipes, in which case they will be labeled with the
100# creating process' label. Thus we also have an exemption when the "object"
Stephen Smalley7d1b6c82015-02-20 12:30:31 -0500101# is a domain type, so that processes can communicate via unnamed pipes
102# passed by binder or local socket IPC.
Stephen Smalley2dd4e512012-01-04 12:33:27 -0500103mlsconstrain fifo_file { read getattr }
Stephen Smalley7d1b6c82015-02-20 12:30:31 -0500104 (l1 dom l2 or t1 == mlstrustedsubject or t2 == mlstrustedobject or t2 == domain);
Stephen Smalley2dd4e512012-01-04 12:33:27 -0500105
106mlsconstrain fifo_file { write setattr append unlink link rename }
Stephen Smalley025b7df2015-03-13 17:07:39 -0400107 (l1 eq l2 or t1 == mlstrustedsubject or t2 == mlstrustedobject or t2 == domain);
Stephen Smalley2dd4e512012-01-04 12:33:27 -0500108
109#
110# Binder IPC constraints
111#
112# Presently commented out, as apps are expected to call one another.
113# This would only make sense if apps were assigned categories
114# based on allowable communications rather than per-app categories.
115#mlsconstrain binder call
116# (l1 eq l2 or t1 == mlstrustedsubject or t2 == mlstrustedsubject);