Smack.txt 28 KB

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