3 "Good for you, you've decided to clean the elevator!"
4 - The Elevator, from Dark Star
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.
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
16 Smack consists of three major components:
18 - Basic utilities, which are helpful but not required
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.
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.
31 The current git repositories for Smack user space are:
33 git@gitorious.org:meego-platform-security/smackutil.git
34 git@gitorious.org:meego-platform-security/libsmack.git
36 These should make and install on most modern distributions.
37 There are three commands included in smackutil:
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
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.
46 If smackutil is installed the startup script will take care
47 of this, but it can be manually as well.
49 Add this line to /etc/fstab:
51 smackfs /smack smackfs smackfsdef=* 0 0
53 and create the /smack directory for mounting.
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
60 The extended attributes that Smack uses are:
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.
67 The Smack label of a process that execs a program file with
68 this attribute set will run with this attribute's value.
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.
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.
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.
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.
91 There are multiple ways to set a Smack label on a file:
93 # attr -S -s SMACK64 -V "value" path
94 # chsmack -a value path
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.
100 Most Smack configuration is accomplished by writing to files
101 in the smackfs filesystem. This pseudo-filesystem is usually
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.
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.
119 This contains the Smack label applied to unlabeled network
122 This interface allows modification of existing access control rules.
123 The format accepted on write is:
125 where the first string is the subject label, the second the
126 object label, the third the access to allow and the fourth the
127 access to deny. The access strings may contain only the characters
128 "rwxat-". If a rule for a given subject and object exists it will be
129 modified by enabling the permissions in the third string and disabling
130 those in the fourth string. If there is no such rule it will be
131 created using the access specified in the third and the fourth strings.
133 This interface allows a specific CIPSO header to be assigned
134 to a Smack label. The format accepted on write is:
135 "%24s%4d%4d"["%4d"]...
136 The first string is a fixed Smack label. The first number is
137 the level to use. The second number is the number of categories.
138 The following numbers are the categories.
139 "level-3-cats-5-19 3 2 5 19"
141 This interface allows a specific CIPSO header to be assigned
142 to a Smack label. The format accepted on write is:
144 The first string is a long Smack label. The first number is
145 the level to use. The second number is the number of categories.
146 The following numbers are the categories.
147 "level-3-cats-5-19 3 2 5 19"
149 This contains the CIPSO level used for Smack direct label
150 representation in network packets.
152 This contains the CIPSO domain of interpretation used in
155 This interface allows access control rules in addition to
156 the system defined rules to be specified. The format accepted
159 where the first string is the subject label, the second the
160 object label, and the third the requested access. The access
161 string may contain only the characters "rwxat-", and specifies
162 which sort of access is allowed. The "-" is a placeholder for
163 permissions that are not allowed. The string "r-x--" would
164 specify read and execute access. Labels are limited to 23
165 characters in length.
167 This interface allows access control rules in addition to
168 the system defined rules to be specified. The format accepted
171 where the first string is the subject label, the second the
172 object label, and the third the requested access. The access
173 string may contain only the characters "rwxat-", and specifies
174 which sort of access is allowed. The "-" is a placeholder for
175 permissions that are not allowed. The string "r-x--" would
176 specify read and execute access.
178 This interface allows process specific access rules to be
179 defined. These rules are only consulted if access would
180 otherwise be permitted, and are intended to provide additional
181 restrictions on the process. The format is the same as for
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
190 This contains the Smack logging state.
192 This contains the CIPSO level used for Smack mapped label
193 representation in network packets.
195 This interface allows specific internet addresses to be
196 treated as single label hosts. Packets are sent to single
197 label hosts without CIPSO headers, but only from processes
198 that have Smack write access to the host label. All packets
199 received from single label hosts are given the specified
200 label. The format accepted on write is:
201 "%d.%d.%d.%d label" or "%d.%d.%d.%d/%d label".
203 This contains the label processes must have for CAP_MAC_ADMIN
204 and CAP_MAC_OVERRIDE to be effective. If this file is empty
205 these capabilities are effective at for processes with any
206 label. The value is set by writing the desired label to the
207 file or cleared by writing "-" to the file.
209 Writing a Smack label here sets the access to '-' for all access
210 rules with that subject label.
212 You can add access rules in /etc/smack/accesses. They take the form:
214 subjectlabel objectlabel access
216 access is a combination of the letters rwxa which specify the
217 kind of access permitted a subject with subjectlabel on an
218 object with objectlabel. If there is no rule no access is allowed.
220 Look for additional programs on http://schaufler-ca.com
222 From the Smack Whitepaper:
224 The Simplified Mandatory Access Control Kernel
227 casey@schaufler-ca.com
229 Mandatory Access Control
231 Computer systems employ a variety of schemes to constrain how information is
232 shared among the people and services using the machine. Some of these schemes
233 allow the program or user to decide what other programs or users are allowed
234 access to pieces of data. These schemes are called discretionary access
235 control mechanisms because the access control is specified at the discretion
236 of the user. Other schemes do not leave the decision regarding what a user or
237 program can access up to users or programs. These schemes are called mandatory
238 access control mechanisms because you don't have a choice regarding the users
239 or programs that have access to pieces of data.
243 From the middle of the 1980's until the turn of the century Mandatory Access
244 Control (MAC) was very closely associated with the Bell & LaPadula security
245 model, a mathematical description of the United States Department of Defense
246 policy for marking paper documents. MAC in this form enjoyed a following
247 within the Capital Beltway and Scandinavian supercomputer centers but was
248 often sited as failing to address general needs.
250 Domain Type Enforcement
252 Around the turn of the century Domain Type Enforcement (DTE) became popular.
253 This scheme organizes users, programs, and data into domains that are
254 protected from each other. This scheme has been widely deployed as a component
255 of popular Linux distributions. The administrative overhead required to
256 maintain this scheme and the detailed understanding of the whole system
257 necessary to provide a secure domain mapping leads to the scheme being
258 disabled or used in limited ways in the majority of cases.
262 Smack is a Mandatory Access Control mechanism designed to provide useful MAC
263 while avoiding the pitfalls of its predecessors. The limitations of Bell &
264 LaPadula are addressed by providing a scheme whereby access can be controlled
265 according to the requirements of the system and its purpose rather than those
266 imposed by an arcane government policy. The complexity of Domain Type
267 Enforcement and avoided by defining access controls in terms of the access
268 modes already in use.
272 The jargon used to talk about Smack will be familiar to those who have dealt
273 with other MAC systems and shouldn't be too difficult for the uninitiated to
274 pick up. There are four terms that are used in a specific way and that are
275 especially important:
277 Subject: A subject is an active entity on the computer system.
278 On Smack a subject is a task, which is in turn the basic unit
281 Object: An object is a passive entity on the computer system.
282 On Smack files of all types, IPC, and tasks can be objects.
284 Access: Any attempt by a subject to put information into or get
285 information from an object is an access.
287 Label: Data that identifies the Mandatory Access Control
288 characteristics of a subject or an object.
290 These definitions are consistent with the traditional use in the security
291 community. There are also some terms from Linux that are likely to crop up:
293 Capability: A task that possesses a capability has permission to
294 violate an aspect of the system security policy, as identified by
295 the specific capability. A task that possesses one or more
296 capabilities is a privileged task, whereas a task with no
297 capabilities is an unprivileged task.
299 Privilege: A task that is allowed to violate the system security
300 policy is said to have privilege. As of this writing a task can
301 have privilege either by possessing capabilities or by having an
302 effective user of root.
306 Smack is an extension to a Linux system. It enforces additional restrictions
307 on what subjects can access which objects, based on the labels attached to
308 each of the subject and the object.
312 Smack labels are ASCII character strings, one to twenty-three characters in
313 length. Single character labels using special characters, that being anything
314 other than a letter or digit, are reserved for use by the Smack development
315 team. Smack labels are unstructured, case sensitive, and the only operation
316 ever performed on them is comparison for equality. Smack labels cannot
317 contain unprintable characters, the "/" (slash), the "\" (backslash), the "'"
318 (quote) and '"' (double-quote) characters.
319 Smack labels cannot begin with a '-'. This is reserved for special options.
321 There are some predefined labels:
323 _ Pronounced "floor", a single underscore character.
324 ^ Pronounced "hat", a single circumflex character.
325 * Pronounced "star", a single asterisk character.
326 ? Pronounced "huh", a single question mark character.
327 @ Pronounced "web", a single at sign character.
329 Every task on a Smack system is assigned a label. System tasks, such as
330 init(8) and systems daemons, are run with the floor ("_") label. User tasks
331 are assigned labels according to the specification found in the
332 /etc/smack/user configuration file.
336 Smack uses the traditional access modes of Linux. These modes are read,
337 execute, write, and occasionally append. There are a few cases where the
338 access mode may not be obvious. These include:
340 Signals: A signal is a write operation from the subject task to
342 Internet Domain IPC: Transmission of a packet is considered a
343 write operation from the source task to the destination task.
345 Smack restricts access based on the label attached to a subject and the label
346 attached to the object it is trying to access. The rules enforced are, in
349 1. Any access requested by a task labeled "*" is denied.
350 2. A read or execute access requested by a task labeled "^"
352 3. A read or execute access requested on an object labeled "_"
354 4. Any access requested on an object labeled "*" is permitted.
355 5. Any access requested by a task on an object with the same
357 6. Any access requested that is explicitly defined in the loaded
358 rule set is permitted.
359 7. Any other access is denied.
363 With the isolation provided by Smack access separation is simple. There are
364 many interesting cases where limited access by subjects to objects with
365 different labels is desired. One example is the familiar spy model of
366 sensitivity, where a scientist working on a highly classified project would be
367 able to read documents of lower classifications and anything she writes will
368 be "born" highly classified. To accommodate such schemes Smack includes a
369 mechanism for specifying rules allowing access between labels.
373 The format of an access rule is:
375 subject-label object-label access
377 Where subject-label is the Smack label of the task, object-label is the Smack
378 label of the thing being accessed, and access is a string specifying the sort
379 of access allowed. The access specification is searched for letters that
380 describe access modes:
382 a: indicates that append access should be granted.
383 r: indicates that read access should be granted.
384 w: indicates that write access should be granted.
385 x: indicates that execute access should be granted.
386 t: indicates that the rule requests transmutation.
388 Uppercase values for the specification letters are allowed as well.
389 Access mode specifications can be in any order. Examples of acceptable rules
399 Examples of unacceptable rules are:
405 Spaces are not allowed in labels. Since a subject always has access to files
406 with the same label specifying a rule for that case is pointless. Only
407 valid letters (rwxatRWXAT) and the dash ('-') character are allowed in
408 access specifications. The dash is a placeholder, so "a-r" is the same
409 as "ar". A lone dash is used to specify that no access should be allowed.
411 Applying Access Rules
413 The developers of Linux rarely define new sorts of things, usually importing
414 schemes and concepts from other systems. Most often, the other systems are
415 variants of Unix. Unix has many endearing properties, but consistency of
416 access control models is not one of them. Smack strives to treat accesses as
417 uniformly as is sensible while keeping with the spirit of the underlying
420 File system objects including files, directories, named pipes, symbolic links,
421 and devices require access permissions that closely match those used by mode
422 bit access. To open a file for reading read access is required on the file. To
423 search a directory requires execute access. Creating a file with write access
424 requires both read and write access on the containing directory. Deleting a
425 file requires read and write access to the file and to the containing
426 directory. It is possible that a user may be able to see that a file exists
427 but not any of its attributes by the circumstance of having read access to the
428 containing directory but not to the differently labeled file. This is an
429 artifact of the file name being data in the directory, not a part of the file.
431 If a directory is marked as transmuting (SMACK64TRANSMUTE=TRUE) and the
432 access rule that allows a process to create an object in that directory
433 includes 't' access the label assigned to the new object will be that
434 of the directory, not the creating process. This makes it much easier
435 for two processes with different labels to share data without granting
436 access to all of their files.
438 IPC objects, message queues, semaphore sets, and memory segments exist in flat
439 namespaces and access requests are only required to match the object in
442 Process objects reflect tasks on the system and the Smack label used to access
443 them is the same Smack label that the task would use for its own access
444 attempts. Sending a signal via the kill() system call is a write operation
445 from the signaler to the recipient. Debugging a process requires both reading
446 and writing. Creating a new task is an internal operation that results in two
447 tasks with identical Smack labels and requires no access checks.
449 Sockets are data structures attached to processes and sending a packet from
450 one process to another requires that the sender have write access to the
451 receiver. The receiver is not required to have read access to the sender.
455 The configuration file /etc/smack/accesses contains the rules to be set at
456 system startup. The contents are written to the special file /smack/load.
457 Rules can be written to /smack/load at any time and take effect immediately.
458 For any pair of subject and object labels there can be only one rule, with the
459 most recently specified overriding any earlier specification.
461 The program smackload is provided to ensure data is formatted
462 properly when written to /smack/load. This program reads lines
465 subjectlabel objectlabel mode.
469 The Smack label of a process can be read from /proc/<pid>/attr/current. A
470 process can read its own Smack label from /proc/self/attr/current. A
471 privileged process can change its own Smack label by writing to
472 /proc/self/attr/current but not the label of another process.
476 The Smack label of a filesystem object is stored as an extended attribute
477 named SMACK64 on the file. This attribute is in the security namespace. It can
478 only be changed by a process with privilege.
482 A process with CAP_MAC_OVERRIDE is privileged.
486 As mentioned before, Smack enforces access control on network protocol
487 transmissions. Every packet sent by a Smack process is tagged with its Smack
488 label. This is done by adding a CIPSO tag to the header of the IP packet. Each
489 packet received is expected to have a CIPSO tag that identifies the label and
490 if it lacks such a tag the network ambient label is assumed. Before the packet
491 is delivered a check is made to determine that a subject with the label on the
492 packet has write access to the receiving process and if that is not the case
493 the packet is dropped.
497 It is normally unnecessary to specify the CIPSO configuration. The default
498 values used by the system handle all internal cases. Smack will compose CIPSO
499 label values to match the Smack labels being used without administrative
500 intervention. Unlabeled packets that come into the system will be given the
503 Smack requires configuration in the case where packets from a system that is
504 not smack that speaks CIPSO may be encountered. Usually this will be a Trusted
505 Solaris system, but there are other, less widely deployed systems out there.
506 CIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level,
507 and a category set with each packet. The DOI is intended to identify a group
508 of systems that use compatible labeling schemes, and the DOI specified on the
509 smack system must match that of the remote system or packets will be
510 discarded. The DOI is 3 by default. The value can be read from /smack/doi and
511 can be changed by writing to /smack/doi.
513 The label and category set are mapped to a Smack label as defined in
516 A Smack/CIPSO mapping has the form:
518 smack level [category [category]*]
520 Smack does not expect the level or category sets to be related in any
521 particular way and does not assume or assign accesses based on them. Some
522 examples of mappings:
529 The ":" and "," characters are permitted in a Smack label but have no special
532 The mapping of Smack labels to CIPSO values is defined by writing to
533 /smack/cipso. Again, the format of data written to this special file
534 is highly restrictive, so the program smackcipso is provided to
535 ensure the writes are done properly. This program takes mappings
536 on the standard input and sends them to /smack/cipso properly.
538 In addition to explicit mappings Smack supports direct CIPSO mappings. One
539 CIPSO level is used to indicate that the category set passed in the packet is
540 in fact an encoding of the Smack label. The level used is 250 by default. The
541 value can be read from /smack/direct and changed by writing to /smack/direct.
545 There are two attributes that are associated with sockets. These attributes
546 can only be set by privileged tasks, but any task can read them for their own
549 SMACK64IPIN: The Smack label of the task object. A privileged
550 program that will enforce policy may set this to the star label.
552 SMACK64IPOUT: The Smack label transmitted with outgoing packets.
553 A privileged program may set this to match the label of another
554 task with which it hopes to communicate.
556 Smack Netlabel Exceptions
558 You will often find that your labeled application has to talk to the outside,
559 unlabeled world. To do this there's a special file /smack/netlabel where you can
560 add some exceptions in the form of :
564 It means that your application will have unlabeled access to @IP1 if it has
565 write access on LABEL1, and access to the subnet @IP2/MASK if it has write
568 Entries in the /smack/netlabel file are matched by longest mask first, like in
569 classless IPv4 routing.
571 A special label '@' and an option '-CIPSO' can be used there :
572 @ means Internet, any application with any label has access to it
573 -CIPSO means standard CIPSO networking
575 If you don't know what CIPSO is and don't plan to use it, you can just do :
576 echo 127.0.0.1 -CIPSO > /smack/netlabel
577 echo 0.0.0.0/0 @ > /smack/netlabel
579 If you use CIPSO on your 192.168.0.0/16 local network and need also unlabeled
580 Internet access, you can have :
581 echo 127.0.0.1 -CIPSO > /smack/netlabel
582 echo 192.168.0.0/16 -CIPSO > /smack/netlabel
583 echo 0.0.0.0/0 @ > /smack/netlabel
586 Writing Applications for Smack
588 There are three sorts of applications that will run on a Smack system. How an
589 application interacts with Smack will determine what it will have to do to
590 work properly under Smack.
592 Smack Ignorant Applications
594 By far the majority of applications have no reason whatever to care about the
595 unique properties of Smack. Since invoking a program has no impact on the
596 Smack label associated with the process the only concern likely to arise is
597 whether the process has execute access to the program.
599 Smack Relevant Applications
601 Some programs can be improved by teaching them about Smack, but do not make
602 any security decisions themselves. The utility ls(1) is one example of such a
605 Smack Enforcing Applications
607 These are special programs that not only know about Smack, but participate in
608 the enforcement of system policy. In most cases these are the programs that
609 set up user sessions. There are also network services that provide information
610 to processes running with various labels.
612 File System Interfaces
614 Smack maintains labels on file system objects using extended attributes. The
615 Smack label of a file, directory, or other file system object can be obtained
618 len = getxattr("/", "security.SMACK64", value, sizeof (value));
620 will put the Smack label of the root directory into value. A privileged
621 process can set the Smack label of a file system object with setxattr(2).
623 len = strlen("Rubble");
624 rc = setxattr("/foo", "security.SMACK64", "Rubble", len, 0);
626 will set the Smack label of /foo to "Rubble" if the program has appropriate
631 The socket attributes can be read using fgetxattr(2).
633 A privileged process can set the Smack label of outgoing packets with
636 len = strlen("Rubble");
637 rc = fsetxattr(fd, "security.SMACK64IPOUT", "Rubble", len, 0);
639 will set the Smack label "Rubble" on packets going out from the socket if the
640 program has appropriate privilege.
642 rc = fsetxattr(fd, "security.SMACK64IPIN, "*", strlen("*"), 0);
644 will set the Smack label "*" as the object label against which incoming
645 packets will be checked if the program has appropriate privilege.
649 Smack supports some mount options:
651 smackfsdef=label: specifies the label to give files that lack
652 the Smack label extended attribute.
654 smackfsroot=label: specifies the label to assign the root of the
655 file system if it lacks the Smack extended attribute.
657 smackfshat=label: specifies a label that must have read access to
658 all labels set on the filesystem. Not yet enforced.
660 smackfsfloor=label: specifies a label to which all labels set on the
661 filesystem must have read access. Not yet enforced.
663 These mount options apply to all file system types.
667 If you want Smack auditing of security events, you need to set CONFIG_AUDIT
668 in your kernel configuration.
669 By default, all denied events will be audited. You can change this behavior by
670 writing a single character to the /smack/logging file :
672 1 : log denied (default)
674 3 : log denied & accepted
676 Events are logged as 'key=value' pairs, for each event you at least will get
677 the subjet, the object, the rights requested, the action, the kernel function
678 that triggered the event, plus other pairs depending on the type of event