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