Smack.rst 32 KB

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