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