Smack.txt 27 KB

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