Smack.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. "Good for you, you've decided to clean the elevator!"
  2. - The Elevator, from Dark Star
  3. Smack is the the Simplified Mandatory Access Control Kernel.
  4. Smack is a kernel based implementation of mandatory access
  5. control that includes simplicity in its primary design goals.
  6. Smack is not the only Mandatory Access Control scheme
  7. available for Linux. Those new to Mandatory Access Control
  8. are encouraged to compare Smack with the other mechanisms
  9. available to determine which is best suited to the problem
  10. at hand.
  11. Smack consists of three major components:
  12. - The kernel
  13. - A start-up script and a few modified applications
  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 startup script etc-init.d-smack should be installed
  24. in /etc/init.d/smack and should be invoked early in the
  25. start-up process. On Fedora rc5.d/S02smack is recommended.
  26. This script ensures that certain devices have the correct
  27. Smack attributes and loads the Smack configuration if
  28. any is defined. This script invokes two programs that
  29. ensure configuration data is properly formatted. These
  30. programs are /usr/sbin/smackload and /usr/sin/smackcipso.
  31. The system will run just fine without these programs,
  32. but it will be difficult to set access rules properly.
  33. A version of "ls" that provides a "-M" option to display
  34. Smack labels on long listing is available.
  35. A hacked version of sshd that allows network logins by users
  36. with specific Smack labels is available. This version does
  37. not work for scp. You must set the /etc/ssh/sshd_config
  38. line:
  39. UsePrivilegeSeparation no
  40. The format of /etc/smack/usr is:
  41. username smack
  42. In keeping with the intent of Smack, configuration data is
  43. minimal and not strictly required. The most important
  44. configuration step is mounting the smackfs pseudo filesystem.
  45. Add this line to /etc/fstab:
  46. smackfs /smack smackfs smackfsdef=* 0 0
  47. and create the /smack directory for mounting.
  48. Smack uses extended attributes (xattrs) to store file labels.
  49. The command to set a Smack label on a file is:
  50. # attr -S -s SMACK64 -V "value" path
  51. NOTE: Smack labels are limited to 23 characters. The attr command
  52. does not enforce this restriction and can be used to set
  53. invalid Smack labels on files.
  54. If you don't do anything special all users will get the floor ("_")
  55. label when they log in. If you do want to log in via the hacked ssh
  56. at other labels use the attr command to set the smack value on the
  57. home directory and it's contents.
  58. You can add access rules in /etc/smack/accesses. They take the form:
  59. subjectlabel objectlabel access
  60. access is a combination of the letters rwxa which specify the
  61. kind of access permitted a subject with subjectlabel on an
  62. object with objectlabel. If there is no rule no access is allowed.
  63. A process can see the smack label it is running with by
  64. reading /proc/self/attr/current. A privileged process can
  65. set the process smack by writing there.
  66. Look for additional programs on http://schaufler-ca.com
  67. From the Smack Whitepaper:
  68. The Simplified Mandatory Access Control Kernel
  69. Casey Schaufler
  70. casey@schaufler-ca.com
  71. Mandatory Access Control
  72. Computer systems employ a variety of schemes to constrain how information is
  73. shared among the people and services using the machine. Some of these schemes
  74. allow the program or user to decide what other programs or users are allowed
  75. access to pieces of data. These schemes are called discretionary access
  76. control mechanisms because the access control is specified at the discretion
  77. of the user. Other schemes do not leave the decision regarding what a user or
  78. program can access up to users or programs. These schemes are called mandatory
  79. access control mechanisms because you don't have a choice regarding the users
  80. or programs that have access to pieces of data.
  81. Bell & LaPadula
  82. From the middle of the 1980's until the turn of the century Mandatory Access
  83. Control (MAC) was very closely associated with the Bell & LaPadula security
  84. model, a mathematical description of the United States Department of Defense
  85. policy for marking paper documents. MAC in this form enjoyed a following
  86. within the Capital Beltway and Scandinavian supercomputer centers but was
  87. often sited as failing to address general needs.
  88. Domain Type Enforcement
  89. Around the turn of the century Domain Type Enforcement (DTE) became popular.
  90. This scheme organizes users, programs, and data into domains that are
  91. protected from each other. This scheme has been widely deployed as a component
  92. of popular Linux distributions. The administrative overhead required to
  93. maintain this scheme and the detailed understanding of the whole system
  94. necessary to provide a secure domain mapping leads to the scheme being
  95. disabled or used in limited ways in the majority of cases.
  96. Smack
  97. Smack is a Mandatory Access Control mechanism designed to provide useful MAC
  98. while avoiding the pitfalls of its predecessors. The limitations of Bell &
  99. LaPadula are addressed by providing a scheme whereby access can be controlled
  100. according to the requirements of the system and its purpose rather than those
  101. imposed by an arcane government policy. The complexity of Domain Type
  102. Enforcement and avoided by defining access controls in terms of the access
  103. modes already in use.
  104. Smack Terminology
  105. The jargon used to talk about Smack will be familiar to those who have dealt
  106. with other MAC systems and shouldn't be too difficult for the uninitiated to
  107. pick up. There are four terms that are used in a specific way and that are
  108. especially important:
  109. Subject: A subject is an active entity on the computer system.
  110. On Smack a subject is a task, which is in turn the basic unit
  111. of execution.
  112. Object: An object is a passive entity on the computer system.
  113. On Smack files of all types, IPC, and tasks can be objects.
  114. Access: Any attempt by a subject to put information into or get
  115. information from an object is an access.
  116. Label: Data that identifies the Mandatory Access Control
  117. characteristics of a subject or an object.
  118. These definitions are consistent with the traditional use in the security
  119. community. There are also some terms from Linux that are likely to crop up:
  120. Capability: A task that possesses a capability has permission to
  121. violate an aspect of the system security policy, as identified by
  122. the specific capability. A task that possesses one or more
  123. capabilities is a privileged task, whereas a task with no
  124. capabilities is an unprivileged task.
  125. Privilege: A task that is allowed to violate the system security
  126. policy is said to have privilege. As of this writing a task can
  127. have privilege either by possessing capabilities or by having an
  128. effective user of root.
  129. Smack Basics
  130. Smack is an extension to a Linux system. It enforces additional restrictions
  131. on what subjects can access which objects, based on the labels attached to
  132. each of the subject and the object.
  133. Labels
  134. Smack labels are ASCII character strings, one to twenty-three characters in
  135. length. Single character labels using special characters, that being anything
  136. other than a letter or digit, are reserved for use by the Smack development
  137. team. Smack labels are unstructured, case sensitive, and the only operation
  138. ever performed on them is comparison for equality. Smack labels cannot
  139. contain unprintable characters or the "/" (slash) character.
  140. There are some predefined labels:
  141. _ Pronounced "floor", a single underscore character.
  142. ^ Pronounced "hat", a single circumflex character.
  143. * Pronounced "star", a single asterisk character.
  144. ? Pronounced "huh", a single question mark character.
  145. Every task on a Smack system is assigned a label. System tasks, such as
  146. init(8) and systems daemons, are run with the floor ("_") label. User tasks
  147. are assigned labels according to the specification found in the
  148. /etc/smack/user configuration file.
  149. Access Rules
  150. Smack uses the traditional access modes of Linux. These modes are read,
  151. execute, write, and occasionally append. There are a few cases where the
  152. access mode may not be obvious. These include:
  153. Signals: A signal is a write operation from the subject task to
  154. the object task.
  155. Internet Domain IPC: Transmission of a packet is considered a
  156. write operation from the source task to the destination task.
  157. Smack restricts access based on the label attached to a subject and the label
  158. attached to the object it is trying to access. The rules enforced are, in
  159. order:
  160. 1. Any access requested by a task labeled "*" is denied.
  161. 2. A read or execute access requested by a task labeled "^"
  162. is permitted.
  163. 3. A read or execute access requested on an object labeled "_"
  164. is permitted.
  165. 4. Any access requested on an object labeled "*" is permitted.
  166. 5. Any access requested by a task on an object with the same
  167. label is permitted.
  168. 6. Any access requested that is explicitly defined in the loaded
  169. rule set is permitted.
  170. 7. Any other access is denied.
  171. Smack Access Rules
  172. With the isolation provided by Smack access separation is simple. There are
  173. many interesting cases where limited access by subjects to objects with
  174. different labels is desired. One example is the familiar spy model of
  175. sensitivity, where a scientist working on a highly classified project would be
  176. able to read documents of lower classifications and anything she writes will
  177. be "born" highly classified. To accommodate such schemes Smack includes a
  178. mechanism for specifying rules allowing access between labels.
  179. Access Rule Format
  180. The format of an access rule is:
  181. subject-label object-label access
  182. Where subject-label is the Smack label of the task, object-label is the Smack
  183. label of the thing being accessed, and access is a string specifying the sort
  184. of access allowed. The Smack labels are limited to 23 characters. The access
  185. specification is searched for letters that describe access modes:
  186. a: indicates that append access should be granted.
  187. r: indicates that read access should be granted.
  188. w: indicates that write access should be granted.
  189. x: indicates that execute access should be granted.
  190. Uppercase values for the specification letters are allowed as well.
  191. Access mode specifications can be in any order. Examples of acceptable rules
  192. are:
  193. TopSecret Secret rx
  194. Secret Unclass R
  195. Manager Game x
  196. User HR w
  197. New Old rRrRr
  198. Closed Off -
  199. Examples of unacceptable rules are:
  200. Top Secret Secret rx
  201. Ace Ace r
  202. Odd spells waxbeans
  203. Spaces are not allowed in labels. Since a subject always has access to files
  204. with the same label specifying a rule for that case is pointless. Only
  205. valid letters (rwxaRWXA) and the dash ('-') character are allowed in
  206. access specifications. The dash is a placeholder, so "a-r" is the same
  207. as "ar". A lone dash is used to specify that no access should be allowed.
  208. Applying Access Rules
  209. The developers of Linux rarely define new sorts of things, usually importing
  210. schemes and concepts from other systems. Most often, the other systems are
  211. variants of Unix. Unix has many endearing properties, but consistency of
  212. access control models is not one of them. Smack strives to treat accesses as
  213. uniformly as is sensible while keeping with the spirit of the underlying
  214. mechanism.
  215. File system objects including files, directories, named pipes, symbolic links,
  216. and devices require access permissions that closely match those used by mode
  217. bit access. To open a file for reading read access is required on the file. To
  218. search a directory requires execute access. Creating a file with write access
  219. requires both read and write access on the containing directory. Deleting a
  220. file requires read and write access to the file and to the containing
  221. directory. It is possible that a user may be able to see that a file exists
  222. but not any of its attributes by the circumstance of having read access to the
  223. containing directory but not to the differently labeled file. This is an
  224. artifact of the file name being data in the directory, not a part of the file.
  225. IPC objects, message queues, semaphore sets, and memory segments exist in flat
  226. namespaces and access requests are only required to match the object in
  227. question.
  228. Process objects reflect tasks on the system and the Smack label used to access
  229. them is the same Smack label that the task would use for its own access
  230. attempts. Sending a signal via the kill() system call is a write operation
  231. from the signaler to the recipient. Debugging a process requires both reading
  232. and writing. Creating a new task is an internal operation that results in two
  233. tasks with identical Smack labels and requires no access checks.
  234. Sockets are data structures attached to processes and sending a packet from
  235. one process to another requires that the sender have write access to the
  236. receiver. The receiver is not required to have read access to the sender.
  237. Setting Access Rules
  238. The configuration file /etc/smack/accesses contains the rules to be set at
  239. system startup. The contents are written to the special file /smack/load.
  240. Rules can be written to /smack/load at any time and take effect immediately.
  241. For any pair of subject and object labels there can be only one rule, with the
  242. most recently specified overriding any earlier specification.
  243. The program smackload is provided to ensure data is formatted
  244. properly when written to /smack/load. This program reads lines
  245. of the form
  246. subjectlabel objectlabel mode.
  247. Task Attribute
  248. The Smack label of a process can be read from /proc/<pid>/attr/current. A
  249. process can read its own Smack label from /proc/self/attr/current. A
  250. privileged process can change its own Smack label by writing to
  251. /proc/self/attr/current but not the label of another process.
  252. File Attribute
  253. The Smack label of a filesystem object is stored as an extended attribute
  254. named SMACK64 on the file. This attribute is in the security namespace. It can
  255. only be changed by a process with privilege.
  256. Privilege
  257. A process with CAP_MAC_OVERRIDE is privileged.
  258. Smack Networking
  259. As mentioned before, Smack enforces access control on network protocol
  260. transmissions. Every packet sent by a Smack process is tagged with its Smack
  261. label. This is done by adding a CIPSO tag to the header of the IP packet. Each
  262. packet received is expected to have a CIPSO tag that identifies the label and
  263. if it lacks such a tag the network ambient label is assumed. Before the packet
  264. is delivered a check is made to determine that a subject with the label on the
  265. packet has write access to the receiving process and if that is not the case
  266. the packet is dropped.
  267. CIPSO Configuration
  268. It is normally unnecessary to specify the CIPSO configuration. The default
  269. values used by the system handle all internal cases. Smack will compose CIPSO
  270. label values to match the Smack labels being used without administrative
  271. intervention. Unlabeled packets that come into the system will be given the
  272. ambient label.
  273. Smack requires configuration in the case where packets from a system that is
  274. not smack that speaks CIPSO may be encountered. Usually this will be a Trusted
  275. Solaris system, but there are other, less widely deployed systems out there.
  276. CIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level,
  277. and a category set with each packet. The DOI is intended to identify a group
  278. of systems that use compatible labeling schemes, and the DOI specified on the
  279. smack system must match that of the remote system or packets will be
  280. discarded. The DOI is 3 by default. The value can be read from /smack/doi and
  281. can be changed by writing to /smack/doi.
  282. The label and category set are mapped to a Smack label as defined in
  283. /etc/smack/cipso.
  284. A Smack/CIPSO mapping has the form:
  285. smack level [category [category]*]
  286. Smack does not expect the level or category sets to be related in any
  287. particular way and does not assume or assign accesses based on them. Some
  288. examples of mappings:
  289. TopSecret 7
  290. TS:A,B 7 1 2
  291. SecBDE 5 2 4 6
  292. RAFTERS 7 12 26
  293. The ":" and "," characters are permitted in a Smack label but have no special
  294. meaning.
  295. The mapping of Smack labels to CIPSO values is defined by writing to
  296. /smack/cipso. Again, the format of data written to this special file
  297. is highly restrictive, so the program smackcipso is provided to
  298. ensure the writes are done properly. This program takes mappings
  299. on the standard input and sends them to /smack/cipso properly.
  300. In addition to explicit mappings Smack supports direct CIPSO mappings. One
  301. CIPSO level is used to indicate that the category set passed in the packet is
  302. in fact an encoding of the Smack label. The level used is 250 by default. The
  303. value can be read from /smack/direct and changed by writing to /smack/direct.
  304. Socket Attributes
  305. There are two attributes that are associated with sockets. These attributes
  306. can only be set by privileged tasks, but any task can read them for their own
  307. sockets.
  308. SMACK64IPIN: The Smack label of the task object. A privileged
  309. program that will enforce policy may set this to the star label.
  310. SMACK64IPOUT: The Smack label transmitted with outgoing packets.
  311. A privileged program may set this to match the label of another
  312. task with which it hopes to communicate.
  313. Writing Applications for Smack
  314. There are three sorts of applications that will run on a Smack system. How an
  315. application interacts with Smack will determine what it will have to do to
  316. work properly under Smack.
  317. Smack Ignorant Applications
  318. By far the majority of applications have no reason whatever to care about the
  319. unique properties of Smack. Since invoking a program has no impact on the
  320. Smack label associated with the process the only concern likely to arise is
  321. whether the process has execute access to the program.
  322. Smack Relevant Applications
  323. Some programs can be improved by teaching them about Smack, but do not make
  324. any security decisions themselves. The utility ls(1) is one example of such a
  325. program.
  326. Smack Enforcing Applications
  327. These are special programs that not only know about Smack, but participate in
  328. the enforcement of system policy. In most cases these are the programs that
  329. set up user sessions. There are also network services that provide information
  330. to processes running with various labels.
  331. File System Interfaces
  332. Smack maintains labels on file system objects using extended attributes. The
  333. Smack label of a file, directory, or other file system object can be obtained
  334. using getxattr(2).
  335. len = getxattr("/", "security.SMACK64", value, sizeof (value));
  336. will put the Smack label of the root directory into value. A privileged
  337. process can set the Smack label of a file system object with setxattr(2).
  338. len = strlen("Rubble");
  339. rc = setxattr("/foo", "security.SMACK64", "Rubble", len, 0);
  340. will set the Smack label of /foo to "Rubble" if the program has appropriate
  341. privilege.
  342. Socket Interfaces
  343. The socket attributes can be read using fgetxattr(2).
  344. A privileged process can set the Smack label of outgoing packets with
  345. fsetxattr(2).
  346. len = strlen("Rubble");
  347. rc = fsetxattr(fd, "security.SMACK64IPOUT", "Rubble", len, 0);
  348. will set the Smack label "Rubble" on packets going out from the socket if the
  349. program has appropriate privilege.
  350. rc = fsetxattr(fd, "security.SMACK64IPIN, "*", strlen("*"), 0);
  351. will set the Smack label "*" as the object label against which incoming
  352. packets will be checked if the program has appropriate privilege.
  353. Administration
  354. Smack supports some mount options:
  355. smackfsdef=label: specifies the label to give files that lack
  356. the Smack label extended attribute.
  357. smackfsroot=label: specifies the label to assign the root of the
  358. file system if it lacks the Smack extended attribute.
  359. smackfshat=label: specifies a label that must have read access to
  360. all labels set on the filesystem. Not yet enforced.
  361. smackfsfloor=label: specifies a label to which all labels set on the
  362. filesystem must have read access. Not yet enforced.
  363. These mount options apply to all file system types.