Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 1 | |
| 2 | |
| 3 | "Good for you, you've decided to clean the elevator!" |
| 4 | - The Elevator, from Dark Star |
| 5 | |
Masanari Iida | df5cbb2 | 2014-03-21 10:04:30 +0900 | [diff] [blame] | 6 | Smack is the Simplified Mandatory Access Control Kernel. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 7 | Smack is a kernel based implementation of mandatory access |
| 8 | control that includes simplicity in its primary design goals. |
| 9 | |
| 10 | Smack is not the only Mandatory Access Control scheme |
| 11 | available for Linux. Those new to Mandatory Access Control |
| 12 | are encouraged to compare Smack with the other mechanisms |
| 13 | available to determine which is best suited to the problem |
| 14 | at hand. |
| 15 | |
| 16 | Smack consists of three major components: |
| 17 | - The kernel |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 18 | - Basic utilities, which are helpful but not required |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 19 | - Configuration data |
| 20 | |
| 21 | The kernel component of Smack is implemented as a Linux |
| 22 | Security Modules (LSM) module. It requires netlabel and |
| 23 | works best with file systems that support extended attributes, |
| 24 | although xattr support is not strictly required. |
| 25 | It is safe to run a Smack kernel under a "vanilla" distribution. |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 26 | |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 27 | Smack kernels use the CIPSO IP option. Some network |
| 28 | configurations are intolerant of IP options and can impede |
| 29 | access to systems that use them as Smack does. |
| 30 | |
Daniel Wagner | 78a0d8f | 2012-09-24 14:21:29 +0200 | [diff] [blame] | 31 | The current git repository for Smack user space is: |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 32 | |
Daniel Wagner | 78a0d8f | 2012-09-24 14:21:29 +0200 | [diff] [blame] | 33 | git://github.com/smack-team/smack.git |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 34 | |
Daniel Wagner | 78a0d8f | 2012-09-24 14:21:29 +0200 | [diff] [blame] | 35 | This should make and install on most modern distributions. |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 36 | There are five commands included in smackutil: |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 37 | |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 38 | chsmack - display or set Smack extended attribute values |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 39 | smackctl - load the Smack access rules |
| 40 | smackaccess - report if a process with one label has access |
| 41 | to an object with another |
| 42 | |
| 43 | These two commands are obsolete with the introduction of |
| 44 | the smackfs/load2 and smackfs/cipso2 interfaces. |
| 45 | |
| 46 | smackload - properly formats data for writing to smackfs/load |
| 47 | smackcipso - properly formats data for writing to smackfs/cipso |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 48 | |
| 49 | In keeping with the intent of Smack, configuration data is |
| 50 | minimal and not strictly required. The most important |
| 51 | configuration step is mounting the smackfs pseudo filesystem. |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 52 | If smackutil is installed the startup script will take care |
| 53 | of this, but it can be manually as well. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 54 | |
| 55 | Add this line to /etc/fstab: |
| 56 | |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 57 | smackfs /sys/fs/smackfs smackfs defaults 0 0 |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 58 | |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 59 | The /sys/fs/smackfs directory is created by the kernel. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 60 | |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 61 | Smack uses extended attributes (xattrs) to store labels on filesystem |
| 62 | objects. The attributes are stored in the extended attribute security |
| 63 | name space. A process must have CAP_MAC_ADMIN to change any of these |
| 64 | attributes. |
| 65 | |
| 66 | The extended attributes that Smack uses are: |
| 67 | |
| 68 | SMACK64 |
| 69 | Used to make access control decisions. In almost all cases |
| 70 | the label given to a new filesystem object will be the label |
| 71 | of the process that created it. |
| 72 | SMACK64EXEC |
| 73 | The Smack label of a process that execs a program file with |
| 74 | this attribute set will run with this attribute's value. |
| 75 | SMACK64MMAP |
| 76 | Don't allow the file to be mmapped by a process whose Smack |
| 77 | label does not allow all of the access permitted to a process |
| 78 | with the label contained in this attribute. This is a very |
| 79 | specific use case for shared libraries. |
| 80 | SMACK64TRANSMUTE |
| 81 | Can only have the value "TRUE". If this attribute is present |
| 82 | on a directory when an object is created in the directory and |
| 83 | the Smack rule (more below) that permitted the write access |
| 84 | to the directory includes the transmute ("t") mode the object |
| 85 | gets the label of the directory instead of the label of the |
| 86 | creating process. If the object being created is a directory |
| 87 | the SMACK64TRANSMUTE attribute is set as well. |
| 88 | SMACK64IPIN |
| 89 | This attribute is only available on file descriptors for sockets. |
| 90 | Use the Smack label in this attribute for access control |
| 91 | decisions on packets being delivered to this socket. |
| 92 | SMACK64IPOUT |
| 93 | This attribute is only available on file descriptors for sockets. |
| 94 | Use the Smack label in this attribute for access control |
| 95 | decisions on packets coming from this socket. |
| 96 | |
| 97 | There are multiple ways to set a Smack label on a file: |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 98 | |
| 99 | # attr -S -s SMACK64 -V "value" path |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 100 | # chsmack -a value path |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 101 | |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 102 | A process can see the Smack label it is running with by |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 103 | reading /proc/self/attr/current. A process with CAP_MAC_ADMIN |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 104 | can set the process Smack by writing there. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 105 | |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 106 | Most Smack configuration is accomplished by writing to files |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 107 | in the smackfs filesystem. This pseudo-filesystem is mounted |
| 108 | on /sys/fs/smackfs. |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 109 | |
| 110 | access |
| 111 | This interface reports whether a subject with the specified |
| 112 | Smack label has a particular access to an object with a |
| 113 | specified Smack label. Write a fixed format access rule to |
| 114 | this file. The next read will indicate whether the access |
| 115 | would be permitted. The text will be either "1" indicating |
| 116 | access, or "0" indicating denial. |
| 117 | access2 |
| 118 | This interface reports whether a subject with the specified |
| 119 | Smack label has a particular access to an object with a |
| 120 | specified Smack label. Write a long format access rule to |
| 121 | this file. The next read will indicate whether the access |
| 122 | would be permitted. The text will be either "1" indicating |
| 123 | access, or "0" indicating denial. |
| 124 | ambient |
| 125 | This contains the Smack label applied to unlabeled network |
| 126 | packets. |
Rafal Krypa | e05b6f9 | 2013-01-10 19:42:00 +0100 | [diff] [blame] | 127 | change-rule |
| 128 | This interface allows modification of existing access control rules. |
| 129 | The format accepted on write is: |
| 130 | "%s %s %s %s" |
| 131 | where the first string is the subject label, the second the |
| 132 | object label, the third the access to allow and the fourth the |
| 133 | access to deny. The access strings may contain only the characters |
| 134 | "rwxat-". If a rule for a given subject and object exists it will be |
| 135 | modified by enabling the permissions in the third string and disabling |
| 136 | those in the fourth string. If there is no such rule it will be |
| 137 | created using the access specified in the third and the fourth strings. |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 138 | cipso |
| 139 | This interface allows a specific CIPSO header to be assigned |
| 140 | to a Smack label. The format accepted on write is: |
| 141 | "%24s%4d%4d"["%4d"]... |
| 142 | The first string is a fixed Smack label. The first number is |
| 143 | the level to use. The second number is the number of categories. |
| 144 | The following numbers are the categories. |
| 145 | "level-3-cats-5-19 3 2 5 19" |
| 146 | cipso2 |
| 147 | This interface allows a specific CIPSO header to be assigned |
| 148 | to a Smack label. The format accepted on write is: |
| 149 | "%s%4d%4d"["%4d"]... |
| 150 | The first string is a long Smack label. The first number is |
| 151 | the level to use. The second number is the number of categories. |
| 152 | The following numbers are the categories. |
| 153 | "level-3-cats-5-19 3 2 5 19" |
| 154 | direct |
| 155 | This contains the CIPSO level used for Smack direct label |
| 156 | representation in network packets. |
| 157 | doi |
| 158 | This contains the CIPSO domain of interpretation used in |
| 159 | network packets. |
| 160 | load |
| 161 | This interface allows access control rules in addition to |
| 162 | the system defined rules to be specified. The format accepted |
| 163 | on write is: |
| 164 | "%24s%24s%5s" |
| 165 | where the first string is the subject label, the second the |
| 166 | object label, and the third the requested access. The access |
| 167 | string may contain only the characters "rwxat-", and specifies |
| 168 | which sort of access is allowed. The "-" is a placeholder for |
| 169 | permissions that are not allowed. The string "r-x--" would |
| 170 | specify read and execute access. Labels are limited to 23 |
| 171 | characters in length. |
| 172 | load2 |
| 173 | This interface allows access control rules in addition to |
| 174 | the system defined rules to be specified. The format accepted |
| 175 | on write is: |
| 176 | "%s %s %s" |
| 177 | where the first string is the subject label, the second the |
| 178 | object label, and the third the requested access. The access |
| 179 | string may contain only the characters "rwxat-", and specifies |
| 180 | which sort of access is allowed. The "-" is a placeholder for |
| 181 | permissions that are not allowed. The string "r-x--" would |
| 182 | specify read and execute access. |
| 183 | load-self |
| 184 | This interface allows process specific access rules to be |
| 185 | defined. These rules are only consulted if access would |
| 186 | otherwise be permitted, and are intended to provide additional |
| 187 | restrictions on the process. The format is the same as for |
| 188 | the load interface. |
| 189 | load-self2 |
| 190 | This interface allows process specific access rules to be |
| 191 | defined. These rules are only consulted if access would |
| 192 | otherwise be permitted, and are intended to provide additional |
| 193 | restrictions on the process. The format is the same as for |
| 194 | the load2 interface. |
| 195 | logging |
| 196 | This contains the Smack logging state. |
| 197 | mapped |
| 198 | This contains the CIPSO level used for Smack mapped label |
| 199 | representation in network packets. |
| 200 | netlabel |
| 201 | This interface allows specific internet addresses to be |
| 202 | treated as single label hosts. Packets are sent to single |
| 203 | label hosts without CIPSO headers, but only from processes |
| 204 | that have Smack write access to the host label. All packets |
| 205 | received from single label hosts are given the specified |
| 206 | label. The format accepted on write is: |
| 207 | "%d.%d.%d.%d label" or "%d.%d.%d.%d/%d label". |
| 208 | onlycap |
| 209 | This contains the label processes must have for CAP_MAC_ADMIN |
| 210 | and CAP_MAC_OVERRIDE to be effective. If this file is empty |
| 211 | these capabilities are effective at for processes with any |
| 212 | label. The value is set by writing the desired label to the |
| 213 | file or cleared by writing "-" to the file. |
Lukasz Pawelczyk | 6686781 | 2014-03-11 17:07:06 +0100 | [diff] [blame] | 214 | ptrace |
| 215 | This is used to define the current ptrace policy |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 216 | 0 - default: this is the policy that relies on Smack access rules. |
Lukasz Pawelczyk | 6686781 | 2014-03-11 17:07:06 +0100 | [diff] [blame] | 217 | For the PTRACE_READ a subject needs to have a read access on |
| 218 | object. For the PTRACE_ATTACH a read-write access is required. |
| 219 | 1 - exact: this is the policy that limits PTRACE_ATTACH. Attach is |
| 220 | only allowed when subject's and object's labels are equal. |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 221 | PTRACE_READ is not affected. Can be overridden with CAP_SYS_PTRACE. |
Lukasz Pawelczyk | 6686781 | 2014-03-11 17:07:06 +0100 | [diff] [blame] | 222 | 2 - draconian: this policy behaves like the 'exact' above with an |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 223 | exception that it can't be overridden with CAP_SYS_PTRACE. |
Rafal Krypa | 449543b | 2012-07-11 17:49:30 +0200 | [diff] [blame] | 224 | revoke-subject |
| 225 | Writing a Smack label here sets the access to '-' for all access |
| 226 | rules with that subject label. |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 227 | unconfined |
| 228 | If the kernel is configured with CONFIG_SECURITY_SMACK_BRINGUP |
| 229 | a process with CAP_MAC_ADMIN can write a label into this interface. |
| 230 | Thereafter, accesses that involve that label will be logged and |
| 231 | the access permitted if it wouldn't be otherwise. Note that this |
| 232 | is dangerous and can ruin the proper labeling of your system. |
| 233 | It should never be used in production. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 234 | |
| 235 | You can add access rules in /etc/smack/accesses. They take the form: |
| 236 | |
| 237 | subjectlabel objectlabel access |
| 238 | |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 239 | access is a combination of the letters rwxatb which specify the |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 240 | kind of access permitted a subject with subjectlabel on an |
| 241 | object with objectlabel. If there is no rule no access is allowed. |
| 242 | |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 243 | Look for additional programs on http://schaufler-ca.com |
| 244 | |
| 245 | From the Smack Whitepaper: |
| 246 | |
| 247 | The Simplified Mandatory Access Control Kernel |
| 248 | |
| 249 | Casey Schaufler |
| 250 | casey@schaufler-ca.com |
| 251 | |
| 252 | Mandatory Access Control |
| 253 | |
| 254 | Computer systems employ a variety of schemes to constrain how information is |
| 255 | shared among the people and services using the machine. Some of these schemes |
| 256 | allow the program or user to decide what other programs or users are allowed |
| 257 | access to pieces of data. These schemes are called discretionary access |
| 258 | control mechanisms because the access control is specified at the discretion |
| 259 | of the user. Other schemes do not leave the decision regarding what a user or |
| 260 | program can access up to users or programs. These schemes are called mandatory |
| 261 | access control mechanisms because you don't have a choice regarding the users |
| 262 | or programs that have access to pieces of data. |
| 263 | |
| 264 | Bell & LaPadula |
| 265 | |
| 266 | From the middle of the 1980's until the turn of the century Mandatory Access |
| 267 | Control (MAC) was very closely associated with the Bell & LaPadula security |
| 268 | model, a mathematical description of the United States Department of Defense |
| 269 | policy for marking paper documents. MAC in this form enjoyed a following |
| 270 | within the Capital Beltway and Scandinavian supercomputer centers but was |
| 271 | often sited as failing to address general needs. |
| 272 | |
| 273 | Domain Type Enforcement |
| 274 | |
| 275 | Around the turn of the century Domain Type Enforcement (DTE) became popular. |
| 276 | This scheme organizes users, programs, and data into domains that are |
| 277 | protected from each other. This scheme has been widely deployed as a component |
| 278 | of popular Linux distributions. The administrative overhead required to |
| 279 | maintain this scheme and the detailed understanding of the whole system |
| 280 | necessary to provide a secure domain mapping leads to the scheme being |
| 281 | disabled or used in limited ways in the majority of cases. |
| 282 | |
| 283 | Smack |
| 284 | |
| 285 | Smack is a Mandatory Access Control mechanism designed to provide useful MAC |
| 286 | while avoiding the pitfalls of its predecessors. The limitations of Bell & |
| 287 | LaPadula are addressed by providing a scheme whereby access can be controlled |
| 288 | according to the requirements of the system and its purpose rather than those |
| 289 | imposed by an arcane government policy. The complexity of Domain Type |
| 290 | Enforcement and avoided by defining access controls in terms of the access |
| 291 | modes already in use. |
| 292 | |
| 293 | Smack Terminology |
| 294 | |
| 295 | The jargon used to talk about Smack will be familiar to those who have dealt |
| 296 | with other MAC systems and shouldn't be too difficult for the uninitiated to |
| 297 | pick up. There are four terms that are used in a specific way and that are |
| 298 | especially important: |
| 299 | |
| 300 | Subject: A subject is an active entity on the computer system. |
| 301 | On Smack a subject is a task, which is in turn the basic unit |
| 302 | of execution. |
| 303 | |
| 304 | Object: An object is a passive entity on the computer system. |
| 305 | On Smack files of all types, IPC, and tasks can be objects. |
| 306 | |
| 307 | Access: Any attempt by a subject to put information into or get |
| 308 | information from an object is an access. |
| 309 | |
| 310 | Label: Data that identifies the Mandatory Access Control |
| 311 | characteristics of a subject or an object. |
| 312 | |
| 313 | These definitions are consistent with the traditional use in the security |
| 314 | community. There are also some terms from Linux that are likely to crop up: |
| 315 | |
| 316 | Capability: A task that possesses a capability has permission to |
| 317 | violate an aspect of the system security policy, as identified by |
| 318 | the specific capability. A task that possesses one or more |
| 319 | capabilities is a privileged task, whereas a task with no |
| 320 | capabilities is an unprivileged task. |
| 321 | |
| 322 | Privilege: A task that is allowed to violate the system security |
| 323 | policy is said to have privilege. As of this writing a task can |
| 324 | have privilege either by possessing capabilities or by having an |
| 325 | effective user of root. |
| 326 | |
| 327 | Smack Basics |
| 328 | |
| 329 | Smack is an extension to a Linux system. It enforces additional restrictions |
| 330 | on what subjects can access which objects, based on the labels attached to |
| 331 | each of the subject and the object. |
| 332 | |
| 333 | Labels |
| 334 | |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 335 | Smack labels are ASCII character strings. They can be up to 255 characters |
| 336 | long, but keeping them to twenty-three characters is recommended. |
| 337 | Single character labels using special characters, that being anything |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 338 | other than a letter or digit, are reserved for use by the Smack development |
| 339 | team. Smack labels are unstructured, case sensitive, and the only operation |
| 340 | ever performed on them is comparison for equality. Smack labels cannot |
Etienne Basset | ecfcc53 | 2009-04-08 20:40:06 +0200 | [diff] [blame] | 341 | contain unprintable characters, the "/" (slash), the "\" (backslash), the "'" |
| 342 | (quote) and '"' (double-quote) characters. |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 343 | Smack labels cannot begin with a '-'. This is reserved for special options. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 344 | |
| 345 | There are some predefined labels: |
| 346 | |
Etienne Basset | 4303154 | 2009-03-27 17:11:01 -0400 | [diff] [blame] | 347 | _ Pronounced "floor", a single underscore character. |
| 348 | ^ Pronounced "hat", a single circumflex character. |
| 349 | * Pronounced "star", a single asterisk character. |
| 350 | ? Pronounced "huh", a single question mark character. |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 351 | @ Pronounced "web", a single at sign character. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 352 | |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 353 | Every task on a Smack system is assigned a label. The Smack label |
| 354 | of a process will usually be assigned by the system initialization |
| 355 | mechanism. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 356 | |
| 357 | Access Rules |
| 358 | |
| 359 | Smack uses the traditional access modes of Linux. These modes are read, |
| 360 | execute, write, and occasionally append. There are a few cases where the |
| 361 | access mode may not be obvious. These include: |
| 362 | |
| 363 | Signals: A signal is a write operation from the subject task to |
| 364 | the object task. |
| 365 | Internet Domain IPC: Transmission of a packet is considered a |
| 366 | write operation from the source task to the destination task. |
| 367 | |
| 368 | Smack restricts access based on the label attached to a subject and the label |
| 369 | attached to the object it is trying to access. The rules enforced are, in |
| 370 | order: |
| 371 | |
| 372 | 1. Any access requested by a task labeled "*" is denied. |
| 373 | 2. A read or execute access requested by a task labeled "^" |
| 374 | is permitted. |
| 375 | 3. A read or execute access requested on an object labeled "_" |
| 376 | is permitted. |
| 377 | 4. Any access requested on an object labeled "*" is permitted. |
| 378 | 5. Any access requested by a task on an object with the same |
| 379 | label is permitted. |
| 380 | 6. Any access requested that is explicitly defined in the loaded |
| 381 | rule set is permitted. |
| 382 | 7. Any other access is denied. |
| 383 | |
| 384 | Smack Access Rules |
| 385 | |
| 386 | With the isolation provided by Smack access separation is simple. There are |
| 387 | many interesting cases where limited access by subjects to objects with |
| 388 | different labels is desired. One example is the familiar spy model of |
| 389 | sensitivity, where a scientist working on a highly classified project would be |
| 390 | able to read documents of lower classifications and anything she writes will |
| 391 | be "born" highly classified. To accommodate such schemes Smack includes a |
| 392 | mechanism for specifying rules allowing access between labels. |
| 393 | |
| 394 | Access Rule Format |
| 395 | |
| 396 | The format of an access rule is: |
| 397 | |
| 398 | subject-label object-label access |
| 399 | |
| 400 | Where subject-label is the Smack label of the task, object-label is the Smack |
| 401 | label of the thing being accessed, and access is a string specifying the sort |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 402 | of access allowed. The access specification is searched for letters that |
| 403 | describe access modes: |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 404 | |
| 405 | a: indicates that append access should be granted. |
| 406 | r: indicates that read access should be granted. |
| 407 | w: indicates that write access should be granted. |
| 408 | x: indicates that execute access should be granted. |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 409 | t: indicates that the rule requests transmutation. |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 410 | b: indicates that the rule should be reported for bring-up. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 411 | |
| 412 | Uppercase values for the specification letters are allowed as well. |
| 413 | Access mode specifications can be in any order. Examples of acceptable rules |
| 414 | are: |
| 415 | |
| 416 | TopSecret Secret rx |
| 417 | Secret Unclass R |
| 418 | Manager Game x |
| 419 | User HR w |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 420 | Snap Crackle rwxatb |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 421 | New Old rRrRr |
| 422 | Closed Off - |
| 423 | |
| 424 | Examples of unacceptable rules are: |
| 425 | |
| 426 | Top Secret Secret rx |
| 427 | Ace Ace r |
| 428 | Odd spells waxbeans |
| 429 | |
| 430 | Spaces are not allowed in labels. Since a subject always has access to files |
| 431 | with the same label specifying a rule for that case is pointless. Only |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 432 | valid letters (rwxatbRWXATB) and the dash ('-') character are allowed in |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 433 | access specifications. The dash is a placeholder, so "a-r" is the same |
| 434 | as "ar". A lone dash is used to specify that no access should be allowed. |
| 435 | |
| 436 | Applying Access Rules |
| 437 | |
| 438 | The developers of Linux rarely define new sorts of things, usually importing |
| 439 | schemes and concepts from other systems. Most often, the other systems are |
| 440 | variants of Unix. Unix has many endearing properties, but consistency of |
| 441 | access control models is not one of them. Smack strives to treat accesses as |
| 442 | uniformly as is sensible while keeping with the spirit of the underlying |
| 443 | mechanism. |
| 444 | |
| 445 | File system objects including files, directories, named pipes, symbolic links, |
| 446 | and devices require access permissions that closely match those used by mode |
| 447 | bit access. To open a file for reading read access is required on the file. To |
| 448 | search a directory requires execute access. Creating a file with write access |
| 449 | requires both read and write access on the containing directory. Deleting a |
| 450 | file requires read and write access to the file and to the containing |
| 451 | directory. It is possible that a user may be able to see that a file exists |
| 452 | but not any of its attributes by the circumstance of having read access to the |
| 453 | containing directory but not to the differently labeled file. This is an |
| 454 | artifact of the file name being data in the directory, not a part of the file. |
| 455 | |
Casey Schaufler | f7112e6 | 2012-05-06 15:22:02 -0700 | [diff] [blame] | 456 | If a directory is marked as transmuting (SMACK64TRANSMUTE=TRUE) and the |
| 457 | access rule that allows a process to create an object in that directory |
| 458 | includes 't' access the label assigned to the new object will be that |
| 459 | of the directory, not the creating process. This makes it much easier |
| 460 | for two processes with different labels to share data without granting |
| 461 | access to all of their files. |
| 462 | |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 463 | IPC objects, message queues, semaphore sets, and memory segments exist in flat |
| 464 | namespaces and access requests are only required to match the object in |
| 465 | question. |
| 466 | |
| 467 | Process objects reflect tasks on the system and the Smack label used to access |
| 468 | them is the same Smack label that the task would use for its own access |
| 469 | attempts. Sending a signal via the kill() system call is a write operation |
| 470 | from the signaler to the recipient. Debugging a process requires both reading |
| 471 | and writing. Creating a new task is an internal operation that results in two |
| 472 | tasks with identical Smack labels and requires no access checks. |
| 473 | |
| 474 | Sockets are data structures attached to processes and sending a packet from |
| 475 | one process to another requires that the sender have write access to the |
| 476 | receiver. The receiver is not required to have read access to the sender. |
| 477 | |
| 478 | Setting Access Rules |
| 479 | |
| 480 | The configuration file /etc/smack/accesses contains the rules to be set at |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 481 | system startup. The contents are written to the special file |
| 482 | /sys/fs/smackfs/load2. Rules can be added at any time and take effect |
| 483 | immediately. For any pair of subject and object labels there can be only |
| 484 | one rule, with the most recently specified overriding any earlier |
| 485 | specification. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 486 | |
| 487 | Task Attribute |
| 488 | |
| 489 | The Smack label of a process can be read from /proc/<pid>/attr/current. A |
| 490 | process can read its own Smack label from /proc/self/attr/current. A |
| 491 | privileged process can change its own Smack label by writing to |
| 492 | /proc/self/attr/current but not the label of another process. |
| 493 | |
| 494 | File Attribute |
| 495 | |
| 496 | The Smack label of a filesystem object is stored as an extended attribute |
| 497 | named SMACK64 on the file. This attribute is in the security namespace. It can |
| 498 | only be changed by a process with privilege. |
| 499 | |
| 500 | Privilege |
| 501 | |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 502 | A process with CAP_MAC_OVERRIDE or CAP_MAC_ADMIN is privileged. |
| 503 | CAP_MAC_OVERRIDE allows the process access to objects it would |
| 504 | be denied otherwise. CAP_MAC_ADMIN allows a process to change |
| 505 | Smack data, including rules and attributes. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 506 | |
| 507 | Smack Networking |
| 508 | |
| 509 | As mentioned before, Smack enforces access control on network protocol |
| 510 | transmissions. Every packet sent by a Smack process is tagged with its Smack |
| 511 | label. This is done by adding a CIPSO tag to the header of the IP packet. Each |
| 512 | packet received is expected to have a CIPSO tag that identifies the label and |
| 513 | if it lacks such a tag the network ambient label is assumed. Before the packet |
| 514 | is delivered a check is made to determine that a subject with the label on the |
| 515 | packet has write access to the receiving process and if that is not the case |
| 516 | the packet is dropped. |
| 517 | |
| 518 | CIPSO Configuration |
| 519 | |
| 520 | It is normally unnecessary to specify the CIPSO configuration. The default |
| 521 | values used by the system handle all internal cases. Smack will compose CIPSO |
| 522 | label values to match the Smack labels being used without administrative |
| 523 | intervention. Unlabeled packets that come into the system will be given the |
| 524 | ambient label. |
| 525 | |
| 526 | Smack requires configuration in the case where packets from a system that is |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 527 | not Smack that speaks CIPSO may be encountered. Usually this will be a Trusted |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 528 | Solaris system, but there are other, less widely deployed systems out there. |
| 529 | CIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level, |
| 530 | and a category set with each packet. The DOI is intended to identify a group |
| 531 | of systems that use compatible labeling schemes, and the DOI specified on the |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 532 | Smack system must match that of the remote system or packets will be |
| 533 | discarded. The DOI is 3 by default. The value can be read from |
| 534 | /sys/fs/smackfs/doi and can be changed by writing to /sys/fs/smackfs/doi. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 535 | |
| 536 | The label and category set are mapped to a Smack label as defined in |
| 537 | /etc/smack/cipso. |
| 538 | |
| 539 | A Smack/CIPSO mapping has the form: |
| 540 | |
| 541 | smack level [category [category]*] |
| 542 | |
| 543 | Smack does not expect the level or category sets to be related in any |
| 544 | particular way and does not assume or assign accesses based on them. Some |
| 545 | examples of mappings: |
| 546 | |
| 547 | TopSecret 7 |
| 548 | TS:A,B 7 1 2 |
| 549 | SecBDE 5 2 4 6 |
| 550 | RAFTERS 7 12 26 |
| 551 | |
| 552 | The ":" and "," characters are permitted in a Smack label but have no special |
| 553 | meaning. |
| 554 | |
| 555 | The mapping of Smack labels to CIPSO values is defined by writing to |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 556 | /sys/fs/smackfs/cipso2. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 557 | |
| 558 | In addition to explicit mappings Smack supports direct CIPSO mappings. One |
| 559 | CIPSO level is used to indicate that the category set passed in the packet is |
| 560 | in fact an encoding of the Smack label. The level used is 250 by default. The |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 561 | value can be read from /sys/fs/smackfs/direct and changed by writing to |
| 562 | /sys/fs/smackfs/direct. |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 563 | |
| 564 | Socket Attributes |
| 565 | |
| 566 | There are two attributes that are associated with sockets. These attributes |
| 567 | can only be set by privileged tasks, but any task can read them for their own |
| 568 | sockets. |
| 569 | |
| 570 | SMACK64IPIN: The Smack label of the task object. A privileged |
| 571 | program that will enforce policy may set this to the star label. |
| 572 | |
| 573 | SMACK64IPOUT: The Smack label transmitted with outgoing packets. |
| 574 | A privileged program may set this to match the label of another |
| 575 | task with which it hopes to communicate. |
| 576 | |
Etienne Basset | 4303154 | 2009-03-27 17:11:01 -0400 | [diff] [blame] | 577 | Smack Netlabel Exceptions |
| 578 | |
| 579 | You will often find that your labeled application has to talk to the outside, |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 580 | unlabeled world. To do this there's a special file /sys/fs/smackfs/netlabel |
| 581 | where you can add some exceptions in the form of : |
Etienne Basset | 4303154 | 2009-03-27 17:11:01 -0400 | [diff] [blame] | 582 | @IP1 LABEL1 or |
| 583 | @IP2/MASK LABEL2 |
| 584 | |
| 585 | It means that your application will have unlabeled access to @IP1 if it has |
| 586 | write access on LABEL1, and access to the subnet @IP2/MASK if it has write |
| 587 | access on LABEL2. |
| 588 | |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 589 | Entries in the /sys/fs/smackfs/netlabel file are matched by longest mask |
| 590 | first, like in classless IPv4 routing. |
Etienne Basset | 4303154 | 2009-03-27 17:11:01 -0400 | [diff] [blame] | 591 | |
| 592 | A special label '@' and an option '-CIPSO' can be used there : |
| 593 | @ means Internet, any application with any label has access to it |
| 594 | -CIPSO means standard CIPSO networking |
| 595 | |
| 596 | If you don't know what CIPSO is and don't plan to use it, you can just do : |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 597 | echo 127.0.0.1 -CIPSO > /sys/fs/smackfs/netlabel |
| 598 | echo 0.0.0.0/0 @ > /sys/fs/smackfs/netlabel |
Etienne Basset | 4303154 | 2009-03-27 17:11:01 -0400 | [diff] [blame] | 599 | |
| 600 | If you use CIPSO on your 192.168.0.0/16 local network and need also unlabeled |
| 601 | Internet access, you can have : |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 602 | echo 127.0.0.1 -CIPSO > /sys/fs/smackfs/netlabel |
| 603 | echo 192.168.0.0/16 -CIPSO > /sys/fs/smackfs/netlabel |
| 604 | echo 0.0.0.0/0 @ > /sys/fs/smackfs/netlabel |
Etienne Basset | 4303154 | 2009-03-27 17:11:01 -0400 | [diff] [blame] | 605 | |
| 606 | |
Casey Schaufler | e114e47 | 2008-02-04 22:29:50 -0800 | [diff] [blame] | 607 | Writing Applications for Smack |
| 608 | |
| 609 | There are three sorts of applications that will run on a Smack system. How an |
| 610 | application interacts with Smack will determine what it will have to do to |
| 611 | work properly under Smack. |
| 612 | |
| 613 | Smack Ignorant Applications |
| 614 | |
| 615 | By far the majority of applications have no reason whatever to care about the |
| 616 | unique properties of Smack. Since invoking a program has no impact on the |
| 617 | Smack label associated with the process the only concern likely to arise is |
| 618 | whether the process has execute access to the program. |
| 619 | |
| 620 | Smack Relevant Applications |
| 621 | |
| 622 | Some programs can be improved by teaching them about Smack, but do not make |
| 623 | any security decisions themselves. The utility ls(1) is one example of such a |
| 624 | program. |
| 625 | |
| 626 | Smack Enforcing Applications |
| 627 | |
| 628 | These are special programs that not only know about Smack, but participate in |
| 629 | the enforcement of system policy. In most cases these are the programs that |
| 630 | set up user sessions. There are also network services that provide information |
| 631 | to processes running with various labels. |
| 632 | |
| 633 | File System Interfaces |
| 634 | |
| 635 | Smack maintains labels on file system objects using extended attributes. The |
| 636 | Smack label of a file, directory, or other file system object can be obtained |
| 637 | using getxattr(2). |
| 638 | |
| 639 | len = getxattr("/", "security.SMACK64", value, sizeof (value)); |
| 640 | |
| 641 | will put the Smack label of the root directory into value. A privileged |
| 642 | process can set the Smack label of a file system object with setxattr(2). |
| 643 | |
| 644 | len = strlen("Rubble"); |
| 645 | rc = setxattr("/foo", "security.SMACK64", "Rubble", len, 0); |
| 646 | |
| 647 | will set the Smack label of /foo to "Rubble" if the program has appropriate |
| 648 | privilege. |
| 649 | |
| 650 | Socket Interfaces |
| 651 | |
| 652 | The socket attributes can be read using fgetxattr(2). |
| 653 | |
| 654 | A privileged process can set the Smack label of outgoing packets with |
| 655 | fsetxattr(2). |
| 656 | |
| 657 | len = strlen("Rubble"); |
| 658 | rc = fsetxattr(fd, "security.SMACK64IPOUT", "Rubble", len, 0); |
| 659 | |
| 660 | will set the Smack label "Rubble" on packets going out from the socket if the |
| 661 | program has appropriate privilege. |
| 662 | |
| 663 | rc = fsetxattr(fd, "security.SMACK64IPIN, "*", strlen("*"), 0); |
| 664 | |
| 665 | will set the Smack label "*" as the object label against which incoming |
| 666 | packets will be checked if the program has appropriate privilege. |
| 667 | |
| 668 | Administration |
| 669 | |
| 670 | Smack supports some mount options: |
| 671 | |
| 672 | smackfsdef=label: specifies the label to give files that lack |
| 673 | the Smack label extended attribute. |
| 674 | |
| 675 | smackfsroot=label: specifies the label to assign the root of the |
| 676 | file system if it lacks the Smack extended attribute. |
| 677 | |
| 678 | smackfshat=label: specifies a label that must have read access to |
| 679 | all labels set on the filesystem. Not yet enforced. |
| 680 | |
| 681 | smackfsfloor=label: specifies a label to which all labels set on the |
| 682 | filesystem must have read access. Not yet enforced. |
| 683 | |
| 684 | These mount options apply to all file system types. |
| 685 | |
Etienne Basset | ecfcc53 | 2009-04-08 20:40:06 +0200 | [diff] [blame] | 686 | Smack auditing |
| 687 | |
| 688 | If you want Smack auditing of security events, you need to set CONFIG_AUDIT |
| 689 | in your kernel configuration. |
| 690 | By default, all denied events will be audited. You can change this behavior by |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 691 | writing a single character to the /sys/fs/smackfs/logging file : |
Etienne Basset | ecfcc53 | 2009-04-08 20:40:06 +0200 | [diff] [blame] | 692 | 0 : no logging |
| 693 | 1 : log denied (default) |
| 694 | 2 : log accepted |
| 695 | 3 : log denied & accepted |
| 696 | |
| 697 | Events are logged as 'key=value' pairs, for each event you at least will get |
Masanari Iida | 40e4712 | 2012-03-04 23:16:11 +0900 | [diff] [blame] | 698 | the subject, the object, the rights requested, the action, the kernel function |
Etienne Basset | ecfcc53 | 2009-04-08 20:40:06 +0200 | [diff] [blame] | 699 | that triggered the event, plus other pairs depending on the type of event |
| 700 | audited. |
Casey Schaufler | 18779b7 | 2015-03-31 09:49:40 -0700 | [diff] [blame] | 701 | |
| 702 | Bringup Mode |
| 703 | |
| 704 | Bringup mode provides logging features that can make application |
| 705 | configuration and system bringup easier. Configure the kernel with |
| 706 | CONFIG_SECURITY_SMACK_BRINGUP to enable these features. When bringup |
| 707 | mode is enabled accesses that succeed due to rules marked with the "b" |
| 708 | access mode will logged. When a new label is introduced for processes |
| 709 | rules can be added aggressively, marked with the "b". The logging allows |
| 710 | tracking of which rules actual get used for that label. |
| 711 | |
| 712 | Another feature of bringup mode is the "unconfined" option. Writing |
| 713 | a label to /sys/fs/smackfs/unconfined makes subjects with that label |
| 714 | able to access any object, and objects with that label accessible to |
| 715 | all subjects. Any access that is granted because a label is unconfined |
| 716 | is logged. This feature is dangerous, as files and directories may |
| 717 | be created in places they couldn't if the policy were being enforced. |