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