Smack.txt 28 KB

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