0001 =====
0002 Smack
0003 =====
0004
0005
0006 "Good for you, you've decided to clean the elevator!"
0007 - The Elevator, from Dark Star
0008
0009 Smack is the Simplified Mandatory Access Control Kernel.
0010 Smack is a kernel based implementation of mandatory access
0011 control that includes simplicity in its primary design goals.
0012
0013 Smack is not the only Mandatory Access Control scheme
0014 available for Linux. Those new to Mandatory Access Control
0015 are encouraged to compare Smack with the other mechanisms
0016 available to determine which is best suited to the problem
0017 at hand.
0018
0019 Smack consists of three major components:
0020
0021 - The kernel
0022 - Basic utilities, which are helpful but not required
0023 - Configuration data
0024
0025 The kernel component of Smack is implemented as a Linux
0026 Security Modules (LSM) module. It requires netlabel and
0027 works best with file systems that support extended attributes,
0028 although xattr support is not strictly required.
0029 It is safe to run a Smack kernel under a "vanilla" distribution.
0030
0031 Smack kernels use the CIPSO IP option. Some network
0032 configurations are intolerant of IP options and can impede
0033 access to systems that use them as Smack does.
0034
0035 Smack is used in the Tizen operating system. Please
0036 go to http://wiki.tizen.org for information about how
0037 Smack is used in Tizen.
0038
0039 The current git repository for Smack user space is:
0040
0041 git://github.com/smack-team/smack.git
0042
0043 This should make and install on most modern distributions.
0044 There are five commands included in smackutil:
0045
0046 chsmack:
0047 display or set Smack extended attribute values
0048
0049 smackctl:
0050 load the Smack access rules
0051
0052 smackaccess:
0053 report if a process with one label has access
0054 to an object with another
0055
0056 These two commands are obsolete with the introduction of
0057 the smackfs/load2 and smackfs/cipso2 interfaces.
0058
0059 smackload:
0060 properly formats data for writing to smackfs/load
0061
0062 smackcipso:
0063 properly formats data for writing to smackfs/cipso
0064
0065 In keeping with the intent of Smack, configuration data is
0066 minimal and not strictly required. The most important
0067 configuration step is mounting the smackfs pseudo filesystem.
0068 If smackutil is installed the startup script will take care
0069 of this, but it can be manually as well.
0070
0071 Add this line to ``/etc/fstab``::
0072
0073 smackfs /sys/fs/smackfs smackfs defaults 0 0
0074
0075 The ``/sys/fs/smackfs`` directory is created by the kernel.
0076
0077 Smack uses extended attributes (xattrs) to store labels on filesystem
0078 objects. The attributes are stored in the extended attribute security
0079 name space. A process must have ``CAP_MAC_ADMIN`` to change any of these
0080 attributes.
0081
0082 The extended attributes that Smack uses are:
0083
0084 SMACK64
0085 Used to make access control decisions. In almost all cases
0086 the label given to a new filesystem object will be the label
0087 of the process that created it.
0088
0089 SMACK64EXEC
0090 The Smack label of a process that execs a program file with
0091 this attribute set will run with this attribute's value.
0092
0093 SMACK64MMAP
0094 Don't allow the file to be mmapped by a process whose Smack
0095 label does not allow all of the access permitted to a process
0096 with the label contained in this attribute. This is a very
0097 specific use case for shared libraries.
0098
0099 SMACK64TRANSMUTE
0100 Can only have the value "TRUE". If this attribute is present
0101 on a directory when an object is created in the directory and
0102 the Smack rule (more below) that permitted the write access
0103 to the directory includes the transmute ("t") mode the object
0104 gets the label of the directory instead of the label of the
0105 creating process. If the object being created is a directory
0106 the SMACK64TRANSMUTE attribute is set as well.
0107
0108 SMACK64IPIN
0109 This attribute is only available on file descriptors for sockets.
0110 Use the Smack label in this attribute for access control
0111 decisions on packets being delivered to this socket.
0112
0113 SMACK64IPOUT
0114 This attribute is only available on file descriptors for sockets.
0115 Use the Smack label in this attribute for access control
0116 decisions on packets coming from this socket.
0117
0118 There are multiple ways to set a Smack label on a file::
0119
0120 # attr -S -s SMACK64 -V "value" path
0121 # chsmack -a value path
0122
0123 A process can see the Smack label it is running with by
0124 reading ``/proc/self/attr/current``. A process with ``CAP_MAC_ADMIN``
0125 can set the process Smack by writing there.
0126
0127 Most Smack configuration is accomplished by writing to files
0128 in the smackfs filesystem. This pseudo-filesystem is mounted
0129 on ``/sys/fs/smackfs``.
0130
0131 access
0132 Provided for backward compatibility. The access2 interface
0133 is preferred and should be used instead.
0134 This interface reports whether a subject with the specified
0135 Smack label has a particular access to an object with a
0136 specified Smack label. Write a fixed format access rule to
0137 this file. The next read will indicate whether the access
0138 would be permitted. The text will be either "1" indicating
0139 access, or "0" indicating denial.
0140
0141 access2
0142 This interface reports whether a subject with the specified
0143 Smack label has a particular access to an object with a
0144 specified Smack label. Write a long format access rule to
0145 this file. The next read will indicate whether the access
0146 would be permitted. The text will be either "1" indicating
0147 access, or "0" indicating denial.
0148
0149 ambient
0150 This contains the Smack label applied to unlabeled network
0151 packets.
0152
0153 change-rule
0154 This interface allows modification of existing access control rules.
0155 The format accepted on write is::
0156
0157 "%s %s %s %s"
0158
0159 where the first string is the subject label, the second the
0160 object label, the third the access to allow and the fourth the
0161 access to deny. The access strings may contain only the characters
0162 "rwxat-". If a rule for a given subject and object exists it will be
0163 modified by enabling the permissions in the third string and disabling
0164 those in the fourth string. If there is no such rule it will be
0165 created using the access specified in the third and the fourth strings.
0166
0167 cipso
0168 Provided for backward compatibility. The cipso2 interface
0169 is preferred and should be used instead.
0170 This interface allows a specific CIPSO header to be assigned
0171 to a Smack label. The format accepted on write is::
0172
0173 "%24s%4d%4d"["%4d"]...
0174
0175 The first string is a fixed Smack label. The first number is
0176 the level to use. The second number is the number of categories.
0177 The following numbers are the categories::
0178
0179 "level-3-cats-5-19 3 2 5 19"
0180
0181 cipso2
0182 This interface allows a specific CIPSO header to be assigned
0183 to a Smack label. The format accepted on write is::
0184
0185 "%s%4d%4d"["%4d"]...
0186
0187 The first string is a long Smack label. The first number is
0188 the level to use. The second number is the number of categories.
0189 The following numbers are the categories::
0190
0191 "level-3-cats-5-19 3 2 5 19"
0192
0193 direct
0194 This contains the CIPSO level used for Smack direct label
0195 representation in network packets.
0196
0197 doi
0198 This contains the CIPSO domain of interpretation used in
0199 network packets.
0200
0201 ipv6host
0202 This interface allows specific IPv6 internet addresses to be
0203 treated as single label hosts. Packets are sent to single
0204 label hosts only from processes that have Smack write access
0205 to the host label. All packets received from single label hosts
0206 are given the specified label. The format accepted on write is::
0207
0208 "%h:%h:%h:%h:%h:%h:%h:%h label" or
0209 "%h:%h:%h:%h:%h:%h:%h:%h/%d label".
0210
0211 The "::" address shortcut is not supported.
0212 If label is "-DELETE" a matched entry will be deleted.
0213
0214 load
0215 Provided for backward compatibility. The load2 interface
0216 is preferred and should be used instead.
0217 This interface allows access control rules in addition to
0218 the system defined rules to be specified. The format accepted
0219 on write is::
0220
0221 "%24s%24s%5s"
0222
0223 where the first string is the subject label, the second the
0224 object label, and the third the requested access. The access
0225 string may contain only the characters "rwxat-", and specifies
0226 which sort of access is allowed. The "-" is a placeholder for
0227 permissions that are not allowed. The string "r-x--" would
0228 specify read and execute access. Labels are limited to 23
0229 characters in length.
0230
0231 load2
0232 This interface allows access control rules in addition to
0233 the system defined rules to be specified. The format accepted
0234 on write is::
0235
0236 "%s %s %s"
0237
0238 where the first string is the subject label, the second the
0239 object label, and the third the requested access. The access
0240 string may contain only the characters "rwxat-", and specifies
0241 which sort of access is allowed. The "-" is a placeholder for
0242 permissions that are not allowed. The string "r-x--" would
0243 specify read and execute access.
0244
0245 load-self
0246 Provided for backward compatibility. The load-self2 interface
0247 is preferred and should be used instead.
0248 This interface allows process specific access rules to be
0249 defined. These rules are only consulted if access would
0250 otherwise be permitted, and are intended to provide additional
0251 restrictions on the process. The format is the same as for
0252 the load interface.
0253
0254 load-self2
0255 This interface allows process specific access rules to be
0256 defined. These rules are only consulted if access would
0257 otherwise be permitted, and are intended to provide additional
0258 restrictions on the process. The format is the same as for
0259 the load2 interface.
0260
0261 logging
0262 This contains the Smack logging state.
0263
0264 mapped
0265 This contains the CIPSO level used for Smack mapped label
0266 representation in network packets.
0267
0268 netlabel
0269 This interface allows specific internet addresses to be
0270 treated as single label hosts. Packets are sent to single
0271 label hosts without CIPSO headers, but only from processes
0272 that have Smack write access to the host label. All packets
0273 received from single label hosts are given the specified
0274 label. The format accepted on write is::
0275
0276 "%d.%d.%d.%d label" or "%d.%d.%d.%d/%d label".
0277
0278 If the label specified is "-CIPSO" the address is treated
0279 as a host that supports CIPSO headers.
0280
0281 onlycap
0282 This contains labels processes must have for CAP_MAC_ADMIN
0283 and ``CAP_MAC_OVERRIDE`` to be effective. If this file is empty
0284 these capabilities are effective at for processes with any
0285 label. The values are set by writing the desired labels, separated
0286 by spaces, to the file or cleared by writing "-" to the file.
0287
0288 ptrace
0289 This is used to define the current ptrace policy
0290
0291 0 - default:
0292 this is the policy that relies on Smack access rules.
0293 For the ``PTRACE_READ`` a subject needs to have a read access on
0294 object. For the ``PTRACE_ATTACH`` a read-write access is required.
0295
0296 1 - exact:
0297 this is the policy that limits ``PTRACE_ATTACH``. Attach is
0298 only allowed when subject's and object's labels are equal.
0299 ``PTRACE_READ`` is not affected. Can be overridden with ``CAP_SYS_PTRACE``.
0300
0301 2 - draconian:
0302 this policy behaves like the 'exact' above with an
0303 exception that it can't be overridden with ``CAP_SYS_PTRACE``.
0304
0305 revoke-subject
0306 Writing a Smack label here sets the access to '-' for all access
0307 rules with that subject label.
0308
0309 unconfined
0310 If the kernel is configured with ``CONFIG_SECURITY_SMACK_BRINGUP``
0311 a process with ``CAP_MAC_ADMIN`` can write a label into this interface.
0312 Thereafter, accesses that involve that label will be logged and
0313 the access permitted if it wouldn't be otherwise. Note that this
0314 is dangerous and can ruin the proper labeling of your system.
0315 It should never be used in production.
0316
0317 relabel-self
0318 This interface contains a list of labels to which the process can
0319 transition to, by writing to ``/proc/self/attr/current``.
0320 Normally a process can change its own label to any legal value, but only
0321 if it has ``CAP_MAC_ADMIN``. This interface allows a process without
0322 ``CAP_MAC_ADMIN`` to relabel itself to one of labels from predefined list.
0323 A process without ``CAP_MAC_ADMIN`` can change its label only once. When it
0324 does, this list will be cleared.
0325 The values are set by writing the desired labels, separated
0326 by spaces, to the file or cleared by writing "-" to the file.
0327
0328 If you are using the smackload utility
0329 you can add access rules in ``/etc/smack/accesses``. They take the form::
0330
0331 subjectlabel objectlabel access
0332
0333 access is a combination of the letters rwxatb which specify the
0334 kind of access permitted a subject with subjectlabel on an
0335 object with objectlabel. If there is no rule no access is allowed.
0336
0337 Look for additional programs on http://schaufler-ca.com
0338
0339 The Simplified Mandatory Access Control Kernel (Whitepaper)
0340 ===========================================================
0341
0342 Casey Schaufler
0343 casey@schaufler-ca.com
0344
0345 Mandatory Access Control
0346 ------------------------
0347
0348 Computer systems employ a variety of schemes to constrain how information is
0349 shared among the people and services using the machine. Some of these schemes
0350 allow the program or user to decide what other programs or users are allowed
0351 access to pieces of data. These schemes are called discretionary access
0352 control mechanisms because the access control is specified at the discretion
0353 of the user. Other schemes do not leave the decision regarding what a user or
0354 program can access up to users or programs. These schemes are called mandatory
0355 access control mechanisms because you don't have a choice regarding the users
0356 or programs that have access to pieces of data.
0357
0358 Bell & LaPadula
0359 ---------------
0360
0361 From the middle of the 1980's until the turn of the century Mandatory Access
0362 Control (MAC) was very closely associated with the Bell & LaPadula security
0363 model, a mathematical description of the United States Department of Defense
0364 policy for marking paper documents. MAC in this form enjoyed a following
0365 within the Capital Beltway and Scandinavian supercomputer centers but was
0366 often sited as failing to address general needs.
0367
0368 Domain Type Enforcement
0369 -----------------------
0370
0371 Around the turn of the century Domain Type Enforcement (DTE) became popular.
0372 This scheme organizes users, programs, and data into domains that are
0373 protected from each other. This scheme has been widely deployed as a component
0374 of popular Linux distributions. The administrative overhead required to
0375 maintain this scheme and the detailed understanding of the whole system
0376 necessary to provide a secure domain mapping leads to the scheme being
0377 disabled or used in limited ways in the majority of cases.
0378
0379 Smack
0380 -----
0381
0382 Smack is a Mandatory Access Control mechanism designed to provide useful MAC
0383 while avoiding the pitfalls of its predecessors. The limitations of Bell &
0384 LaPadula are addressed by providing a scheme whereby access can be controlled
0385 according to the requirements of the system and its purpose rather than those
0386 imposed by an arcane government policy. The complexity of Domain Type
0387 Enforcement and avoided by defining access controls in terms of the access
0388 modes already in use.
0389
0390 Smack Terminology
0391 -----------------
0392
0393 The jargon used to talk about Smack will be familiar to those who have dealt
0394 with other MAC systems and shouldn't be too difficult for the uninitiated to
0395 pick up. There are four terms that are used in a specific way and that are
0396 especially important:
0397
0398 Subject:
0399 A subject is an active entity on the computer system.
0400 On Smack a subject is a task, which is in turn the basic unit
0401 of execution.
0402
0403 Object:
0404 An object is a passive entity on the computer system.
0405 On Smack files of all types, IPC, and tasks can be objects.
0406
0407 Access:
0408 Any attempt by a subject to put information into or get
0409 information from an object is an access.
0410
0411 Label:
0412 Data that identifies the Mandatory Access Control
0413 characteristics of a subject or an object.
0414
0415 These definitions are consistent with the traditional use in the security
0416 community. There are also some terms from Linux that are likely to crop up:
0417
0418 Capability:
0419 A task that possesses a capability has permission to
0420 violate an aspect of the system security policy, as identified by
0421 the specific capability. A task that possesses one or more
0422 capabilities is a privileged task, whereas a task with no
0423 capabilities is an unprivileged task.
0424
0425 Privilege:
0426 A task that is allowed to violate the system security
0427 policy is said to have privilege. As of this writing a task can
0428 have privilege either by possessing capabilities or by having an
0429 effective user of root.
0430
0431 Smack Basics
0432 ------------
0433
0434 Smack is an extension to a Linux system. It enforces additional restrictions
0435 on what subjects can access which objects, based on the labels attached to
0436 each of the subject and the object.
0437
0438 Labels
0439 ~~~~~~
0440
0441 Smack labels are ASCII character strings. They can be up to 255 characters
0442 long, but keeping them to twenty-three characters is recommended.
0443 Single character labels using special characters, that being anything
0444 other than a letter or digit, are reserved for use by the Smack development
0445 team. Smack labels are unstructured, case sensitive, and the only operation
0446 ever performed on them is comparison for equality. Smack labels cannot
0447 contain unprintable characters, the "/" (slash), the "\" (backslash), the "'"
0448 (quote) and '"' (double-quote) characters.
0449 Smack labels cannot begin with a '-'. This is reserved for special options.
0450
0451 There are some predefined labels::
0452
0453 _ Pronounced "floor", a single underscore character.
0454 ^ Pronounced "hat", a single circumflex character.
0455 * Pronounced "star", a single asterisk character.
0456 ? Pronounced "huh", a single question mark character.
0457 @ Pronounced "web", a single at sign character.
0458
0459 Every task on a Smack system is assigned a label. The Smack label
0460 of a process will usually be assigned by the system initialization
0461 mechanism.
0462
0463 Access Rules
0464 ~~~~~~~~~~~~
0465
0466 Smack uses the traditional access modes of Linux. These modes are read,
0467 execute, write, and occasionally append. There are a few cases where the
0468 access mode may not be obvious. These include:
0469
0470 Signals:
0471 A signal is a write operation from the subject task to
0472 the object task.
0473
0474 Internet Domain IPC:
0475 Transmission of a packet is considered a
0476 write operation from the source task to the destination task.
0477
0478 Smack restricts access based on the label attached to a subject and the label
0479 attached to the object it is trying to access. The rules enforced are, in
0480 order:
0481
0482 1. Any access requested by a task labeled "*" is denied.
0483 2. A read or execute access requested by a task labeled "^"
0484 is permitted.
0485 3. A read or execute access requested on an object labeled "_"
0486 is permitted.
0487 4. Any access requested on an object labeled "*" is permitted.
0488 5. Any access requested by a task on an object with the same
0489 label is permitted.
0490 6. Any access requested that is explicitly defined in the loaded
0491 rule set is permitted.
0492 7. Any other access is denied.
0493
0494 Smack Access Rules
0495 ~~~~~~~~~~~~~~~~~~
0496
0497 With the isolation provided by Smack access separation is simple. There are
0498 many interesting cases where limited access by subjects to objects with
0499 different labels is desired. One example is the familiar spy model of
0500 sensitivity, where a scientist working on a highly classified project would be
0501 able to read documents of lower classifications and anything she writes will
0502 be "born" highly classified. To accommodate such schemes Smack includes a
0503 mechanism for specifying rules allowing access between labels.
0504
0505 Access Rule Format
0506 ~~~~~~~~~~~~~~~~~~
0507
0508 The format of an access rule is::
0509
0510 subject-label object-label access
0511
0512 Where subject-label is the Smack label of the task, object-label is the Smack
0513 label of the thing being accessed, and access is a string specifying the sort
0514 of access allowed. The access specification is searched for letters that
0515 describe access modes:
0516
0517 a: indicates that append access should be granted.
0518 r: indicates that read access should be granted.
0519 w: indicates that write access should be granted.
0520 x: indicates that execute access should be granted.
0521 t: indicates that the rule requests transmutation.
0522 b: indicates that the rule should be reported for bring-up.
0523
0524 Uppercase values for the specification letters are allowed as well.
0525 Access mode specifications can be in any order. Examples of acceptable rules
0526 are::
0527
0528 TopSecret Secret rx
0529 Secret Unclass R
0530 Manager Game x
0531 User HR w
0532 Snap Crackle rwxatb
0533 New Old rRrRr
0534 Closed Off -
0535
0536 Examples of unacceptable rules are::
0537
0538 Top Secret Secret rx
0539 Ace Ace r
0540 Odd spells waxbeans
0541
0542 Spaces are not allowed in labels. Since a subject always has access to files
0543 with the same label specifying a rule for that case is pointless. Only
0544 valid letters (rwxatbRWXATB) and the dash ('-') character are allowed in
0545 access specifications. The dash is a placeholder, so "a-r" is the same
0546 as "ar". A lone dash is used to specify that no access should be allowed.
0547
0548 Applying Access Rules
0549 ~~~~~~~~~~~~~~~~~~~~~
0550
0551 The developers of Linux rarely define new sorts of things, usually importing
0552 schemes and concepts from other systems. Most often, the other systems are
0553 variants of Unix. Unix has many endearing properties, but consistency of
0554 access control models is not one of them. Smack strives to treat accesses as
0555 uniformly as is sensible while keeping with the spirit of the underlying
0556 mechanism.
0557
0558 File system objects including files, directories, named pipes, symbolic links,
0559 and devices require access permissions that closely match those used by mode
0560 bit access. To open a file for reading read access is required on the file. To
0561 search a directory requires execute access. Creating a file with write access
0562 requires both read and write access on the containing directory. Deleting a
0563 file requires read and write access to the file and to the containing
0564 directory. It is possible that a user may be able to see that a file exists
0565 but not any of its attributes by the circumstance of having read access to the
0566 containing directory but not to the differently labeled file. This is an
0567 artifact of the file name being data in the directory, not a part of the file.
0568
0569 If a directory is marked as transmuting (SMACK64TRANSMUTE=TRUE) and the
0570 access rule that allows a process to create an object in that directory
0571 includes 't' access the label assigned to the new object will be that
0572 of the directory, not the creating process. This makes it much easier
0573 for two processes with different labels to share data without granting
0574 access to all of their files.
0575
0576 IPC objects, message queues, semaphore sets, and memory segments exist in flat
0577 namespaces and access requests are only required to match the object in
0578 question.
0579
0580 Process objects reflect tasks on the system and the Smack label used to access
0581 them is the same Smack label that the task would use for its own access
0582 attempts. Sending a signal via the kill() system call is a write operation
0583 from the signaler to the recipient. Debugging a process requires both reading
0584 and writing. Creating a new task is an internal operation that results in two
0585 tasks with identical Smack labels and requires no access checks.
0586
0587 Sockets are data structures attached to processes and sending a packet from
0588 one process to another requires that the sender have write access to the
0589 receiver. The receiver is not required to have read access to the sender.
0590
0591 Setting Access Rules
0592 ~~~~~~~~~~~~~~~~~~~~
0593
0594 The configuration file /etc/smack/accesses contains the rules to be set at
0595 system startup. The contents are written to the special file
0596 /sys/fs/smackfs/load2. Rules can be added at any time and take effect
0597 immediately. For any pair of subject and object labels there can be only
0598 one rule, with the most recently specified overriding any earlier
0599 specification.
0600
0601 Task Attribute
0602 ~~~~~~~~~~~~~~
0603
0604 The Smack label of a process can be read from /proc/<pid>/attr/current. A
0605 process can read its own Smack label from /proc/self/attr/current. A
0606 privileged process can change its own Smack label by writing to
0607 /proc/self/attr/current but not the label of another process.
0608
0609 File Attribute
0610 ~~~~~~~~~~~~~~
0611
0612 The Smack label of a filesystem object is stored as an extended attribute
0613 named SMACK64 on the file. This attribute is in the security namespace. It can
0614 only be changed by a process with privilege.
0615
0616 Privilege
0617 ~~~~~~~~~
0618
0619 A process with CAP_MAC_OVERRIDE or CAP_MAC_ADMIN is privileged.
0620 CAP_MAC_OVERRIDE allows the process access to objects it would
0621 be denied otherwise. CAP_MAC_ADMIN allows a process to change
0622 Smack data, including rules and attributes.
0623
0624 Smack Networking
0625 ~~~~~~~~~~~~~~~~
0626
0627 As mentioned before, Smack enforces access control on network protocol
0628 transmissions. Every packet sent by a Smack process is tagged with its Smack
0629 label. This is done by adding a CIPSO tag to the header of the IP packet. Each
0630 packet received is expected to have a CIPSO tag that identifies the label and
0631 if it lacks such a tag the network ambient label is assumed. Before the packet
0632 is delivered a check is made to determine that a subject with the label on the
0633 packet has write access to the receiving process and if that is not the case
0634 the packet is dropped.
0635
0636 CIPSO Configuration
0637 ~~~~~~~~~~~~~~~~~~~
0638
0639 It is normally unnecessary to specify the CIPSO configuration. The default
0640 values used by the system handle all internal cases. Smack will compose CIPSO
0641 label values to match the Smack labels being used without administrative
0642 intervention. Unlabeled packets that come into the system will be given the
0643 ambient label.
0644
0645 Smack requires configuration in the case where packets from a system that is
0646 not Smack that speaks CIPSO may be encountered. Usually this will be a Trusted
0647 Solaris system, but there are other, less widely deployed systems out there.
0648 CIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level,
0649 and a category set with each packet. The DOI is intended to identify a group
0650 of systems that use compatible labeling schemes, and the DOI specified on the
0651 Smack system must match that of the remote system or packets will be
0652 discarded. The DOI is 3 by default. The value can be read from
0653 /sys/fs/smackfs/doi and can be changed by writing to /sys/fs/smackfs/doi.
0654
0655 The label and category set are mapped to a Smack label as defined in
0656 /etc/smack/cipso.
0657
0658 A Smack/CIPSO mapping has the form::
0659
0660 smack level [category [category]*]
0661
0662 Smack does not expect the level or category sets to be related in any
0663 particular way and does not assume or assign accesses based on them. Some
0664 examples of mappings::
0665
0666 TopSecret 7
0667 TS:A,B 7 1 2
0668 SecBDE 5 2 4 6
0669 RAFTERS 7 12 26
0670
0671 The ":" and "," characters are permitted in a Smack label but have no special
0672 meaning.
0673
0674 The mapping of Smack labels to CIPSO values is defined by writing to
0675 /sys/fs/smackfs/cipso2.
0676
0677 In addition to explicit mappings Smack supports direct CIPSO mappings. One
0678 CIPSO level is used to indicate that the category set passed in the packet is
0679 in fact an encoding of the Smack label. The level used is 250 by default. The
0680 value can be read from /sys/fs/smackfs/direct and changed by writing to
0681 /sys/fs/smackfs/direct.
0682
0683 Socket Attributes
0684 ~~~~~~~~~~~~~~~~~
0685
0686 There are two attributes that are associated with sockets. These attributes
0687 can only be set by privileged tasks, but any task can read them for their own
0688 sockets.
0689
0690 SMACK64IPIN:
0691 The Smack label of the task object. A privileged
0692 program that will enforce policy may set this to the star label.
0693
0694 SMACK64IPOUT:
0695 The Smack label transmitted with outgoing packets.
0696 A privileged program may set this to match the label of another
0697 task with which it hopes to communicate.
0698
0699 Smack Netlabel Exceptions
0700 ~~~~~~~~~~~~~~~~~~~~~~~~~
0701
0702 You will often find that your labeled application has to talk to the outside,
0703 unlabeled world. To do this there's a special file /sys/fs/smackfs/netlabel
0704 where you can add some exceptions in the form of::
0705
0706 @IP1 LABEL1 or
0707 @IP2/MASK LABEL2
0708
0709 It means that your application will have unlabeled access to @IP1 if it has
0710 write access on LABEL1, and access to the subnet @IP2/MASK if it has write
0711 access on LABEL2.
0712
0713 Entries in the /sys/fs/smackfs/netlabel file are matched by longest mask
0714 first, like in classless IPv4 routing.
0715
0716 A special label '@' and an option '-CIPSO' can be used there::
0717
0718 @ means Internet, any application with any label has access to it
0719 -CIPSO means standard CIPSO networking
0720
0721 If you don't know what CIPSO is and don't plan to use it, you can just do::
0722
0723 echo 127.0.0.1 -CIPSO > /sys/fs/smackfs/netlabel
0724 echo 0.0.0.0/0 @ > /sys/fs/smackfs/netlabel
0725
0726 If you use CIPSO on your 192.168.0.0/16 local network and need also unlabeled
0727 Internet access, you can have::
0728
0729 echo 127.0.0.1 -CIPSO > /sys/fs/smackfs/netlabel
0730 echo 192.168.0.0/16 -CIPSO > /sys/fs/smackfs/netlabel
0731 echo 0.0.0.0/0 @ > /sys/fs/smackfs/netlabel
0732
0733 Writing Applications for Smack
0734 ------------------------------
0735
0736 There are three sorts of applications that will run on a Smack system. How an
0737 application interacts with Smack will determine what it will have to do to
0738 work properly under Smack.
0739
0740 Smack Ignorant Applications
0741 ---------------------------
0742
0743 By far the majority of applications have no reason whatever to care about the
0744 unique properties of Smack. Since invoking a program has no impact on the
0745 Smack label associated with the process the only concern likely to arise is
0746 whether the process has execute access to the program.
0747
0748 Smack Relevant Applications
0749 ---------------------------
0750
0751 Some programs can be improved by teaching them about Smack, but do not make
0752 any security decisions themselves. The utility ls(1) is one example of such a
0753 program.
0754
0755 Smack Enforcing Applications
0756 ----------------------------
0757
0758 These are special programs that not only know about Smack, but participate in
0759 the enforcement of system policy. In most cases these are the programs that
0760 set up user sessions. There are also network services that provide information
0761 to processes running with various labels.
0762
0763 File System Interfaces
0764 ----------------------
0765
0766 Smack maintains labels on file system objects using extended attributes. The
0767 Smack label of a file, directory, or other file system object can be obtained
0768 using getxattr(2)::
0769
0770 len = getxattr("/", "security.SMACK64", value, sizeof (value));
0771
0772 will put the Smack label of the root directory into value. A privileged
0773 process can set the Smack label of a file system object with setxattr(2)::
0774
0775 len = strlen("Rubble");
0776 rc = setxattr("/foo", "security.SMACK64", "Rubble", len, 0);
0777
0778 will set the Smack label of /foo to "Rubble" if the program has appropriate
0779 privilege.
0780
0781 Socket Interfaces
0782 -----------------
0783
0784 The socket attributes can be read using fgetxattr(2).
0785
0786 A privileged process can set the Smack label of outgoing packets with
0787 fsetxattr(2)::
0788
0789 len = strlen("Rubble");
0790 rc = fsetxattr(fd, "security.SMACK64IPOUT", "Rubble", len, 0);
0791
0792 will set the Smack label "Rubble" on packets going out from the socket if the
0793 program has appropriate privilege::
0794
0795 rc = fsetxattr(fd, "security.SMACK64IPIN, "*", strlen("*"), 0);
0796
0797 will set the Smack label "*" as the object label against which incoming
0798 packets will be checked if the program has appropriate privilege.
0799
0800 Administration
0801 --------------
0802
0803 Smack supports some mount options:
0804
0805 smackfsdef=label:
0806 specifies the label to give files that lack
0807 the Smack label extended attribute.
0808
0809 smackfsroot=label:
0810 specifies the label to assign the root of the
0811 file system if it lacks the Smack extended attribute.
0812
0813 smackfshat=label:
0814 specifies a label that must have read access to
0815 all labels set on the filesystem. Not yet enforced.
0816
0817 smackfsfloor=label:
0818 specifies a label to which all labels set on the
0819 filesystem must have read access. Not yet enforced.
0820
0821 smackfstransmute=label:
0822 behaves exactly like smackfsroot except that it also
0823 sets the transmute flag on the root of the mount
0824
0825 These mount options apply to all file system types.
0826
0827 Smack auditing
0828 --------------
0829
0830 If you want Smack auditing of security events, you need to set CONFIG_AUDIT
0831 in your kernel configuration.
0832 By default, all denied events will be audited. You can change this behavior by
0833 writing a single character to the /sys/fs/smackfs/logging file::
0834
0835 0 : no logging
0836 1 : log denied (default)
0837 2 : log accepted
0838 3 : log denied & accepted
0839
0840 Events are logged as 'key=value' pairs, for each event you at least will get
0841 the subject, the object, the rights requested, the action, the kernel function
0842 that triggered the event, plus other pairs depending on the type of event
0843 audited.
0844
0845 Bringup Mode
0846 ------------
0847
0848 Bringup mode provides logging features that can make application
0849 configuration and system bringup easier. Configure the kernel with
0850 CONFIG_SECURITY_SMACK_BRINGUP to enable these features. When bringup
0851 mode is enabled accesses that succeed due to rules marked with the "b"
0852 access mode will logged. When a new label is introduced for processes
0853 rules can be added aggressively, marked with the "b". The logging allows
0854 tracking of which rules actual get used for that label.
0855
0856 Another feature of bringup mode is the "unconfined" option. Writing
0857 a label to /sys/fs/smackfs/unconfined makes subjects with that label
0858 able to access any object, and objects with that label accessible to
0859 all subjects. Any access that is granted because a label is unconfined
0860 is logged. This feature is dangerous, as files and directories may
0861 be created in places they couldn't if the policy were being enforced.