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