Smack.txt 31 KB

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