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