18c2ecf20Sopenharmony_ci=====
28c2ecf20Sopenharmony_ciSmack
38c2ecf20Sopenharmony_ci=====
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci    "Good for you, you've decided to clean the elevator!"
78c2ecf20Sopenharmony_ci    - The Elevator, from Dark Star
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciSmack is the Simplified Mandatory Access Control Kernel.
108c2ecf20Sopenharmony_ciSmack is a kernel based implementation of mandatory access
118c2ecf20Sopenharmony_cicontrol that includes simplicity in its primary design goals.
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciSmack is not the only Mandatory Access Control scheme
148c2ecf20Sopenharmony_ciavailable for Linux. Those new to Mandatory Access Control
158c2ecf20Sopenharmony_ciare encouraged to compare Smack with the other mechanisms
168c2ecf20Sopenharmony_ciavailable to determine which is best suited to the problem
178c2ecf20Sopenharmony_ciat hand.
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciSmack consists of three major components:
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci    - The kernel
228c2ecf20Sopenharmony_ci    - Basic utilities, which are helpful but not required
238c2ecf20Sopenharmony_ci    - Configuration data
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciThe kernel component of Smack is implemented as a Linux
268c2ecf20Sopenharmony_ciSecurity Modules (LSM) module. It requires netlabel and
278c2ecf20Sopenharmony_ciworks best with file systems that support extended attributes,
288c2ecf20Sopenharmony_cialthough xattr support is not strictly required.
298c2ecf20Sopenharmony_ciIt is safe to run a Smack kernel under a "vanilla" distribution.
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciSmack kernels use the CIPSO IP option. Some network
328c2ecf20Sopenharmony_ciconfigurations are intolerant of IP options and can impede
338c2ecf20Sopenharmony_ciaccess to systems that use them as Smack does.
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciSmack is used in the Tizen operating system. Please
368c2ecf20Sopenharmony_cigo to http://wiki.tizen.org for information about how
378c2ecf20Sopenharmony_ciSmack is used in Tizen.
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciThe current git repository for Smack user space is:
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	git://github.com/smack-team/smack.git
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciThis should make and install on most modern distributions.
448c2ecf20Sopenharmony_ciThere are five commands included in smackutil:
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cichsmack:
478c2ecf20Sopenharmony_ci	display or set Smack extended attribute values
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cismackctl:
508c2ecf20Sopenharmony_ci	load the Smack access rules
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cismackaccess:
538c2ecf20Sopenharmony_ci	report if a process with one label has access
548c2ecf20Sopenharmony_ci	to an object with another
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciThese two commands are obsolete with the introduction of
578c2ecf20Sopenharmony_cithe smackfs/load2 and smackfs/cipso2 interfaces.
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cismackload:
608c2ecf20Sopenharmony_ci	properly formats data for writing to smackfs/load
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cismackcipso:
638c2ecf20Sopenharmony_ci	properly formats data for writing to smackfs/cipso
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciIn keeping with the intent of Smack, configuration data is
668c2ecf20Sopenharmony_ciminimal and not strictly required. The most important
678c2ecf20Sopenharmony_ciconfiguration step is mounting the smackfs pseudo filesystem.
688c2ecf20Sopenharmony_ciIf smackutil is installed the startup script will take care
698c2ecf20Sopenharmony_ciof this, but it can be manually as well.
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ciAdd this line to ``/etc/fstab``::
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci    smackfs /sys/fs/smackfs smackfs defaults 0 0
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciThe ``/sys/fs/smackfs`` directory is created by the kernel.
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ciSmack uses extended attributes (xattrs) to store labels on filesystem
788c2ecf20Sopenharmony_ciobjects. The attributes are stored in the extended attribute security
798c2ecf20Sopenharmony_ciname space. A process must have ``CAP_MAC_ADMIN`` to change any of these
808c2ecf20Sopenharmony_ciattributes.
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ciThe extended attributes that Smack uses are:
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ciSMACK64
858c2ecf20Sopenharmony_ci	Used to make access control decisions. In almost all cases
868c2ecf20Sopenharmony_ci	the label given to a new filesystem object will be the label
878c2ecf20Sopenharmony_ci	of the process that created it.
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ciSMACK64EXEC
908c2ecf20Sopenharmony_ci	The Smack label of a process that execs a program file with
918c2ecf20Sopenharmony_ci	this attribute set will run with this attribute's value.
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ciSMACK64MMAP
948c2ecf20Sopenharmony_ci	Don't allow the file to be mmapped by a process whose Smack
958c2ecf20Sopenharmony_ci	label does not allow all of the access permitted to a process
968c2ecf20Sopenharmony_ci	with the label contained in this attribute. This is a very
978c2ecf20Sopenharmony_ci	specific use case for shared libraries.
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ciSMACK64TRANSMUTE
1008c2ecf20Sopenharmony_ci	Can only have the value "TRUE". If this attribute is present
1018c2ecf20Sopenharmony_ci	on a directory when an object is created in the directory and
1028c2ecf20Sopenharmony_ci	the Smack rule (more below) that permitted the write access
1038c2ecf20Sopenharmony_ci	to the directory includes the transmute ("t") mode the object
1048c2ecf20Sopenharmony_ci	gets the label of the directory instead of the label of the
1058c2ecf20Sopenharmony_ci	creating process. If the object being created is a directory
1068c2ecf20Sopenharmony_ci	the SMACK64TRANSMUTE attribute is set as well.
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ciSMACK64IPIN
1098c2ecf20Sopenharmony_ci	This attribute is only available on file descriptors for sockets.
1108c2ecf20Sopenharmony_ci	Use the Smack label in this attribute for access control
1118c2ecf20Sopenharmony_ci	decisions on packets being delivered to this socket.
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ciSMACK64IPOUT
1148c2ecf20Sopenharmony_ci	This attribute is only available on file descriptors for sockets.
1158c2ecf20Sopenharmony_ci	Use the Smack label in this attribute for access control
1168c2ecf20Sopenharmony_ci	decisions on packets coming from this socket.
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ciThere are multiple ways to set a Smack label on a file::
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci    # attr -S -s SMACK64 -V "value" path
1218c2ecf20Sopenharmony_ci    # chsmack -a value path
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ciA process can see the Smack label it is running with by
1248c2ecf20Sopenharmony_cireading ``/proc/self/attr/current``. A process with ``CAP_MAC_ADMIN``
1258c2ecf20Sopenharmony_cican set the process Smack by writing there.
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ciMost Smack configuration is accomplished by writing to files
1288c2ecf20Sopenharmony_ciin the smackfs filesystem. This pseudo-filesystem is mounted
1298c2ecf20Sopenharmony_cion ``/sys/fs/smackfs``.
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ciaccess
1328c2ecf20Sopenharmony_ci	Provided for backward compatibility. The access2 interface
1338c2ecf20Sopenharmony_ci	is preferred and should be used instead.
1348c2ecf20Sopenharmony_ci	This interface reports whether a subject with the specified
1358c2ecf20Sopenharmony_ci	Smack label has a particular access to an object with a
1368c2ecf20Sopenharmony_ci	specified Smack label. Write a fixed format access rule to
1378c2ecf20Sopenharmony_ci	this file. The next read will indicate whether the access
1388c2ecf20Sopenharmony_ci	would be permitted. The text will be either "1" indicating
1398c2ecf20Sopenharmony_ci	access, or "0" indicating denial.
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ciaccess2
1428c2ecf20Sopenharmony_ci	This interface reports whether a subject with the specified
1438c2ecf20Sopenharmony_ci	Smack label has a particular access to an object with a
1448c2ecf20Sopenharmony_ci	specified Smack label. Write a long format access rule to
1458c2ecf20Sopenharmony_ci	this file. The next read will indicate whether the access
1468c2ecf20Sopenharmony_ci	would be permitted. The text will be either "1" indicating
1478c2ecf20Sopenharmony_ci	access, or "0" indicating denial.
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ciambient
1508c2ecf20Sopenharmony_ci	This contains the Smack label applied to unlabeled network
1518c2ecf20Sopenharmony_ci	packets.
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_cichange-rule
1548c2ecf20Sopenharmony_ci	This interface allows modification of existing access control rules.
1558c2ecf20Sopenharmony_ci	The format accepted on write is::
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci		"%s %s %s %s"
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	where the first string is the subject label, the second the
1608c2ecf20Sopenharmony_ci	object label, the third the access to allow and the fourth the
1618c2ecf20Sopenharmony_ci	access to deny. The access strings may contain only the characters
1628c2ecf20Sopenharmony_ci	"rwxat-". If a rule for a given subject and object exists it will be
1638c2ecf20Sopenharmony_ci	modified by enabling the permissions in the third string and disabling
1648c2ecf20Sopenharmony_ci	those in the fourth string. If there is no such rule it will be
1658c2ecf20Sopenharmony_ci	created using the access specified in the third and the fourth strings.
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cicipso
1688c2ecf20Sopenharmony_ci	Provided for backward compatibility. The cipso2 interface
1698c2ecf20Sopenharmony_ci	is preferred and should be used instead.
1708c2ecf20Sopenharmony_ci	This interface allows a specific CIPSO header to be assigned
1718c2ecf20Sopenharmony_ci	to a Smack label. The format accepted on write is::
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci		"%24s%4d%4d"["%4d"]...
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	The first string is a fixed Smack label. The first number is
1768c2ecf20Sopenharmony_ci	the level to use. The second number is the number of categories.
1778c2ecf20Sopenharmony_ci	The following numbers are the categories::
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci		"level-3-cats-5-19          3   2   5  19"
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_cicipso2
1828c2ecf20Sopenharmony_ci	This interface allows a specific CIPSO header to be assigned
1838c2ecf20Sopenharmony_ci	to a Smack label. The format accepted on write is::
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci		"%s%4d%4d"["%4d"]...
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	The first string is a long Smack label. The first number is
1888c2ecf20Sopenharmony_ci	the level to use. The second number is the number of categories.
1898c2ecf20Sopenharmony_ci	The following numbers are the categories::
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci		"level-3-cats-5-19   3   2   5  19"
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_cidirect
1948c2ecf20Sopenharmony_ci	This contains the CIPSO level used for Smack direct label
1958c2ecf20Sopenharmony_ci	representation in network packets.
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_cidoi
1988c2ecf20Sopenharmony_ci	This contains the CIPSO domain of interpretation used in
1998c2ecf20Sopenharmony_ci	network packets.
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ciipv6host
2028c2ecf20Sopenharmony_ci	This interface allows specific IPv6 internet addresses to be
2038c2ecf20Sopenharmony_ci	treated as single label hosts. Packets are sent to single
2048c2ecf20Sopenharmony_ci	label hosts only from processes that have Smack write access
2058c2ecf20Sopenharmony_ci	to the host label. All packets received from single label hosts
2068c2ecf20Sopenharmony_ci	are given the specified label. The format accepted on write is::
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci		"%h:%h:%h:%h:%h:%h:%h:%h label" or
2098c2ecf20Sopenharmony_ci		"%h:%h:%h:%h:%h:%h:%h:%h/%d label".
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	The "::" address shortcut is not supported.
2128c2ecf20Sopenharmony_ci	If label is "-DELETE" a matched entry will be deleted.
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ciload
2158c2ecf20Sopenharmony_ci	Provided for backward compatibility. The load2 interface
2168c2ecf20Sopenharmony_ci	is preferred and should be used instead.
2178c2ecf20Sopenharmony_ci	This interface allows access control rules in addition to
2188c2ecf20Sopenharmony_ci	the system defined rules to be specified. The format accepted
2198c2ecf20Sopenharmony_ci	on write is::
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci		"%24s%24s%5s"
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	where the first string is the subject label, the second the
2248c2ecf20Sopenharmony_ci	object label, and the third the requested access. The access
2258c2ecf20Sopenharmony_ci	string may contain only the characters "rwxat-", and specifies
2268c2ecf20Sopenharmony_ci	which sort of access is allowed. The "-" is a placeholder for
2278c2ecf20Sopenharmony_ci	permissions that are not allowed. The string "r-x--" would
2288c2ecf20Sopenharmony_ci	specify read and execute access. Labels are limited to 23
2298c2ecf20Sopenharmony_ci	characters in length.
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ciload2
2328c2ecf20Sopenharmony_ci	This interface allows access control rules in addition to
2338c2ecf20Sopenharmony_ci	the system defined rules to be specified. The format accepted
2348c2ecf20Sopenharmony_ci	on write is::
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci		"%s %s %s"
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	where the first string is the subject label, the second the
2398c2ecf20Sopenharmony_ci	object label, and the third the requested access. The access
2408c2ecf20Sopenharmony_ci	string may contain only the characters "rwxat-", and specifies
2418c2ecf20Sopenharmony_ci	which sort of access is allowed. The "-" is a placeholder for
2428c2ecf20Sopenharmony_ci	permissions that are not allowed. The string "r-x--" would
2438c2ecf20Sopenharmony_ci	specify read and execute access.
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ciload-self
2468c2ecf20Sopenharmony_ci	Provided for backward compatibility. The load-self2 interface
2478c2ecf20Sopenharmony_ci	is preferred and should be used instead.
2488c2ecf20Sopenharmony_ci	This interface allows process specific access rules to be
2498c2ecf20Sopenharmony_ci	defined. These rules are only consulted if access would
2508c2ecf20Sopenharmony_ci	otherwise be permitted, and are intended to provide additional
2518c2ecf20Sopenharmony_ci	restrictions on the process. The format is the same as for
2528c2ecf20Sopenharmony_ci	the load interface.
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ciload-self2
2558c2ecf20Sopenharmony_ci	This interface allows process specific access rules to be
2568c2ecf20Sopenharmony_ci	defined. These rules are only consulted if access would
2578c2ecf20Sopenharmony_ci	otherwise be permitted, and are intended to provide additional
2588c2ecf20Sopenharmony_ci	restrictions on the process. The format is the same as for
2598c2ecf20Sopenharmony_ci	the load2 interface.
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_cilogging
2628c2ecf20Sopenharmony_ci	This contains the Smack logging state.
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_cimapped
2658c2ecf20Sopenharmony_ci	This contains the CIPSO level used for Smack mapped label
2668c2ecf20Sopenharmony_ci	representation in network packets.
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_cinetlabel
2698c2ecf20Sopenharmony_ci	This interface allows specific internet addresses to be
2708c2ecf20Sopenharmony_ci	treated as single label hosts. Packets are sent to single
2718c2ecf20Sopenharmony_ci	label hosts without CIPSO headers, but only from processes
2728c2ecf20Sopenharmony_ci	that have Smack write access to the host label. All packets
2738c2ecf20Sopenharmony_ci	received from single label hosts are given the specified
2748c2ecf20Sopenharmony_ci	label. The format accepted on write is::
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci		"%d.%d.%d.%d label" or "%d.%d.%d.%d/%d label".
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	If the label specified is "-CIPSO" the address is treated
2798c2ecf20Sopenharmony_ci	as a host that supports CIPSO headers.
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_cionlycap
2828c2ecf20Sopenharmony_ci	This contains labels processes must have for CAP_MAC_ADMIN
2838c2ecf20Sopenharmony_ci	and ``CAP_MAC_OVERRIDE`` to be effective. If this file is empty
2848c2ecf20Sopenharmony_ci	these capabilities are effective at for processes with any
2858c2ecf20Sopenharmony_ci	label. The values are set by writing the desired labels, separated
2868c2ecf20Sopenharmony_ci	by spaces, to the file or cleared by writing "-" to the file.
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ciptrace
2898c2ecf20Sopenharmony_ci	This is used to define the current ptrace policy
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci	0 - default:
2928c2ecf20Sopenharmony_ci	    this is the policy that relies on Smack access rules.
2938c2ecf20Sopenharmony_ci	    For the ``PTRACE_READ`` a subject needs to have a read access on
2948c2ecf20Sopenharmony_ci	    object. For the ``PTRACE_ATTACH`` a read-write access is required.
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	1 - exact:
2978c2ecf20Sopenharmony_ci	    this is the policy that limits ``PTRACE_ATTACH``. Attach is
2988c2ecf20Sopenharmony_ci	    only allowed when subject's and object's labels are equal.
2998c2ecf20Sopenharmony_ci	    ``PTRACE_READ`` is not affected. Can be overridden with ``CAP_SYS_PTRACE``.
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	2 - draconian:
3028c2ecf20Sopenharmony_ci	    this policy behaves like the 'exact' above with an
3038c2ecf20Sopenharmony_ci	    exception that it can't be overridden with ``CAP_SYS_PTRACE``.
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_cirevoke-subject
3068c2ecf20Sopenharmony_ci	Writing a Smack label here sets the access to '-' for all access
3078c2ecf20Sopenharmony_ci	rules with that subject label.
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ciunconfined
3108c2ecf20Sopenharmony_ci	If the kernel is configured with ``CONFIG_SECURITY_SMACK_BRINGUP``
3118c2ecf20Sopenharmony_ci	a process with ``CAP_MAC_ADMIN`` can write a label into this interface.
3128c2ecf20Sopenharmony_ci	Thereafter, accesses that involve that label will be logged and
3138c2ecf20Sopenharmony_ci	the access permitted if it wouldn't be otherwise. Note that this
3148c2ecf20Sopenharmony_ci	is dangerous and can ruin the proper labeling of your system.
3158c2ecf20Sopenharmony_ci	It should never be used in production.
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_cirelabel-self
3188c2ecf20Sopenharmony_ci	This interface contains a list of labels to which the process can
3198c2ecf20Sopenharmony_ci	transition to, by writing to ``/proc/self/attr/current``.
3208c2ecf20Sopenharmony_ci	Normally a process can change its own label to any legal value, but only
3218c2ecf20Sopenharmony_ci	if it has ``CAP_MAC_ADMIN``. This interface allows a process without
3228c2ecf20Sopenharmony_ci	``CAP_MAC_ADMIN`` to relabel itself to one of labels from predefined list.
3238c2ecf20Sopenharmony_ci	A process without ``CAP_MAC_ADMIN`` can change its label only once. When it
3248c2ecf20Sopenharmony_ci	does, this list will be cleared.
3258c2ecf20Sopenharmony_ci	The values are set by writing the desired labels, separated
3268c2ecf20Sopenharmony_ci	by spaces, to the file or cleared by writing "-" to the file.
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ciIf you are using the smackload utility
3298c2ecf20Sopenharmony_ciyou can add access rules in ``/etc/smack/accesses``. They take the form::
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci    subjectlabel objectlabel access
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ciaccess is a combination of the letters rwxatb which specify the
3348c2ecf20Sopenharmony_cikind of access permitted a subject with subjectlabel on an
3358c2ecf20Sopenharmony_ciobject with objectlabel. If there is no rule no access is allowed.
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ciLook for additional programs on http://schaufler-ca.com
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ciThe Simplified Mandatory Access Control Kernel (Whitepaper)
3408c2ecf20Sopenharmony_ci===========================================================
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ciCasey Schaufler
3438c2ecf20Sopenharmony_cicasey@schaufler-ca.com
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ciMandatory Access Control
3468c2ecf20Sopenharmony_ci------------------------
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ciComputer systems employ a variety of schemes to constrain how information is
3498c2ecf20Sopenharmony_cishared among the people and services using the machine. Some of these schemes
3508c2ecf20Sopenharmony_ciallow the program or user to decide what other programs or users are allowed
3518c2ecf20Sopenharmony_ciaccess to pieces of data. These schemes are called discretionary access
3528c2ecf20Sopenharmony_cicontrol mechanisms because the access control is specified at the discretion
3538c2ecf20Sopenharmony_ciof the user. Other schemes do not leave the decision regarding what a user or
3548c2ecf20Sopenharmony_ciprogram can access up to users or programs. These schemes are called mandatory
3558c2ecf20Sopenharmony_ciaccess control mechanisms because you don't have a choice regarding the users
3568c2ecf20Sopenharmony_cior programs that have access to pieces of data.
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ciBell & LaPadula
3598c2ecf20Sopenharmony_ci---------------
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ciFrom the middle of the 1980's until the turn of the century Mandatory Access
3628c2ecf20Sopenharmony_ciControl (MAC) was very closely associated with the Bell & LaPadula security
3638c2ecf20Sopenharmony_cimodel, a mathematical description of the United States Department of Defense
3648c2ecf20Sopenharmony_cipolicy for marking paper documents. MAC in this form enjoyed a following
3658c2ecf20Sopenharmony_ciwithin the Capital Beltway and Scandinavian supercomputer centers but was
3668c2ecf20Sopenharmony_cioften sited as failing to address general needs.
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ciDomain Type Enforcement
3698c2ecf20Sopenharmony_ci-----------------------
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ciAround the turn of the century Domain Type Enforcement (DTE) became popular.
3728c2ecf20Sopenharmony_ciThis scheme organizes users, programs, and data into domains that are
3738c2ecf20Sopenharmony_ciprotected from each other. This scheme has been widely deployed as a component
3748c2ecf20Sopenharmony_ciof popular Linux distributions. The administrative overhead required to
3758c2ecf20Sopenharmony_cimaintain this scheme and the detailed understanding of the whole system
3768c2ecf20Sopenharmony_cinecessary to provide a secure domain mapping leads to the scheme being
3778c2ecf20Sopenharmony_cidisabled or used in limited ways in the majority of cases.
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ciSmack
3808c2ecf20Sopenharmony_ci-----
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ciSmack is a Mandatory Access Control mechanism designed to provide useful MAC
3838c2ecf20Sopenharmony_ciwhile avoiding the pitfalls of its predecessors. The limitations of Bell &
3848c2ecf20Sopenharmony_ciLaPadula are addressed by providing a scheme whereby access can be controlled
3858c2ecf20Sopenharmony_ciaccording to the requirements of the system and its purpose rather than those
3868c2ecf20Sopenharmony_ciimposed by an arcane government policy. The complexity of Domain Type
3878c2ecf20Sopenharmony_ciEnforcement and avoided by defining access controls in terms of the access
3888c2ecf20Sopenharmony_cimodes already in use.
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ciSmack Terminology
3918c2ecf20Sopenharmony_ci-----------------
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ciThe jargon used to talk about Smack will be familiar to those who have dealt
3948c2ecf20Sopenharmony_ciwith other MAC systems and shouldn't be too difficult for the uninitiated to
3958c2ecf20Sopenharmony_cipick up. There are four terms that are used in a specific way and that are
3968c2ecf20Sopenharmony_ciespecially important:
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci  Subject:
3998c2ecf20Sopenharmony_ci	A subject is an active entity on the computer system.
4008c2ecf20Sopenharmony_ci	On Smack a subject is a task, which is in turn the basic unit
4018c2ecf20Sopenharmony_ci	of execution.
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci  Object:
4048c2ecf20Sopenharmony_ci	An object is a passive entity on the computer system.
4058c2ecf20Sopenharmony_ci	On Smack files of all types, IPC, and tasks can be objects.
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci  Access:
4088c2ecf20Sopenharmony_ci	Any attempt by a subject to put information into or get
4098c2ecf20Sopenharmony_ci	information from an object is an access.
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci  Label:
4128c2ecf20Sopenharmony_ci	Data that identifies the Mandatory Access Control
4138c2ecf20Sopenharmony_ci	characteristics of a subject or an object.
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ciThese definitions are consistent with the traditional use in the security
4168c2ecf20Sopenharmony_cicommunity. There are also some terms from Linux that are likely to crop up:
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci  Capability:
4198c2ecf20Sopenharmony_ci	A task that possesses a capability has permission to
4208c2ecf20Sopenharmony_ci	violate an aspect of the system security policy, as identified by
4218c2ecf20Sopenharmony_ci	the specific capability. A task that possesses one or more
4228c2ecf20Sopenharmony_ci	capabilities is a privileged task, whereas a task with no
4238c2ecf20Sopenharmony_ci	capabilities is an unprivileged task.
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci  Privilege:
4268c2ecf20Sopenharmony_ci	A task that is allowed to violate the system security
4278c2ecf20Sopenharmony_ci	policy is said to have privilege. As of this writing a task can
4288c2ecf20Sopenharmony_ci	have privilege either by possessing capabilities or by having an
4298c2ecf20Sopenharmony_ci	effective user of root.
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ciSmack Basics
4328c2ecf20Sopenharmony_ci------------
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ciSmack is an extension to a Linux system. It enforces additional restrictions
4358c2ecf20Sopenharmony_cion what subjects can access which objects, based on the labels attached to
4368c2ecf20Sopenharmony_cieach of the subject and the object.
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ciLabels
4398c2ecf20Sopenharmony_ci~~~~~~
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ciSmack labels are ASCII character strings. They can be up to 255 characters
4428c2ecf20Sopenharmony_cilong, but keeping them to twenty-three characters is recommended.
4438c2ecf20Sopenharmony_ciSingle character labels using special characters, that being anything
4448c2ecf20Sopenharmony_ciother than a letter or digit, are reserved for use by the Smack development
4458c2ecf20Sopenharmony_citeam. Smack labels are unstructured, case sensitive, and the only operation
4468c2ecf20Sopenharmony_ciever performed on them is comparison for equality. Smack labels cannot
4478c2ecf20Sopenharmony_cicontain unprintable characters, the "/" (slash), the "\" (backslash), the "'"
4488c2ecf20Sopenharmony_ci(quote) and '"' (double-quote) characters.
4498c2ecf20Sopenharmony_ciSmack labels cannot begin with a '-'. This is reserved for special options.
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ciThere are some predefined labels::
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	_ 	Pronounced "floor", a single underscore character.
4548c2ecf20Sopenharmony_ci	^ 	Pronounced "hat", a single circumflex character.
4558c2ecf20Sopenharmony_ci	* 	Pronounced "star", a single asterisk character.
4568c2ecf20Sopenharmony_ci	? 	Pronounced "huh", a single question mark character.
4578c2ecf20Sopenharmony_ci	@ 	Pronounced "web", a single at sign character.
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ciEvery task on a Smack system is assigned a label. The Smack label
4608c2ecf20Sopenharmony_ciof a process will usually be assigned by the system initialization
4618c2ecf20Sopenharmony_cimechanism.
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ciAccess Rules
4648c2ecf20Sopenharmony_ci~~~~~~~~~~~~
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ciSmack uses the traditional access modes of Linux. These modes are read,
4678c2ecf20Sopenharmony_ciexecute, write, and occasionally append. There are a few cases where the
4688c2ecf20Sopenharmony_ciaccess mode may not be obvious. These include:
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci  Signals:
4718c2ecf20Sopenharmony_ci	A signal is a write operation from the subject task to
4728c2ecf20Sopenharmony_ci	the object task.
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci  Internet Domain IPC:
4758c2ecf20Sopenharmony_ci	Transmission of a packet is considered a
4768c2ecf20Sopenharmony_ci	write operation from the source task to the destination task.
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ciSmack restricts access based on the label attached to a subject and the label
4798c2ecf20Sopenharmony_ciattached to the object it is trying to access. The rules enforced are, in
4808c2ecf20Sopenharmony_ciorder:
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci	1. Any access requested by a task labeled "*" is denied.
4838c2ecf20Sopenharmony_ci	2. A read or execute access requested by a task labeled "^"
4848c2ecf20Sopenharmony_ci	   is permitted.
4858c2ecf20Sopenharmony_ci	3. A read or execute access requested on an object labeled "_"
4868c2ecf20Sopenharmony_ci	   is permitted.
4878c2ecf20Sopenharmony_ci	4. Any access requested on an object labeled "*" is permitted.
4888c2ecf20Sopenharmony_ci	5. Any access requested by a task on an object with the same
4898c2ecf20Sopenharmony_ci	   label is permitted.
4908c2ecf20Sopenharmony_ci	6. Any access requested that is explicitly defined in the loaded
4918c2ecf20Sopenharmony_ci	   rule set is permitted.
4928c2ecf20Sopenharmony_ci	7. Any other access is denied.
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ciSmack Access Rules
4958c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ciWith the isolation provided by Smack access separation is simple. There are
4988c2ecf20Sopenharmony_cimany interesting cases where limited access by subjects to objects with
4998c2ecf20Sopenharmony_cidifferent labels is desired. One example is the familiar spy model of
5008c2ecf20Sopenharmony_cisensitivity, where a scientist working on a highly classified project would be
5018c2ecf20Sopenharmony_ciable to read documents of lower classifications and anything she writes will
5028c2ecf20Sopenharmony_cibe "born" highly classified. To accommodate such schemes Smack includes a
5038c2ecf20Sopenharmony_cimechanism for specifying rules allowing access between labels.
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ciAccess Rule Format
5068c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ciThe format of an access rule is::
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci	subject-label object-label access
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ciWhere subject-label is the Smack label of the task, object-label is the Smack
5138c2ecf20Sopenharmony_cilabel of the thing being accessed, and access is a string specifying the sort
5148c2ecf20Sopenharmony_ciof access allowed. The access specification is searched for letters that
5158c2ecf20Sopenharmony_cidescribe access modes:
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ci	a: indicates that append access should be granted.
5188c2ecf20Sopenharmony_ci	r: indicates that read access should be granted.
5198c2ecf20Sopenharmony_ci	w: indicates that write access should be granted.
5208c2ecf20Sopenharmony_ci	x: indicates that execute access should be granted.
5218c2ecf20Sopenharmony_ci	t: indicates that the rule requests transmutation.
5228c2ecf20Sopenharmony_ci	b: indicates that the rule should be reported for bring-up.
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ciUppercase values for the specification letters are allowed as well.
5258c2ecf20Sopenharmony_ciAccess mode specifications can be in any order. Examples of acceptable rules
5268c2ecf20Sopenharmony_ciare::
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci	TopSecret Secret  rx
5298c2ecf20Sopenharmony_ci	Secret    Unclass R
5308c2ecf20Sopenharmony_ci	Manager   Game    x
5318c2ecf20Sopenharmony_ci	User      HR      w
5328c2ecf20Sopenharmony_ci	Snap      Crackle rwxatb
5338c2ecf20Sopenharmony_ci	New       Old     rRrRr
5348c2ecf20Sopenharmony_ci	Closed    Off     -
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ciExamples of unacceptable rules are::
5378c2ecf20Sopenharmony_ci
5388c2ecf20Sopenharmony_ci	Top Secret Secret     rx
5398c2ecf20Sopenharmony_ci	Ace        Ace        r
5408c2ecf20Sopenharmony_ci	Odd        spells     waxbeans
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ciSpaces are not allowed in labels. Since a subject always has access to files
5438c2ecf20Sopenharmony_ciwith the same label specifying a rule for that case is pointless. Only
5448c2ecf20Sopenharmony_civalid letters (rwxatbRWXATB) and the dash ('-') character are allowed in
5458c2ecf20Sopenharmony_ciaccess specifications. The dash is a placeholder, so "a-r" is the same
5468c2ecf20Sopenharmony_cias "ar". A lone dash is used to specify that no access should be allowed.
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ciApplying Access Rules
5498c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_ciThe developers of Linux rarely define new sorts of things, usually importing
5528c2ecf20Sopenharmony_cischemes and concepts from other systems. Most often, the other systems are
5538c2ecf20Sopenharmony_civariants of Unix. Unix has many endearing properties, but consistency of
5548c2ecf20Sopenharmony_ciaccess control models is not one of them. Smack strives to treat accesses as
5558c2ecf20Sopenharmony_ciuniformly as is sensible while keeping with the spirit of the underlying
5568c2ecf20Sopenharmony_cimechanism.
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ciFile system objects including files, directories, named pipes, symbolic links,
5598c2ecf20Sopenharmony_ciand devices require access permissions that closely match those used by mode
5608c2ecf20Sopenharmony_cibit access. To open a file for reading read access is required on the file. To
5618c2ecf20Sopenharmony_cisearch a directory requires execute access. Creating a file with write access
5628c2ecf20Sopenharmony_cirequires both read and write access on the containing directory. Deleting a
5638c2ecf20Sopenharmony_cifile requires read and write access to the file and to the containing
5648c2ecf20Sopenharmony_cidirectory. It is possible that a user may be able to see that a file exists
5658c2ecf20Sopenharmony_cibut not any of its attributes by the circumstance of having read access to the
5668c2ecf20Sopenharmony_cicontaining directory but not to the differently labeled file. This is an
5678c2ecf20Sopenharmony_ciartifact of the file name being data in the directory, not a part of the file.
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_ciIf a directory is marked as transmuting (SMACK64TRANSMUTE=TRUE) and the
5708c2ecf20Sopenharmony_ciaccess rule that allows a process to create an object in that directory
5718c2ecf20Sopenharmony_ciincludes 't' access the label assigned to the new object will be that
5728c2ecf20Sopenharmony_ciof the directory, not the creating process. This makes it much easier
5738c2ecf20Sopenharmony_cifor two processes with different labels to share data without granting
5748c2ecf20Sopenharmony_ciaccess to all of their files.
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_ciIPC objects, message queues, semaphore sets, and memory segments exist in flat
5778c2ecf20Sopenharmony_cinamespaces and access requests are only required to match the object in
5788c2ecf20Sopenharmony_ciquestion.
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ciProcess objects reflect tasks on the system and the Smack label used to access
5818c2ecf20Sopenharmony_cithem is the same Smack label that the task would use for its own access
5828c2ecf20Sopenharmony_ciattempts. Sending a signal via the kill() system call is a write operation
5838c2ecf20Sopenharmony_cifrom the signaler to the recipient. Debugging a process requires both reading
5848c2ecf20Sopenharmony_ciand writing. Creating a new task is an internal operation that results in two
5858c2ecf20Sopenharmony_citasks with identical Smack labels and requires no access checks.
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ciSockets are data structures attached to processes and sending a packet from
5888c2ecf20Sopenharmony_cione process to another requires that the sender have write access to the
5898c2ecf20Sopenharmony_cireceiver. The receiver is not required to have read access to the sender.
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ciSetting Access Rules
5928c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ciThe configuration file /etc/smack/accesses contains the rules to be set at
5958c2ecf20Sopenharmony_cisystem startup. The contents are written to the special file
5968c2ecf20Sopenharmony_ci/sys/fs/smackfs/load2. Rules can be added at any time and take effect
5978c2ecf20Sopenharmony_ciimmediately. For any pair of subject and object labels there can be only
5988c2ecf20Sopenharmony_cione rule, with the most recently specified overriding any earlier
5998c2ecf20Sopenharmony_cispecification.
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_ciTask Attribute
6028c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~
6038c2ecf20Sopenharmony_ci
6048c2ecf20Sopenharmony_ciThe Smack label of a process can be read from /proc/<pid>/attr/current. A
6058c2ecf20Sopenharmony_ciprocess can read its own Smack label from /proc/self/attr/current. A
6068c2ecf20Sopenharmony_ciprivileged process can change its own Smack label by writing to
6078c2ecf20Sopenharmony_ci/proc/self/attr/current but not the label of another process.
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_ciFile Attribute
6108c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ciThe Smack label of a filesystem object is stored as an extended attribute
6138c2ecf20Sopenharmony_cinamed SMACK64 on the file. This attribute is in the security namespace. It can
6148c2ecf20Sopenharmony_cionly be changed by a process with privilege.
6158c2ecf20Sopenharmony_ci
6168c2ecf20Sopenharmony_ciPrivilege
6178c2ecf20Sopenharmony_ci~~~~~~~~~
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ciA process with CAP_MAC_OVERRIDE or CAP_MAC_ADMIN is privileged.
6208c2ecf20Sopenharmony_ciCAP_MAC_OVERRIDE allows the process access to objects it would
6218c2ecf20Sopenharmony_cibe denied otherwise. CAP_MAC_ADMIN allows a process to change
6228c2ecf20Sopenharmony_ciSmack data, including rules and attributes.
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ciSmack Networking
6258c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_ciAs mentioned before, Smack enforces access control on network protocol
6288c2ecf20Sopenharmony_citransmissions. Every packet sent by a Smack process is tagged with its Smack
6298c2ecf20Sopenharmony_cilabel. This is done by adding a CIPSO tag to the header of the IP packet. Each
6308c2ecf20Sopenharmony_cipacket received is expected to have a CIPSO tag that identifies the label and
6318c2ecf20Sopenharmony_ciif it lacks such a tag the network ambient label is assumed. Before the packet
6328c2ecf20Sopenharmony_ciis delivered a check is made to determine that a subject with the label on the
6338c2ecf20Sopenharmony_cipacket has write access to the receiving process and if that is not the case
6348c2ecf20Sopenharmony_cithe packet is dropped.
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_ciCIPSO Configuration
6378c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~
6388c2ecf20Sopenharmony_ci
6398c2ecf20Sopenharmony_ciIt is normally unnecessary to specify the CIPSO configuration. The default
6408c2ecf20Sopenharmony_civalues used by the system handle all internal cases. Smack will compose CIPSO
6418c2ecf20Sopenharmony_cilabel values to match the Smack labels being used without administrative
6428c2ecf20Sopenharmony_ciintervention. Unlabeled packets that come into the system will be given the
6438c2ecf20Sopenharmony_ciambient label.
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_ciSmack requires configuration in the case where packets from a system that is
6468c2ecf20Sopenharmony_cinot Smack that speaks CIPSO may be encountered. Usually this will be a Trusted
6478c2ecf20Sopenharmony_ciSolaris system, but there are other, less widely deployed systems out there.
6488c2ecf20Sopenharmony_ciCIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level,
6498c2ecf20Sopenharmony_ciand a category set with each packet. The DOI is intended to identify a group
6508c2ecf20Sopenharmony_ciof systems that use compatible labeling schemes, and the DOI specified on the
6518c2ecf20Sopenharmony_ciSmack system must match that of the remote system or packets will be
6528c2ecf20Sopenharmony_cidiscarded. The DOI is 3 by default. The value can be read from
6538c2ecf20Sopenharmony_ci/sys/fs/smackfs/doi and can be changed by writing to /sys/fs/smackfs/doi.
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ciThe label and category set are mapped to a Smack label as defined in
6568c2ecf20Sopenharmony_ci/etc/smack/cipso.
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_ciA Smack/CIPSO mapping has the form::
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci	smack level [category [category]*]
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_ciSmack does not expect the level or category sets to be related in any
6638c2ecf20Sopenharmony_ciparticular way and does not assume or assign accesses based on them. Some
6648c2ecf20Sopenharmony_ciexamples of mappings::
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci	TopSecret 7
6678c2ecf20Sopenharmony_ci	TS:A,B    7 1 2
6688c2ecf20Sopenharmony_ci	SecBDE    5 2 4 6
6698c2ecf20Sopenharmony_ci	RAFTERS   7 12 26
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_ciThe ":" and "," characters are permitted in a Smack label but have no special
6728c2ecf20Sopenharmony_cimeaning.
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_ciThe mapping of Smack labels to CIPSO values is defined by writing to
6758c2ecf20Sopenharmony_ci/sys/fs/smackfs/cipso2.
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_ciIn addition to explicit mappings Smack supports direct CIPSO mappings. One
6788c2ecf20Sopenharmony_ciCIPSO level is used to indicate that the category set passed in the packet is
6798c2ecf20Sopenharmony_ciin fact an encoding of the Smack label. The level used is 250 by default. The
6808c2ecf20Sopenharmony_civalue can be read from /sys/fs/smackfs/direct and changed by writing to
6818c2ecf20Sopenharmony_ci/sys/fs/smackfs/direct.
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ciSocket Attributes
6848c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_ciThere are two attributes that are associated with sockets. These attributes
6878c2ecf20Sopenharmony_cican only be set by privileged tasks, but any task can read them for their own
6888c2ecf20Sopenharmony_cisockets.
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci  SMACK64IPIN:
6918c2ecf20Sopenharmony_ci	The Smack label of the task object. A privileged
6928c2ecf20Sopenharmony_ci	program that will enforce policy may set this to the star label.
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci  SMACK64IPOUT:
6958c2ecf20Sopenharmony_ci	The Smack label transmitted with outgoing packets.
6968c2ecf20Sopenharmony_ci	A privileged program may set this to match the label of another
6978c2ecf20Sopenharmony_ci	task with which it hopes to communicate.
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_ciSmack Netlabel Exceptions
7008c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_ciYou will often find that your labeled application has to talk to the outside,
7038c2ecf20Sopenharmony_ciunlabeled world. To do this there's a special file /sys/fs/smackfs/netlabel
7048c2ecf20Sopenharmony_ciwhere you can add some exceptions in the form of::
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_ci	@IP1	   LABEL1 or
7078c2ecf20Sopenharmony_ci	@IP2/MASK  LABEL2
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ciIt means that your application will have unlabeled access to @IP1 if it has
7108c2ecf20Sopenharmony_ciwrite access on LABEL1, and access to the subnet @IP2/MASK if it has write
7118c2ecf20Sopenharmony_ciaccess on LABEL2.
7128c2ecf20Sopenharmony_ci
7138c2ecf20Sopenharmony_ciEntries in the /sys/fs/smackfs/netlabel file are matched by longest mask
7148c2ecf20Sopenharmony_cifirst, like in classless IPv4 routing.
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ciA special label '@' and an option '-CIPSO' can be used there::
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_ci	@      means Internet, any application with any label has access to it
7198c2ecf20Sopenharmony_ci	-CIPSO means standard CIPSO networking
7208c2ecf20Sopenharmony_ci
7218c2ecf20Sopenharmony_ciIf you don't know what CIPSO is and don't plan to use it, you can just do::
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_ci	echo 127.0.0.1 -CIPSO > /sys/fs/smackfs/netlabel
7248c2ecf20Sopenharmony_ci	echo 0.0.0.0/0 @      > /sys/fs/smackfs/netlabel
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_ciIf you use CIPSO on your 192.168.0.0/16 local network and need also unlabeled
7278c2ecf20Sopenharmony_ciInternet access, you can have::
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ci	echo 127.0.0.1      -CIPSO > /sys/fs/smackfs/netlabel
7308c2ecf20Sopenharmony_ci	echo 192.168.0.0/16 -CIPSO > /sys/fs/smackfs/netlabel
7318c2ecf20Sopenharmony_ci	echo 0.0.0.0/0      @      > /sys/fs/smackfs/netlabel
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_ciWriting Applications for Smack
7348c2ecf20Sopenharmony_ci------------------------------
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ciThere are three sorts of applications that will run on a Smack system. How an
7378c2ecf20Sopenharmony_ciapplication interacts with Smack will determine what it will have to do to
7388c2ecf20Sopenharmony_ciwork properly under Smack.
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ciSmack Ignorant Applications
7418c2ecf20Sopenharmony_ci---------------------------
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ciBy far the majority of applications have no reason whatever to care about the
7448c2ecf20Sopenharmony_ciunique properties of Smack. Since invoking a program has no impact on the
7458c2ecf20Sopenharmony_ciSmack label associated with the process the only concern likely to arise is
7468c2ecf20Sopenharmony_ciwhether the process has execute access to the program.
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ciSmack Relevant Applications
7498c2ecf20Sopenharmony_ci---------------------------
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_ciSome programs can be improved by teaching them about Smack, but do not make
7528c2ecf20Sopenharmony_ciany security decisions themselves. The utility ls(1) is one example of such a
7538c2ecf20Sopenharmony_ciprogram.
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_ciSmack Enforcing Applications
7568c2ecf20Sopenharmony_ci----------------------------
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_ciThese are special programs that not only know about Smack, but participate in
7598c2ecf20Sopenharmony_cithe enforcement of system policy. In most cases these are the programs that
7608c2ecf20Sopenharmony_ciset up user sessions. There are also network services that provide information
7618c2ecf20Sopenharmony_cito processes running with various labels.
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_ciFile System Interfaces
7648c2ecf20Sopenharmony_ci----------------------
7658c2ecf20Sopenharmony_ci
7668c2ecf20Sopenharmony_ciSmack maintains labels on file system objects using extended attributes. The
7678c2ecf20Sopenharmony_ciSmack label of a file, directory, or other file system object can be obtained
7688c2ecf20Sopenharmony_ciusing getxattr(2)::
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ci	len = getxattr("/", "security.SMACK64", value, sizeof (value));
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_ciwill put the Smack label of the root directory into value. A privileged
7738c2ecf20Sopenharmony_ciprocess can set the Smack label of a file system object with setxattr(2)::
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_ci	len = strlen("Rubble");
7768c2ecf20Sopenharmony_ci	rc = setxattr("/foo", "security.SMACK64", "Rubble", len, 0);
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_ciwill set the Smack label of /foo to "Rubble" if the program has appropriate
7798c2ecf20Sopenharmony_ciprivilege.
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ciSocket Interfaces
7828c2ecf20Sopenharmony_ci-----------------
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ciThe socket attributes can be read using fgetxattr(2).
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ciA privileged process can set the Smack label of outgoing packets with
7878c2ecf20Sopenharmony_cifsetxattr(2)::
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci	len = strlen("Rubble");
7908c2ecf20Sopenharmony_ci	rc = fsetxattr(fd, "security.SMACK64IPOUT", "Rubble", len, 0);
7918c2ecf20Sopenharmony_ci
7928c2ecf20Sopenharmony_ciwill set the Smack label "Rubble" on packets going out from the socket if the
7938c2ecf20Sopenharmony_ciprogram has appropriate privilege::
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_ci	rc = fsetxattr(fd, "security.SMACK64IPIN, "*", strlen("*"), 0);
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ciwill set the Smack label "*" as the object label against which incoming
7988c2ecf20Sopenharmony_cipackets will be checked if the program has appropriate privilege.
7998c2ecf20Sopenharmony_ci
8008c2ecf20Sopenharmony_ciAdministration
8018c2ecf20Sopenharmony_ci--------------
8028c2ecf20Sopenharmony_ci
8038c2ecf20Sopenharmony_ciSmack supports some mount options:
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci  smackfsdef=label:
8068c2ecf20Sopenharmony_ci	specifies the label to give files that lack
8078c2ecf20Sopenharmony_ci	the Smack label extended attribute.
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci  smackfsroot=label:
8108c2ecf20Sopenharmony_ci	specifies the label to assign the root of the
8118c2ecf20Sopenharmony_ci	file system if it lacks the Smack extended attribute.
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci  smackfshat=label:
8148c2ecf20Sopenharmony_ci	specifies a label that must have read access to
8158c2ecf20Sopenharmony_ci	all labels set on the filesystem. Not yet enforced.
8168c2ecf20Sopenharmony_ci
8178c2ecf20Sopenharmony_ci  smackfsfloor=label:
8188c2ecf20Sopenharmony_ci	specifies a label to which all labels set on the
8198c2ecf20Sopenharmony_ci	filesystem must have read access. Not yet enforced.
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci  smackfstransmute=label:
8228c2ecf20Sopenharmony_ci	behaves exactly like smackfsroot except that it also
8238c2ecf20Sopenharmony_ci	sets the transmute flag on the root of the mount
8248c2ecf20Sopenharmony_ci
8258c2ecf20Sopenharmony_ciThese mount options apply to all file system types.
8268c2ecf20Sopenharmony_ci
8278c2ecf20Sopenharmony_ciSmack auditing
8288c2ecf20Sopenharmony_ci--------------
8298c2ecf20Sopenharmony_ci
8308c2ecf20Sopenharmony_ciIf you want Smack auditing of security events, you need to set CONFIG_AUDIT
8318c2ecf20Sopenharmony_ciin your kernel configuration.
8328c2ecf20Sopenharmony_ciBy default, all denied events will be audited. You can change this behavior by
8338c2ecf20Sopenharmony_ciwriting a single character to the /sys/fs/smackfs/logging file::
8348c2ecf20Sopenharmony_ci
8358c2ecf20Sopenharmony_ci	0 : no logging
8368c2ecf20Sopenharmony_ci	1 : log denied (default)
8378c2ecf20Sopenharmony_ci	2 : log accepted
8388c2ecf20Sopenharmony_ci	3 : log denied & accepted
8398c2ecf20Sopenharmony_ci
8408c2ecf20Sopenharmony_ciEvents are logged as 'key=value' pairs, for each event you at least will get
8418c2ecf20Sopenharmony_cithe subject, the object, the rights requested, the action, the kernel function
8428c2ecf20Sopenharmony_cithat triggered the event, plus other pairs depending on the type of event
8438c2ecf20Sopenharmony_ciaudited.
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ciBringup Mode
8468c2ecf20Sopenharmony_ci------------
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_ciBringup mode provides logging features that can make application
8498c2ecf20Sopenharmony_ciconfiguration and system bringup easier. Configure the kernel with
8508c2ecf20Sopenharmony_ciCONFIG_SECURITY_SMACK_BRINGUP to enable these features. When bringup
8518c2ecf20Sopenharmony_cimode is enabled accesses that succeed due to rules marked with the "b"
8528c2ecf20Sopenharmony_ciaccess mode will logged. When a new label is introduced for processes
8538c2ecf20Sopenharmony_cirules can be added aggressively, marked with the "b". The logging allows
8548c2ecf20Sopenharmony_citracking of which rules actual get used for that label.
8558c2ecf20Sopenharmony_ci
8568c2ecf20Sopenharmony_ciAnother feature of bringup mode is the "unconfined" option. Writing
8578c2ecf20Sopenharmony_cia label to /sys/fs/smackfs/unconfined makes subjects with that label
8588c2ecf20Sopenharmony_ciable to access any object, and objects with that label accessible to
8598c2ecf20Sopenharmony_ciall subjects. Any access that is granted because a label is unconfined
8608c2ecf20Sopenharmony_ciis logged. This feature is dangerous, as files and directories may
8618c2ecf20Sopenharmony_cibe created in places they couldn't if the policy were being enforced.
862