162306a36Sopenharmony_ci===== 262306a36Sopenharmony_ciSmack 362306a36Sopenharmony_ci===== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci "Good for you, you've decided to clean the elevator!" 762306a36Sopenharmony_ci - The Elevator, from Dark Star 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciSmack is the Simplified Mandatory Access Control Kernel. 1062306a36Sopenharmony_ciSmack is a kernel based implementation of mandatory access 1162306a36Sopenharmony_cicontrol that includes simplicity in its primary design goals. 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciSmack is not the only Mandatory Access Control scheme 1462306a36Sopenharmony_ciavailable for Linux. Those new to Mandatory Access Control 1562306a36Sopenharmony_ciare encouraged to compare Smack with the other mechanisms 1662306a36Sopenharmony_ciavailable to determine which is best suited to the problem 1762306a36Sopenharmony_ciat hand. 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciSmack consists of three major components: 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci - The kernel 2262306a36Sopenharmony_ci - Basic utilities, which are helpful but not required 2362306a36Sopenharmony_ci - Configuration data 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ciThe kernel component of Smack is implemented as a Linux 2662306a36Sopenharmony_ciSecurity Modules (LSM) module. It requires netlabel and 2762306a36Sopenharmony_ciworks best with file systems that support extended attributes, 2862306a36Sopenharmony_cialthough xattr support is not strictly required. 2962306a36Sopenharmony_ciIt is safe to run a Smack kernel under a "vanilla" distribution. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciSmack kernels use the CIPSO IP option. Some network 3262306a36Sopenharmony_ciconfigurations are intolerant of IP options and can impede 3362306a36Sopenharmony_ciaccess to systems that use them as Smack does. 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciSmack is used in the Tizen operating system. Please 3662306a36Sopenharmony_cigo to http://wiki.tizen.org for information about how 3762306a36Sopenharmony_ciSmack is used in Tizen. 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ciThe current git repository for Smack user space is: 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci git://github.com/smack-team/smack.git 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ciThis should make and install on most modern distributions. 4462306a36Sopenharmony_ciThere are five commands included in smackutil: 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_cichsmack: 4762306a36Sopenharmony_ci display or set Smack extended attribute values 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_cismackctl: 5062306a36Sopenharmony_ci load the Smack access rules 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_cismackaccess: 5362306a36Sopenharmony_ci report if a process with one label has access 5462306a36Sopenharmony_ci to an object with another 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciThese two commands are obsolete with the introduction of 5762306a36Sopenharmony_cithe smackfs/load2 and smackfs/cipso2 interfaces. 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_cismackload: 6062306a36Sopenharmony_ci properly formats data for writing to smackfs/load 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_cismackcipso: 6362306a36Sopenharmony_ci properly formats data for writing to smackfs/cipso 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ciIn keeping with the intent of Smack, configuration data is 6662306a36Sopenharmony_ciminimal and not strictly required. The most important 6762306a36Sopenharmony_ciconfiguration step is mounting the smackfs pseudo filesystem. 6862306a36Sopenharmony_ciIf smackutil is installed the startup script will take care 6962306a36Sopenharmony_ciof this, but it can be manually as well. 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciAdd this line to ``/etc/fstab``:: 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci smackfs /sys/fs/smackfs smackfs defaults 0 0 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ciThe ``/sys/fs/smackfs`` directory is created by the kernel. 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ciSmack uses extended attributes (xattrs) to store labels on filesystem 7862306a36Sopenharmony_ciobjects. The attributes are stored in the extended attribute security 7962306a36Sopenharmony_ciname space. A process must have ``CAP_MAC_ADMIN`` to change any of these 8062306a36Sopenharmony_ciattributes. 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ciThe extended attributes that Smack uses are: 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ciSMACK64 8562306a36Sopenharmony_ci Used to make access control decisions. In almost all cases 8662306a36Sopenharmony_ci the label given to a new filesystem object will be the label 8762306a36Sopenharmony_ci of the process that created it. 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciSMACK64EXEC 9062306a36Sopenharmony_ci The Smack label of a process that execs a program file with 9162306a36Sopenharmony_ci this attribute set will run with this attribute's value. 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ciSMACK64MMAP 9462306a36Sopenharmony_ci Don't allow the file to be mmapped by a process whose Smack 9562306a36Sopenharmony_ci label does not allow all of the access permitted to a process 9662306a36Sopenharmony_ci with the label contained in this attribute. This is a very 9762306a36Sopenharmony_ci specific use case for shared libraries. 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ciSMACK64TRANSMUTE 10062306a36Sopenharmony_ci Can only have the value "TRUE". If this attribute is present 10162306a36Sopenharmony_ci on a directory when an object is created in the directory and 10262306a36Sopenharmony_ci the Smack rule (more below) that permitted the write access 10362306a36Sopenharmony_ci to the directory includes the transmute ("t") mode the object 10462306a36Sopenharmony_ci gets the label of the directory instead of the label of the 10562306a36Sopenharmony_ci creating process. If the object being created is a directory 10662306a36Sopenharmony_ci the SMACK64TRANSMUTE attribute is set as well. 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ciSMACK64IPIN 10962306a36Sopenharmony_ci This attribute is only available on file descriptors for sockets. 11062306a36Sopenharmony_ci Use the Smack label in this attribute for access control 11162306a36Sopenharmony_ci decisions on packets being delivered to this socket. 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ciSMACK64IPOUT 11462306a36Sopenharmony_ci This attribute is only available on file descriptors for sockets. 11562306a36Sopenharmony_ci Use the Smack label in this attribute for access control 11662306a36Sopenharmony_ci decisions on packets coming from this socket. 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ciThere are multiple ways to set a Smack label on a file:: 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci # attr -S -s SMACK64 -V "value" path 12162306a36Sopenharmony_ci # chsmack -a value path 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ciA process can see the Smack label it is running with by 12462306a36Sopenharmony_cireading ``/proc/self/attr/current``. A process with ``CAP_MAC_ADMIN`` 12562306a36Sopenharmony_cican set the process Smack by writing there. 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ciMost Smack configuration is accomplished by writing to files 12862306a36Sopenharmony_ciin the smackfs filesystem. This pseudo-filesystem is mounted 12962306a36Sopenharmony_cion ``/sys/fs/smackfs``. 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ciaccess 13262306a36Sopenharmony_ci Provided for backward compatibility. The access2 interface 13362306a36Sopenharmony_ci is preferred and should be used instead. 13462306a36Sopenharmony_ci This interface reports whether a subject with the specified 13562306a36Sopenharmony_ci Smack label has a particular access to an object with a 13662306a36Sopenharmony_ci specified Smack label. Write a fixed format access rule to 13762306a36Sopenharmony_ci this file. The next read will indicate whether the access 13862306a36Sopenharmony_ci would be permitted. The text will be either "1" indicating 13962306a36Sopenharmony_ci access, or "0" indicating denial. 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ciaccess2 14262306a36Sopenharmony_ci This interface reports whether a subject with the specified 14362306a36Sopenharmony_ci Smack label has a particular access to an object with a 14462306a36Sopenharmony_ci specified Smack label. Write a long format access rule to 14562306a36Sopenharmony_ci this file. The next read will indicate whether the access 14662306a36Sopenharmony_ci would be permitted. The text will be either "1" indicating 14762306a36Sopenharmony_ci access, or "0" indicating denial. 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ciambient 15062306a36Sopenharmony_ci This contains the Smack label applied to unlabeled network 15162306a36Sopenharmony_ci packets. 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_cichange-rule 15462306a36Sopenharmony_ci This interface allows modification of existing access control rules. 15562306a36Sopenharmony_ci The format accepted on write is:: 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci "%s %s %s %s" 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci where the first string is the subject label, the second the 16062306a36Sopenharmony_ci object label, the third the access to allow and the fourth the 16162306a36Sopenharmony_ci access to deny. The access strings may contain only the characters 16262306a36Sopenharmony_ci "rwxat-". If a rule for a given subject and object exists it will be 16362306a36Sopenharmony_ci modified by enabling the permissions in the third string and disabling 16462306a36Sopenharmony_ci those in the fourth string. If there is no such rule it will be 16562306a36Sopenharmony_ci created using the access specified in the third and the fourth strings. 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_cicipso 16862306a36Sopenharmony_ci Provided for backward compatibility. The cipso2 interface 16962306a36Sopenharmony_ci is preferred and should be used instead. 17062306a36Sopenharmony_ci This interface allows a specific CIPSO header to be assigned 17162306a36Sopenharmony_ci to a Smack label. The format accepted on write is:: 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci "%24s%4d%4d"["%4d"]... 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci The first string is a fixed Smack label. The first number is 17662306a36Sopenharmony_ci the level to use. The second number is the number of categories. 17762306a36Sopenharmony_ci The following numbers are the categories:: 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci "level-3-cats-5-19 3 2 5 19" 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_cicipso2 18262306a36Sopenharmony_ci This interface allows a specific CIPSO header to be assigned 18362306a36Sopenharmony_ci to a Smack label. The format accepted on write is:: 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci "%s%4d%4d"["%4d"]... 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci The first string is a long Smack label. The first number is 18862306a36Sopenharmony_ci the level to use. The second number is the number of categories. 18962306a36Sopenharmony_ci The following numbers are the categories:: 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci "level-3-cats-5-19 3 2 5 19" 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_cidirect 19462306a36Sopenharmony_ci This contains the CIPSO level used for Smack direct label 19562306a36Sopenharmony_ci representation in network packets. 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_cidoi 19862306a36Sopenharmony_ci This contains the CIPSO domain of interpretation used in 19962306a36Sopenharmony_ci network packets. 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ciipv6host 20262306a36Sopenharmony_ci This interface allows specific IPv6 internet addresses to be 20362306a36Sopenharmony_ci treated as single label hosts. Packets are sent to single 20462306a36Sopenharmony_ci label hosts only from processes that have Smack write access 20562306a36Sopenharmony_ci to the host label. All packets received from single label hosts 20662306a36Sopenharmony_ci are given the specified label. The format accepted on write is:: 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci "%h:%h:%h:%h:%h:%h:%h:%h label" or 20962306a36Sopenharmony_ci "%h:%h:%h:%h:%h:%h:%h:%h/%d label". 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ci The "::" address shortcut is not supported. 21262306a36Sopenharmony_ci If label is "-DELETE" a matched entry will be deleted. 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ciload 21562306a36Sopenharmony_ci Provided for backward compatibility. The load2 interface 21662306a36Sopenharmony_ci is preferred and should be used instead. 21762306a36Sopenharmony_ci This interface allows access control rules in addition to 21862306a36Sopenharmony_ci the system defined rules to be specified. The format accepted 21962306a36Sopenharmony_ci on write is:: 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci "%24s%24s%5s" 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci where the first string is the subject label, the second the 22462306a36Sopenharmony_ci object label, and the third the requested access. The access 22562306a36Sopenharmony_ci string may contain only the characters "rwxat-", and specifies 22662306a36Sopenharmony_ci which sort of access is allowed. The "-" is a placeholder for 22762306a36Sopenharmony_ci permissions that are not allowed. The string "r-x--" would 22862306a36Sopenharmony_ci specify read and execute access. Labels are limited to 23 22962306a36Sopenharmony_ci characters in length. 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ciload2 23262306a36Sopenharmony_ci This interface allows access control rules in addition to 23362306a36Sopenharmony_ci the system defined rules to be specified. The format accepted 23462306a36Sopenharmony_ci on write is:: 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci "%s %s %s" 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci where the first string is the subject label, the second the 23962306a36Sopenharmony_ci object label, and the third the requested access. The access 24062306a36Sopenharmony_ci string may contain only the characters "rwxat-", and specifies 24162306a36Sopenharmony_ci which sort of access is allowed. The "-" is a placeholder for 24262306a36Sopenharmony_ci permissions that are not allowed. The string "r-x--" would 24362306a36Sopenharmony_ci specify read and execute access. 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ciload-self 24662306a36Sopenharmony_ci Provided for backward compatibility. The load-self2 interface 24762306a36Sopenharmony_ci is preferred and should be used instead. 24862306a36Sopenharmony_ci This interface allows process specific access rules to be 24962306a36Sopenharmony_ci defined. These rules are only consulted if access would 25062306a36Sopenharmony_ci otherwise be permitted, and are intended to provide additional 25162306a36Sopenharmony_ci restrictions on the process. The format is the same as for 25262306a36Sopenharmony_ci the load interface. 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ciload-self2 25562306a36Sopenharmony_ci This interface allows process specific access rules to be 25662306a36Sopenharmony_ci defined. These rules are only consulted if access would 25762306a36Sopenharmony_ci otherwise be permitted, and are intended to provide additional 25862306a36Sopenharmony_ci restrictions on the process. The format is the same as for 25962306a36Sopenharmony_ci the load2 interface. 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_cilogging 26262306a36Sopenharmony_ci This contains the Smack logging state. 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_cimapped 26562306a36Sopenharmony_ci This contains the CIPSO level used for Smack mapped label 26662306a36Sopenharmony_ci representation in network packets. 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_cinetlabel 26962306a36Sopenharmony_ci This interface allows specific internet addresses to be 27062306a36Sopenharmony_ci treated as single label hosts. Packets are sent to single 27162306a36Sopenharmony_ci label hosts without CIPSO headers, but only from processes 27262306a36Sopenharmony_ci that have Smack write access to the host label. All packets 27362306a36Sopenharmony_ci received from single label hosts are given the specified 27462306a36Sopenharmony_ci label. The format accepted on write is:: 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci "%d.%d.%d.%d label" or "%d.%d.%d.%d/%d label". 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci If the label specified is "-CIPSO" the address is treated 27962306a36Sopenharmony_ci as a host that supports CIPSO headers. 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_cionlycap 28262306a36Sopenharmony_ci This contains labels processes must have for CAP_MAC_ADMIN 28362306a36Sopenharmony_ci and ``CAP_MAC_OVERRIDE`` to be effective. If this file is empty 28462306a36Sopenharmony_ci these capabilities are effective at for processes with any 28562306a36Sopenharmony_ci label. The values are set by writing the desired labels, separated 28662306a36Sopenharmony_ci by spaces, to the file or cleared by writing "-" to the file. 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ciptrace 28962306a36Sopenharmony_ci This is used to define the current ptrace policy 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_ci 0 - default: 29262306a36Sopenharmony_ci this is the policy that relies on Smack access rules. 29362306a36Sopenharmony_ci For the ``PTRACE_READ`` a subject needs to have a read access on 29462306a36Sopenharmony_ci object. For the ``PTRACE_ATTACH`` a read-write access is required. 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci 1 - exact: 29762306a36Sopenharmony_ci this is the policy that limits ``PTRACE_ATTACH``. Attach is 29862306a36Sopenharmony_ci only allowed when subject's and object's labels are equal. 29962306a36Sopenharmony_ci ``PTRACE_READ`` is not affected. Can be overridden with ``CAP_SYS_PTRACE``. 30062306a36Sopenharmony_ci 30162306a36Sopenharmony_ci 2 - draconian: 30262306a36Sopenharmony_ci this policy behaves like the 'exact' above with an 30362306a36Sopenharmony_ci exception that it can't be overridden with ``CAP_SYS_PTRACE``. 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_cirevoke-subject 30662306a36Sopenharmony_ci Writing a Smack label here sets the access to '-' for all access 30762306a36Sopenharmony_ci rules with that subject label. 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_ciunconfined 31062306a36Sopenharmony_ci If the kernel is configured with ``CONFIG_SECURITY_SMACK_BRINGUP`` 31162306a36Sopenharmony_ci a process with ``CAP_MAC_ADMIN`` can write a label into this interface. 31262306a36Sopenharmony_ci Thereafter, accesses that involve that label will be logged and 31362306a36Sopenharmony_ci the access permitted if it wouldn't be otherwise. Note that this 31462306a36Sopenharmony_ci is dangerous and can ruin the proper labeling of your system. 31562306a36Sopenharmony_ci It should never be used in production. 31662306a36Sopenharmony_ci 31762306a36Sopenharmony_cirelabel-self 31862306a36Sopenharmony_ci This interface contains a list of labels to which the process can 31962306a36Sopenharmony_ci transition to, by writing to ``/proc/self/attr/current``. 32062306a36Sopenharmony_ci Normally a process can change its own label to any legal value, but only 32162306a36Sopenharmony_ci if it has ``CAP_MAC_ADMIN``. This interface allows a process without 32262306a36Sopenharmony_ci ``CAP_MAC_ADMIN`` to relabel itself to one of labels from predefined list. 32362306a36Sopenharmony_ci A process without ``CAP_MAC_ADMIN`` can change its label only once. When it 32462306a36Sopenharmony_ci does, this list will be cleared. 32562306a36Sopenharmony_ci The values are set by writing the desired labels, separated 32662306a36Sopenharmony_ci by spaces, to the file or cleared by writing "-" to the file. 32762306a36Sopenharmony_ci 32862306a36Sopenharmony_ciIf you are using the smackload utility 32962306a36Sopenharmony_ciyou can add access rules in ``/etc/smack/accesses``. They take the form:: 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ci subjectlabel objectlabel access 33262306a36Sopenharmony_ci 33362306a36Sopenharmony_ciaccess is a combination of the letters rwxatb which specify the 33462306a36Sopenharmony_cikind of access permitted a subject with subjectlabel on an 33562306a36Sopenharmony_ciobject with objectlabel. If there is no rule no access is allowed. 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ciLook for additional programs on http://schaufler-ca.com 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ciThe Simplified Mandatory Access Control Kernel (Whitepaper) 34062306a36Sopenharmony_ci=========================================================== 34162306a36Sopenharmony_ci 34262306a36Sopenharmony_ciCasey Schaufler 34362306a36Sopenharmony_cicasey@schaufler-ca.com 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ciMandatory Access Control 34662306a36Sopenharmony_ci------------------------ 34762306a36Sopenharmony_ci 34862306a36Sopenharmony_ciComputer systems employ a variety of schemes to constrain how information is 34962306a36Sopenharmony_cishared among the people and services using the machine. Some of these schemes 35062306a36Sopenharmony_ciallow the program or user to decide what other programs or users are allowed 35162306a36Sopenharmony_ciaccess to pieces of data. These schemes are called discretionary access 35262306a36Sopenharmony_cicontrol mechanisms because the access control is specified at the discretion 35362306a36Sopenharmony_ciof the user. Other schemes do not leave the decision regarding what a user or 35462306a36Sopenharmony_ciprogram can access up to users or programs. These schemes are called mandatory 35562306a36Sopenharmony_ciaccess control mechanisms because you don't have a choice regarding the users 35662306a36Sopenharmony_cior programs that have access to pieces of data. 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ciBell & LaPadula 35962306a36Sopenharmony_ci--------------- 36062306a36Sopenharmony_ci 36162306a36Sopenharmony_ciFrom the middle of the 1980's until the turn of the century Mandatory Access 36262306a36Sopenharmony_ciControl (MAC) was very closely associated with the Bell & LaPadula security 36362306a36Sopenharmony_cimodel, a mathematical description of the United States Department of Defense 36462306a36Sopenharmony_cipolicy for marking paper documents. MAC in this form enjoyed a following 36562306a36Sopenharmony_ciwithin the Capital Beltway and Scandinavian supercomputer centers but was 36662306a36Sopenharmony_cioften sited as failing to address general needs. 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_ciDomain Type Enforcement 36962306a36Sopenharmony_ci----------------------- 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ciAround the turn of the century Domain Type Enforcement (DTE) became popular. 37262306a36Sopenharmony_ciThis scheme organizes users, programs, and data into domains that are 37362306a36Sopenharmony_ciprotected from each other. This scheme has been widely deployed as a component 37462306a36Sopenharmony_ciof popular Linux distributions. The administrative overhead required to 37562306a36Sopenharmony_cimaintain this scheme and the detailed understanding of the whole system 37662306a36Sopenharmony_cinecessary to provide a secure domain mapping leads to the scheme being 37762306a36Sopenharmony_cidisabled or used in limited ways in the majority of cases. 37862306a36Sopenharmony_ci 37962306a36Sopenharmony_ciSmack 38062306a36Sopenharmony_ci----- 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ciSmack is a Mandatory Access Control mechanism designed to provide useful MAC 38362306a36Sopenharmony_ciwhile avoiding the pitfalls of its predecessors. The limitations of Bell & 38462306a36Sopenharmony_ciLaPadula are addressed by providing a scheme whereby access can be controlled 38562306a36Sopenharmony_ciaccording to the requirements of the system and its purpose rather than those 38662306a36Sopenharmony_ciimposed by an arcane government policy. The complexity of Domain Type 38762306a36Sopenharmony_ciEnforcement and avoided by defining access controls in terms of the access 38862306a36Sopenharmony_cimodes already in use. 38962306a36Sopenharmony_ci 39062306a36Sopenharmony_ciSmack Terminology 39162306a36Sopenharmony_ci----------------- 39262306a36Sopenharmony_ci 39362306a36Sopenharmony_ciThe jargon used to talk about Smack will be familiar to those who have dealt 39462306a36Sopenharmony_ciwith other MAC systems and shouldn't be too difficult for the uninitiated to 39562306a36Sopenharmony_cipick up. There are four terms that are used in a specific way and that are 39662306a36Sopenharmony_ciespecially important: 39762306a36Sopenharmony_ci 39862306a36Sopenharmony_ci Subject: 39962306a36Sopenharmony_ci A subject is an active entity on the computer system. 40062306a36Sopenharmony_ci On Smack a subject is a task, which is in turn the basic unit 40162306a36Sopenharmony_ci of execution. 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci Object: 40462306a36Sopenharmony_ci An object is a passive entity on the computer system. 40562306a36Sopenharmony_ci On Smack files of all types, IPC, and tasks can be objects. 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_ci Access: 40862306a36Sopenharmony_ci Any attempt by a subject to put information into or get 40962306a36Sopenharmony_ci information from an object is an access. 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ci Label: 41262306a36Sopenharmony_ci Data that identifies the Mandatory Access Control 41362306a36Sopenharmony_ci characteristics of a subject or an object. 41462306a36Sopenharmony_ci 41562306a36Sopenharmony_ciThese definitions are consistent with the traditional use in the security 41662306a36Sopenharmony_cicommunity. There are also some terms from Linux that are likely to crop up: 41762306a36Sopenharmony_ci 41862306a36Sopenharmony_ci Capability: 41962306a36Sopenharmony_ci A task that possesses a capability has permission to 42062306a36Sopenharmony_ci violate an aspect of the system security policy, as identified by 42162306a36Sopenharmony_ci the specific capability. A task that possesses one or more 42262306a36Sopenharmony_ci capabilities is a privileged task, whereas a task with no 42362306a36Sopenharmony_ci capabilities is an unprivileged task. 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_ci Privilege: 42662306a36Sopenharmony_ci A task that is allowed to violate the system security 42762306a36Sopenharmony_ci policy is said to have privilege. As of this writing a task can 42862306a36Sopenharmony_ci have privilege either by possessing capabilities or by having an 42962306a36Sopenharmony_ci effective user of root. 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ciSmack Basics 43262306a36Sopenharmony_ci------------ 43362306a36Sopenharmony_ci 43462306a36Sopenharmony_ciSmack is an extension to a Linux system. It enforces additional restrictions 43562306a36Sopenharmony_cion what subjects can access which objects, based on the labels attached to 43662306a36Sopenharmony_cieach of the subject and the object. 43762306a36Sopenharmony_ci 43862306a36Sopenharmony_ciLabels 43962306a36Sopenharmony_ci~~~~~~ 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ciSmack labels are ASCII character strings. They can be up to 255 characters 44262306a36Sopenharmony_cilong, but keeping them to twenty-three characters is recommended. 44362306a36Sopenharmony_ciSingle character labels using special characters, that being anything 44462306a36Sopenharmony_ciother than a letter or digit, are reserved for use by the Smack development 44562306a36Sopenharmony_citeam. Smack labels are unstructured, case sensitive, and the only operation 44662306a36Sopenharmony_ciever performed on them is comparison for equality. Smack labels cannot 44762306a36Sopenharmony_cicontain unprintable characters, the "/" (slash), the "\" (backslash), the "'" 44862306a36Sopenharmony_ci(quote) and '"' (double-quote) characters. 44962306a36Sopenharmony_ciSmack labels cannot begin with a '-'. This is reserved for special options. 45062306a36Sopenharmony_ci 45162306a36Sopenharmony_ciThere are some predefined labels:: 45262306a36Sopenharmony_ci 45362306a36Sopenharmony_ci _ Pronounced "floor", a single underscore character. 45462306a36Sopenharmony_ci ^ Pronounced "hat", a single circumflex character. 45562306a36Sopenharmony_ci * Pronounced "star", a single asterisk character. 45662306a36Sopenharmony_ci ? Pronounced "huh", a single question mark character. 45762306a36Sopenharmony_ci @ Pronounced "web", a single at sign character. 45862306a36Sopenharmony_ci 45962306a36Sopenharmony_ciEvery task on a Smack system is assigned a label. The Smack label 46062306a36Sopenharmony_ciof a process will usually be assigned by the system initialization 46162306a36Sopenharmony_cimechanism. 46262306a36Sopenharmony_ci 46362306a36Sopenharmony_ciAccess Rules 46462306a36Sopenharmony_ci~~~~~~~~~~~~ 46562306a36Sopenharmony_ci 46662306a36Sopenharmony_ciSmack uses the traditional access modes of Linux. These modes are read, 46762306a36Sopenharmony_ciexecute, write, and occasionally append. There are a few cases where the 46862306a36Sopenharmony_ciaccess mode may not be obvious. These include: 46962306a36Sopenharmony_ci 47062306a36Sopenharmony_ci Signals: 47162306a36Sopenharmony_ci A signal is a write operation from the subject task to 47262306a36Sopenharmony_ci the object task. 47362306a36Sopenharmony_ci 47462306a36Sopenharmony_ci Internet Domain IPC: 47562306a36Sopenharmony_ci Transmission of a packet is considered a 47662306a36Sopenharmony_ci write operation from the source task to the destination task. 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_ciSmack restricts access based on the label attached to a subject and the label 47962306a36Sopenharmony_ciattached to the object it is trying to access. The rules enforced are, in 48062306a36Sopenharmony_ciorder: 48162306a36Sopenharmony_ci 48262306a36Sopenharmony_ci 1. Any access requested by a task labeled "*" is denied. 48362306a36Sopenharmony_ci 2. A read or execute access requested by a task labeled "^" 48462306a36Sopenharmony_ci is permitted. 48562306a36Sopenharmony_ci 3. A read or execute access requested on an object labeled "_" 48662306a36Sopenharmony_ci is permitted. 48762306a36Sopenharmony_ci 4. Any access requested on an object labeled "*" is permitted. 48862306a36Sopenharmony_ci 5. Any access requested by a task on an object with the same 48962306a36Sopenharmony_ci label is permitted. 49062306a36Sopenharmony_ci 6. Any access requested that is explicitly defined in the loaded 49162306a36Sopenharmony_ci rule set is permitted. 49262306a36Sopenharmony_ci 7. Any other access is denied. 49362306a36Sopenharmony_ci 49462306a36Sopenharmony_ciSmack Access Rules 49562306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~ 49662306a36Sopenharmony_ci 49762306a36Sopenharmony_ciWith the isolation provided by Smack access separation is simple. There are 49862306a36Sopenharmony_cimany interesting cases where limited access by subjects to objects with 49962306a36Sopenharmony_cidifferent labels is desired. One example is the familiar spy model of 50062306a36Sopenharmony_cisensitivity, where a scientist working on a highly classified project would be 50162306a36Sopenharmony_ciable to read documents of lower classifications and anything she writes will 50262306a36Sopenharmony_cibe "born" highly classified. To accommodate such schemes Smack includes a 50362306a36Sopenharmony_cimechanism for specifying rules allowing access between labels. 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_ciAccess Rule Format 50662306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~ 50762306a36Sopenharmony_ci 50862306a36Sopenharmony_ciThe format of an access rule is:: 50962306a36Sopenharmony_ci 51062306a36Sopenharmony_ci subject-label object-label access 51162306a36Sopenharmony_ci 51262306a36Sopenharmony_ciWhere subject-label is the Smack label of the task, object-label is the Smack 51362306a36Sopenharmony_cilabel of the thing being accessed, and access is a string specifying the sort 51462306a36Sopenharmony_ciof access allowed. The access specification is searched for letters that 51562306a36Sopenharmony_cidescribe access modes: 51662306a36Sopenharmony_ci 51762306a36Sopenharmony_ci a: indicates that append access should be granted. 51862306a36Sopenharmony_ci r: indicates that read access should be granted. 51962306a36Sopenharmony_ci w: indicates that write access should be granted. 52062306a36Sopenharmony_ci x: indicates that execute access should be granted. 52162306a36Sopenharmony_ci t: indicates that the rule requests transmutation. 52262306a36Sopenharmony_ci b: indicates that the rule should be reported for bring-up. 52362306a36Sopenharmony_ci 52462306a36Sopenharmony_ciUppercase values for the specification letters are allowed as well. 52562306a36Sopenharmony_ciAccess mode specifications can be in any order. Examples of acceptable rules 52662306a36Sopenharmony_ciare:: 52762306a36Sopenharmony_ci 52862306a36Sopenharmony_ci TopSecret Secret rx 52962306a36Sopenharmony_ci Secret Unclass R 53062306a36Sopenharmony_ci Manager Game x 53162306a36Sopenharmony_ci User HR w 53262306a36Sopenharmony_ci Snap Crackle rwxatb 53362306a36Sopenharmony_ci New Old rRrRr 53462306a36Sopenharmony_ci Closed Off - 53562306a36Sopenharmony_ci 53662306a36Sopenharmony_ciExamples of unacceptable rules are:: 53762306a36Sopenharmony_ci 53862306a36Sopenharmony_ci Top Secret Secret rx 53962306a36Sopenharmony_ci Ace Ace r 54062306a36Sopenharmony_ci Odd spells waxbeans 54162306a36Sopenharmony_ci 54262306a36Sopenharmony_ciSpaces are not allowed in labels. Since a subject always has access to files 54362306a36Sopenharmony_ciwith the same label specifying a rule for that case is pointless. Only 54462306a36Sopenharmony_civalid letters (rwxatbRWXATB) and the dash ('-') character are allowed in 54562306a36Sopenharmony_ciaccess specifications. The dash is a placeholder, so "a-r" is the same 54662306a36Sopenharmony_cias "ar". A lone dash is used to specify that no access should be allowed. 54762306a36Sopenharmony_ci 54862306a36Sopenharmony_ciApplying Access Rules 54962306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~ 55062306a36Sopenharmony_ci 55162306a36Sopenharmony_ciThe developers of Linux rarely define new sorts of things, usually importing 55262306a36Sopenharmony_cischemes and concepts from other systems. Most often, the other systems are 55362306a36Sopenharmony_civariants of Unix. Unix has many endearing properties, but consistency of 55462306a36Sopenharmony_ciaccess control models is not one of them. Smack strives to treat accesses as 55562306a36Sopenharmony_ciuniformly as is sensible while keeping with the spirit of the underlying 55662306a36Sopenharmony_cimechanism. 55762306a36Sopenharmony_ci 55862306a36Sopenharmony_ciFile system objects including files, directories, named pipes, symbolic links, 55962306a36Sopenharmony_ciand devices require access permissions that closely match those used by mode 56062306a36Sopenharmony_cibit access. To open a file for reading read access is required on the file. To 56162306a36Sopenharmony_cisearch a directory requires execute access. Creating a file with write access 56262306a36Sopenharmony_cirequires both read and write access on the containing directory. Deleting a 56362306a36Sopenharmony_cifile requires read and write access to the file and to the containing 56462306a36Sopenharmony_cidirectory. It is possible that a user may be able to see that a file exists 56562306a36Sopenharmony_cibut not any of its attributes by the circumstance of having read access to the 56662306a36Sopenharmony_cicontaining directory but not to the differently labeled file. This is an 56762306a36Sopenharmony_ciartifact of the file name being data in the directory, not a part of the file. 56862306a36Sopenharmony_ci 56962306a36Sopenharmony_ciIf a directory is marked as transmuting (SMACK64TRANSMUTE=TRUE) and the 57062306a36Sopenharmony_ciaccess rule that allows a process to create an object in that directory 57162306a36Sopenharmony_ciincludes 't' access the label assigned to the new object will be that 57262306a36Sopenharmony_ciof the directory, not the creating process. This makes it much easier 57362306a36Sopenharmony_cifor two processes with different labels to share data without granting 57462306a36Sopenharmony_ciaccess to all of their files. 57562306a36Sopenharmony_ci 57662306a36Sopenharmony_ciIPC objects, message queues, semaphore sets, and memory segments exist in flat 57762306a36Sopenharmony_cinamespaces and access requests are only required to match the object in 57862306a36Sopenharmony_ciquestion. 57962306a36Sopenharmony_ci 58062306a36Sopenharmony_ciProcess objects reflect tasks on the system and the Smack label used to access 58162306a36Sopenharmony_cithem is the same Smack label that the task would use for its own access 58262306a36Sopenharmony_ciattempts. Sending a signal via the kill() system call is a write operation 58362306a36Sopenharmony_cifrom the signaler to the recipient. Debugging a process requires both reading 58462306a36Sopenharmony_ciand writing. Creating a new task is an internal operation that results in two 58562306a36Sopenharmony_citasks with identical Smack labels and requires no access checks. 58662306a36Sopenharmony_ci 58762306a36Sopenharmony_ciSockets are data structures attached to processes and sending a packet from 58862306a36Sopenharmony_cione process to another requires that the sender have write access to the 58962306a36Sopenharmony_cireceiver. The receiver is not required to have read access to the sender. 59062306a36Sopenharmony_ci 59162306a36Sopenharmony_ciSetting Access Rules 59262306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~ 59362306a36Sopenharmony_ci 59462306a36Sopenharmony_ciThe configuration file /etc/smack/accesses contains the rules to be set at 59562306a36Sopenharmony_cisystem startup. The contents are written to the special file 59662306a36Sopenharmony_ci/sys/fs/smackfs/load2. Rules can be added at any time and take effect 59762306a36Sopenharmony_ciimmediately. For any pair of subject and object labels there can be only 59862306a36Sopenharmony_cione rule, with the most recently specified overriding any earlier 59962306a36Sopenharmony_cispecification. 60062306a36Sopenharmony_ci 60162306a36Sopenharmony_ciTask Attribute 60262306a36Sopenharmony_ci~~~~~~~~~~~~~~ 60362306a36Sopenharmony_ci 60462306a36Sopenharmony_ciThe Smack label of a process can be read from /proc/<pid>/attr/current. A 60562306a36Sopenharmony_ciprocess can read its own Smack label from /proc/self/attr/current. A 60662306a36Sopenharmony_ciprivileged process can change its own Smack label by writing to 60762306a36Sopenharmony_ci/proc/self/attr/current but not the label of another process. 60862306a36Sopenharmony_ci 60962306a36Sopenharmony_ciFile Attribute 61062306a36Sopenharmony_ci~~~~~~~~~~~~~~ 61162306a36Sopenharmony_ci 61262306a36Sopenharmony_ciThe Smack label of a filesystem object is stored as an extended attribute 61362306a36Sopenharmony_cinamed SMACK64 on the file. This attribute is in the security namespace. It can 61462306a36Sopenharmony_cionly be changed by a process with privilege. 61562306a36Sopenharmony_ci 61662306a36Sopenharmony_ciPrivilege 61762306a36Sopenharmony_ci~~~~~~~~~ 61862306a36Sopenharmony_ci 61962306a36Sopenharmony_ciA process with CAP_MAC_OVERRIDE or CAP_MAC_ADMIN is privileged. 62062306a36Sopenharmony_ciCAP_MAC_OVERRIDE allows the process access to objects it would 62162306a36Sopenharmony_cibe denied otherwise. CAP_MAC_ADMIN allows a process to change 62262306a36Sopenharmony_ciSmack data, including rules and attributes. 62362306a36Sopenharmony_ci 62462306a36Sopenharmony_ciSmack Networking 62562306a36Sopenharmony_ci~~~~~~~~~~~~~~~~ 62662306a36Sopenharmony_ci 62762306a36Sopenharmony_ciAs mentioned before, Smack enforces access control on network protocol 62862306a36Sopenharmony_citransmissions. Every packet sent by a Smack process is tagged with its Smack 62962306a36Sopenharmony_cilabel. This is done by adding a CIPSO tag to the header of the IP packet. Each 63062306a36Sopenharmony_cipacket received is expected to have a CIPSO tag that identifies the label and 63162306a36Sopenharmony_ciif it lacks such a tag the network ambient label is assumed. Before the packet 63262306a36Sopenharmony_ciis delivered a check is made to determine that a subject with the label on the 63362306a36Sopenharmony_cipacket has write access to the receiving process and if that is not the case 63462306a36Sopenharmony_cithe packet is dropped. 63562306a36Sopenharmony_ci 63662306a36Sopenharmony_ciCIPSO Configuration 63762306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~ 63862306a36Sopenharmony_ci 63962306a36Sopenharmony_ciIt is normally unnecessary to specify the CIPSO configuration. The default 64062306a36Sopenharmony_civalues used by the system handle all internal cases. Smack will compose CIPSO 64162306a36Sopenharmony_cilabel values to match the Smack labels being used without administrative 64262306a36Sopenharmony_ciintervention. Unlabeled packets that come into the system will be given the 64362306a36Sopenharmony_ciambient label. 64462306a36Sopenharmony_ci 64562306a36Sopenharmony_ciSmack requires configuration in the case where packets from a system that is 64662306a36Sopenharmony_cinot Smack that speaks CIPSO may be encountered. Usually this will be a Trusted 64762306a36Sopenharmony_ciSolaris system, but there are other, less widely deployed systems out there. 64862306a36Sopenharmony_ciCIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level, 64962306a36Sopenharmony_ciand a category set with each packet. The DOI is intended to identify a group 65062306a36Sopenharmony_ciof systems that use compatible labeling schemes, and the DOI specified on the 65162306a36Sopenharmony_ciSmack system must match that of the remote system or packets will be 65262306a36Sopenharmony_cidiscarded. The DOI is 3 by default. The value can be read from 65362306a36Sopenharmony_ci/sys/fs/smackfs/doi and can be changed by writing to /sys/fs/smackfs/doi. 65462306a36Sopenharmony_ci 65562306a36Sopenharmony_ciThe label and category set are mapped to a Smack label as defined in 65662306a36Sopenharmony_ci/etc/smack/cipso. 65762306a36Sopenharmony_ci 65862306a36Sopenharmony_ciA Smack/CIPSO mapping has the form:: 65962306a36Sopenharmony_ci 66062306a36Sopenharmony_ci smack level [category [category]*] 66162306a36Sopenharmony_ci 66262306a36Sopenharmony_ciSmack does not expect the level or category sets to be related in any 66362306a36Sopenharmony_ciparticular way and does not assume or assign accesses based on them. Some 66462306a36Sopenharmony_ciexamples of mappings:: 66562306a36Sopenharmony_ci 66662306a36Sopenharmony_ci TopSecret 7 66762306a36Sopenharmony_ci TS:A,B 7 1 2 66862306a36Sopenharmony_ci SecBDE 5 2 4 6 66962306a36Sopenharmony_ci RAFTERS 7 12 26 67062306a36Sopenharmony_ci 67162306a36Sopenharmony_ciThe ":" and "," characters are permitted in a Smack label but have no special 67262306a36Sopenharmony_cimeaning. 67362306a36Sopenharmony_ci 67462306a36Sopenharmony_ciThe mapping of Smack labels to CIPSO values is defined by writing to 67562306a36Sopenharmony_ci/sys/fs/smackfs/cipso2. 67662306a36Sopenharmony_ci 67762306a36Sopenharmony_ciIn addition to explicit mappings Smack supports direct CIPSO mappings. One 67862306a36Sopenharmony_ciCIPSO level is used to indicate that the category set passed in the packet is 67962306a36Sopenharmony_ciin fact an encoding of the Smack label. The level used is 250 by default. The 68062306a36Sopenharmony_civalue can be read from /sys/fs/smackfs/direct and changed by writing to 68162306a36Sopenharmony_ci/sys/fs/smackfs/direct. 68262306a36Sopenharmony_ci 68362306a36Sopenharmony_ciSocket Attributes 68462306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~ 68562306a36Sopenharmony_ci 68662306a36Sopenharmony_ciThere are two attributes that are associated with sockets. These attributes 68762306a36Sopenharmony_cican only be set by privileged tasks, but any task can read them for their own 68862306a36Sopenharmony_cisockets. 68962306a36Sopenharmony_ci 69062306a36Sopenharmony_ci SMACK64IPIN: 69162306a36Sopenharmony_ci The Smack label of the task object. A privileged 69262306a36Sopenharmony_ci program that will enforce policy may set this to the star label. 69362306a36Sopenharmony_ci 69462306a36Sopenharmony_ci SMACK64IPOUT: 69562306a36Sopenharmony_ci The Smack label transmitted with outgoing packets. 69662306a36Sopenharmony_ci A privileged program may set this to match the label of another 69762306a36Sopenharmony_ci task with which it hopes to communicate. 69862306a36Sopenharmony_ci 69962306a36Sopenharmony_ciSmack Netlabel Exceptions 70062306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~ 70162306a36Sopenharmony_ci 70262306a36Sopenharmony_ciYou will often find that your labeled application has to talk to the outside, 70362306a36Sopenharmony_ciunlabeled world. To do this there's a special file /sys/fs/smackfs/netlabel 70462306a36Sopenharmony_ciwhere you can add some exceptions in the form of:: 70562306a36Sopenharmony_ci 70662306a36Sopenharmony_ci @IP1 LABEL1 or 70762306a36Sopenharmony_ci @IP2/MASK LABEL2 70862306a36Sopenharmony_ci 70962306a36Sopenharmony_ciIt means that your application will have unlabeled access to @IP1 if it has 71062306a36Sopenharmony_ciwrite access on LABEL1, and access to the subnet @IP2/MASK if it has write 71162306a36Sopenharmony_ciaccess on LABEL2. 71262306a36Sopenharmony_ci 71362306a36Sopenharmony_ciEntries in the /sys/fs/smackfs/netlabel file are matched by longest mask 71462306a36Sopenharmony_cifirst, like in classless IPv4 routing. 71562306a36Sopenharmony_ci 71662306a36Sopenharmony_ciA special label '@' and an option '-CIPSO' can be used there:: 71762306a36Sopenharmony_ci 71862306a36Sopenharmony_ci @ means Internet, any application with any label has access to it 71962306a36Sopenharmony_ci -CIPSO means standard CIPSO networking 72062306a36Sopenharmony_ci 72162306a36Sopenharmony_ciIf you don't know what CIPSO is and don't plan to use it, you can just do:: 72262306a36Sopenharmony_ci 72362306a36Sopenharmony_ci echo 127.0.0.1 -CIPSO > /sys/fs/smackfs/netlabel 72462306a36Sopenharmony_ci echo 0.0.0.0/0 @ > /sys/fs/smackfs/netlabel 72562306a36Sopenharmony_ci 72662306a36Sopenharmony_ciIf you use CIPSO on your 192.168.0.0/16 local network and need also unlabeled 72762306a36Sopenharmony_ciInternet access, you can have:: 72862306a36Sopenharmony_ci 72962306a36Sopenharmony_ci echo 127.0.0.1 -CIPSO > /sys/fs/smackfs/netlabel 73062306a36Sopenharmony_ci echo 192.168.0.0/16 -CIPSO > /sys/fs/smackfs/netlabel 73162306a36Sopenharmony_ci echo 0.0.0.0/0 @ > /sys/fs/smackfs/netlabel 73262306a36Sopenharmony_ci 73362306a36Sopenharmony_ciWriting Applications for Smack 73462306a36Sopenharmony_ci------------------------------ 73562306a36Sopenharmony_ci 73662306a36Sopenharmony_ciThere are three sorts of applications that will run on a Smack system. How an 73762306a36Sopenharmony_ciapplication interacts with Smack will determine what it will have to do to 73862306a36Sopenharmony_ciwork properly under Smack. 73962306a36Sopenharmony_ci 74062306a36Sopenharmony_ciSmack Ignorant Applications 74162306a36Sopenharmony_ci--------------------------- 74262306a36Sopenharmony_ci 74362306a36Sopenharmony_ciBy far the majority of applications have no reason whatever to care about the 74462306a36Sopenharmony_ciunique properties of Smack. Since invoking a program has no impact on the 74562306a36Sopenharmony_ciSmack label associated with the process the only concern likely to arise is 74662306a36Sopenharmony_ciwhether the process has execute access to the program. 74762306a36Sopenharmony_ci 74862306a36Sopenharmony_ciSmack Relevant Applications 74962306a36Sopenharmony_ci--------------------------- 75062306a36Sopenharmony_ci 75162306a36Sopenharmony_ciSome programs can be improved by teaching them about Smack, but do not make 75262306a36Sopenharmony_ciany security decisions themselves. The utility ls(1) is one example of such a 75362306a36Sopenharmony_ciprogram. 75462306a36Sopenharmony_ci 75562306a36Sopenharmony_ciSmack Enforcing Applications 75662306a36Sopenharmony_ci---------------------------- 75762306a36Sopenharmony_ci 75862306a36Sopenharmony_ciThese are special programs that not only know about Smack, but participate in 75962306a36Sopenharmony_cithe enforcement of system policy. In most cases these are the programs that 76062306a36Sopenharmony_ciset up user sessions. There are also network services that provide information 76162306a36Sopenharmony_cito processes running with various labels. 76262306a36Sopenharmony_ci 76362306a36Sopenharmony_ciFile System Interfaces 76462306a36Sopenharmony_ci---------------------- 76562306a36Sopenharmony_ci 76662306a36Sopenharmony_ciSmack maintains labels on file system objects using extended attributes. The 76762306a36Sopenharmony_ciSmack label of a file, directory, or other file system object can be obtained 76862306a36Sopenharmony_ciusing getxattr(2):: 76962306a36Sopenharmony_ci 77062306a36Sopenharmony_ci len = getxattr("/", "security.SMACK64", value, sizeof (value)); 77162306a36Sopenharmony_ci 77262306a36Sopenharmony_ciwill put the Smack label of the root directory into value. A privileged 77362306a36Sopenharmony_ciprocess can set the Smack label of a file system object with setxattr(2):: 77462306a36Sopenharmony_ci 77562306a36Sopenharmony_ci len = strlen("Rubble"); 77662306a36Sopenharmony_ci rc = setxattr("/foo", "security.SMACK64", "Rubble", len, 0); 77762306a36Sopenharmony_ci 77862306a36Sopenharmony_ciwill set the Smack label of /foo to "Rubble" if the program has appropriate 77962306a36Sopenharmony_ciprivilege. 78062306a36Sopenharmony_ci 78162306a36Sopenharmony_ciSocket Interfaces 78262306a36Sopenharmony_ci----------------- 78362306a36Sopenharmony_ci 78462306a36Sopenharmony_ciThe socket attributes can be read using fgetxattr(2). 78562306a36Sopenharmony_ci 78662306a36Sopenharmony_ciA privileged process can set the Smack label of outgoing packets with 78762306a36Sopenharmony_cifsetxattr(2):: 78862306a36Sopenharmony_ci 78962306a36Sopenharmony_ci len = strlen("Rubble"); 79062306a36Sopenharmony_ci rc = fsetxattr(fd, "security.SMACK64IPOUT", "Rubble", len, 0); 79162306a36Sopenharmony_ci 79262306a36Sopenharmony_ciwill set the Smack label "Rubble" on packets going out from the socket if the 79362306a36Sopenharmony_ciprogram has appropriate privilege:: 79462306a36Sopenharmony_ci 79562306a36Sopenharmony_ci rc = fsetxattr(fd, "security.SMACK64IPIN, "*", strlen("*"), 0); 79662306a36Sopenharmony_ci 79762306a36Sopenharmony_ciwill set the Smack label "*" as the object label against which incoming 79862306a36Sopenharmony_cipackets will be checked if the program has appropriate privilege. 79962306a36Sopenharmony_ci 80062306a36Sopenharmony_ciAdministration 80162306a36Sopenharmony_ci-------------- 80262306a36Sopenharmony_ci 80362306a36Sopenharmony_ciSmack supports some mount options: 80462306a36Sopenharmony_ci 80562306a36Sopenharmony_ci smackfsdef=label: 80662306a36Sopenharmony_ci specifies the label to give files that lack 80762306a36Sopenharmony_ci the Smack label extended attribute. 80862306a36Sopenharmony_ci 80962306a36Sopenharmony_ci smackfsroot=label: 81062306a36Sopenharmony_ci specifies the label to assign the root of the 81162306a36Sopenharmony_ci file system if it lacks the Smack extended attribute. 81262306a36Sopenharmony_ci 81362306a36Sopenharmony_ci smackfshat=label: 81462306a36Sopenharmony_ci specifies a label that must have read access to 81562306a36Sopenharmony_ci all labels set on the filesystem. Not yet enforced. 81662306a36Sopenharmony_ci 81762306a36Sopenharmony_ci smackfsfloor=label: 81862306a36Sopenharmony_ci specifies a label to which all labels set on the 81962306a36Sopenharmony_ci filesystem must have read access. Not yet enforced. 82062306a36Sopenharmony_ci 82162306a36Sopenharmony_ci smackfstransmute=label: 82262306a36Sopenharmony_ci behaves exactly like smackfsroot except that it also 82362306a36Sopenharmony_ci sets the transmute flag on the root of the mount 82462306a36Sopenharmony_ci 82562306a36Sopenharmony_ciThese mount options apply to all file system types. 82662306a36Sopenharmony_ci 82762306a36Sopenharmony_ciSmack auditing 82862306a36Sopenharmony_ci-------------- 82962306a36Sopenharmony_ci 83062306a36Sopenharmony_ciIf you want Smack auditing of security events, you need to set CONFIG_AUDIT 83162306a36Sopenharmony_ciin your kernel configuration. 83262306a36Sopenharmony_ciBy default, all denied events will be audited. You can change this behavior by 83362306a36Sopenharmony_ciwriting a single character to the /sys/fs/smackfs/logging file:: 83462306a36Sopenharmony_ci 83562306a36Sopenharmony_ci 0 : no logging 83662306a36Sopenharmony_ci 1 : log denied (default) 83762306a36Sopenharmony_ci 2 : log accepted 83862306a36Sopenharmony_ci 3 : log denied & accepted 83962306a36Sopenharmony_ci 84062306a36Sopenharmony_ciEvents are logged as 'key=value' pairs, for each event you at least will get 84162306a36Sopenharmony_cithe subject, the object, the rights requested, the action, the kernel function 84262306a36Sopenharmony_cithat triggered the event, plus other pairs depending on the type of event 84362306a36Sopenharmony_ciaudited. 84462306a36Sopenharmony_ci 84562306a36Sopenharmony_ciBringup Mode 84662306a36Sopenharmony_ci------------ 84762306a36Sopenharmony_ci 84862306a36Sopenharmony_ciBringup mode provides logging features that can make application 84962306a36Sopenharmony_ciconfiguration and system bringup easier. Configure the kernel with 85062306a36Sopenharmony_ciCONFIG_SECURITY_SMACK_BRINGUP to enable these features. When bringup 85162306a36Sopenharmony_cimode is enabled accesses that succeed due to rules marked with the "b" 85262306a36Sopenharmony_ciaccess mode will logged. When a new label is introduced for processes 85362306a36Sopenharmony_cirules can be added aggressively, marked with the "b". The logging allows 85462306a36Sopenharmony_citracking of which rules actual get used for that label. 85562306a36Sopenharmony_ci 85662306a36Sopenharmony_ciAnother feature of bringup mode is the "unconfined" option. Writing 85762306a36Sopenharmony_cia label to /sys/fs/smackfs/unconfined makes subjects with that label 85862306a36Sopenharmony_ciable to access any object, and objects with that label accessible to 85962306a36Sopenharmony_ciall subjects. Any access that is granted because a label is unconfined 86062306a36Sopenharmony_ciis logged. This feature is dangerous, as files and directories may 86162306a36Sopenharmony_cibe created in places they couldn't if the policy were being enforced. 862