Smack.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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 its 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, the "/" (slash), the "\" (backslash), the "'"
  140. (quote) and '"' (double-quote) characters.
  141. Smack labels cannot begin with a '-', which is reserved for special options.
  142. There are some predefined labels:
  143. _ Pronounced "floor", a single underscore character.
  144. ^ Pronounced "hat", a single circumflex character.
  145. * Pronounced "star", a single asterisk character.
  146. ? Pronounced "huh", a single question mark character.
  147. @ Pronounced "Internet", a single at sign character.
  148. Every task on a Smack system is assigned a label. System tasks, such as
  149. init(8) and systems daemons, are run with the floor ("_") label. User tasks
  150. are assigned labels according to the specification found in the
  151. /etc/smack/user configuration file.
  152. Access Rules
  153. Smack uses the traditional access modes of Linux. These modes are read,
  154. execute, write, and occasionally append. There are a few cases where the
  155. access mode may not be obvious. These include:
  156. Signals: A signal is a write operation from the subject task to
  157. the object task.
  158. Internet Domain IPC: Transmission of a packet is considered a
  159. write operation from the source task to the destination task.
  160. Smack restricts access based on the label attached to a subject and the label
  161. attached to the object it is trying to access. The rules enforced are, in
  162. order:
  163. 1. Any access requested by a task labeled "*" is denied.
  164. 2. A read or execute access requested by a task labeled "^"
  165. is permitted.
  166. 3. A read or execute access requested on an object labeled "_"
  167. is permitted.
  168. 4. Any access requested on an object labeled "*" is permitted.
  169. 5. Any access requested by a task on an object with the same
  170. label is permitted.
  171. 6. Any access requested that is explicitly defined in the loaded
  172. rule set is permitted.
  173. 7. Any other access is denied.
  174. Smack Access Rules
  175. With the isolation provided by Smack access separation is simple. There are
  176. many interesting cases where limited access by subjects to objects with
  177. different labels is desired. One example is the familiar spy model of
  178. sensitivity, where a scientist working on a highly classified project would be
  179. able to read documents of lower classifications and anything she writes will
  180. be "born" highly classified. To accommodate such schemes Smack includes a
  181. mechanism for specifying rules allowing access between labels.
  182. Access Rule Format
  183. The format of an access rule is:
  184. subject-label object-label access
  185. Where subject-label is the Smack label of the task, object-label is the Smack
  186. label of the thing being accessed, and access is a string specifying the sort
  187. of access allowed. The Smack labels are limited to 23 characters. The access
  188. specification is searched for letters that describe access modes:
  189. a: indicates that append access should be granted.
  190. r: indicates that read access should be granted.
  191. w: indicates that write access should be granted.
  192. x: indicates that execute access should be granted.
  193. Uppercase values for the specification letters are allowed as well.
  194. Access mode specifications can be in any order. Examples of acceptable rules
  195. are:
  196. TopSecret Secret rx
  197. Secret Unclass R
  198. Manager Game x
  199. User HR w
  200. New Old rRrRr
  201. Closed Off -
  202. Examples of unacceptable rules are:
  203. Top Secret Secret rx
  204. Ace Ace r
  205. Odd spells waxbeans
  206. Spaces are not allowed in labels. Since a subject always has access to files
  207. with the same label specifying a rule for that case is pointless. Only
  208. valid letters (rwxaRWXA) and the dash ('-') character are allowed in
  209. access specifications. The dash is a placeholder, so "a-r" is the same
  210. as "ar". A lone dash is used to specify that no access should be allowed.
  211. Applying Access Rules
  212. The developers of Linux rarely define new sorts of things, usually importing
  213. schemes and concepts from other systems. Most often, the other systems are
  214. variants of Unix. Unix has many endearing properties, but consistency of
  215. access control models is not one of them. Smack strives to treat accesses as
  216. uniformly as is sensible while keeping with the spirit of the underlying
  217. mechanism.
  218. File system objects including files, directories, named pipes, symbolic links,
  219. and devices require access permissions that closely match those used by mode
  220. bit access. To open a file for reading read access is required on the file. To
  221. search a directory requires execute access. Creating a file with write access
  222. requires both read and write access on the containing directory. Deleting a
  223. file requires read and write access to the file and to the containing
  224. directory. It is possible that a user may be able to see that a file exists
  225. but not any of its attributes by the circumstance of having read access to the
  226. containing directory but not to the differently labeled file. This is an
  227. artifact of the file name being data in the directory, not a part of the file.
  228. IPC objects, message queues, semaphore sets, and memory segments exist in flat
  229. namespaces and access requests are only required to match the object in
  230. question.
  231. Process objects reflect tasks on the system and the Smack label used to access
  232. them is the same Smack label that the task would use for its own access
  233. attempts. Sending a signal via the kill() system call is a write operation
  234. from the signaler to the recipient. Debugging a process requires both reading
  235. and writing. Creating a new task is an internal operation that results in two
  236. tasks with identical Smack labels and requires no access checks.
  237. Sockets are data structures attached to processes and sending a packet from
  238. one process to another requires that the sender have write access to the
  239. receiver. The receiver is not required to have read access to the sender.
  240. Setting Access Rules
  241. The configuration file /etc/smack/accesses contains the rules to be set at
  242. system startup. The contents are written to the special file /smack/load.
  243. Rules can be written to /smack/load at any time and take effect immediately.
  244. For any pair of subject and object labels there can be only one rule, with the
  245. most recently specified overriding any earlier specification.
  246. The program smackload is provided to ensure data is formatted
  247. properly when written to /smack/load. This program reads lines
  248. of the form
  249. subjectlabel objectlabel mode.
  250. Task Attribute
  251. The Smack label of a process can be read from /proc/<pid>/attr/current. A
  252. process can read its own Smack label from /proc/self/attr/current. A
  253. privileged process can change its own Smack label by writing to
  254. /proc/self/attr/current but not the label of another process.
  255. File Attribute
  256. The Smack label of a filesystem object is stored as an extended attribute
  257. named SMACK64 on the file. This attribute is in the security namespace. It can
  258. only be changed by a process with privilege.
  259. Privilege
  260. A process with CAP_MAC_OVERRIDE is privileged.
  261. Smack Networking
  262. As mentioned before, Smack enforces access control on network protocol
  263. transmissions. Every packet sent by a Smack process is tagged with its Smack
  264. label. This is done by adding a CIPSO tag to the header of the IP packet. Each
  265. packet received is expected to have a CIPSO tag that identifies the label and
  266. if it lacks such a tag the network ambient label is assumed. Before the packet
  267. is delivered a check is made to determine that a subject with the label on the
  268. packet has write access to the receiving process and if that is not the case
  269. the packet is dropped.
  270. CIPSO Configuration
  271. It is normally unnecessary to specify the CIPSO configuration. The default
  272. values used by the system handle all internal cases. Smack will compose CIPSO
  273. label values to match the Smack labels being used without administrative
  274. intervention. Unlabeled packets that come into the system will be given the
  275. ambient label.
  276. Smack requires configuration in the case where packets from a system that is
  277. not smack that speaks CIPSO may be encountered. Usually this will be a Trusted
  278. Solaris system, but there are other, less widely deployed systems out there.
  279. CIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level,
  280. and a category set with each packet. The DOI is intended to identify a group
  281. of systems that use compatible labeling schemes, and the DOI specified on the
  282. smack system must match that of the remote system or packets will be
  283. discarded. The DOI is 3 by default. The value can be read from /smack/doi and
  284. can be changed by writing to /smack/doi.
  285. The label and category set are mapped to a Smack label as defined in
  286. /etc/smack/cipso.
  287. A Smack/CIPSO mapping has the form:
  288. smack level [category [category]*]
  289. Smack does not expect the level or category sets to be related in any
  290. particular way and does not assume or assign accesses based on them. Some
  291. examples of mappings:
  292. TopSecret 7
  293. TS:A,B 7 1 2
  294. SecBDE 5 2 4 6
  295. RAFTERS 7 12 26
  296. The ":" and "," characters are permitted in a Smack label but have no special
  297. meaning.
  298. The mapping of Smack labels to CIPSO values is defined by writing to
  299. /smack/cipso. Again, the format of data written to this special file
  300. is highly restrictive, so the program smackcipso is provided to
  301. ensure the writes are done properly. This program takes mappings
  302. on the standard input and sends them to /smack/cipso properly.
  303. In addition to explicit mappings Smack supports direct CIPSO mappings. One
  304. CIPSO level is used to indicate that the category set passed in the packet is
  305. in fact an encoding of the Smack label. The level used is 250 by default. The
  306. value can be read from /smack/direct and changed by writing to /smack/direct.
  307. Socket Attributes
  308. There are two attributes that are associated with sockets. These attributes
  309. can only be set by privileged tasks, but any task can read them for their own
  310. sockets.
  311. SMACK64IPIN: The Smack label of the task object. A privileged
  312. program that will enforce policy may set this to the star label.
  313. SMACK64IPOUT: The Smack label transmitted with outgoing packets.
  314. A privileged program may set this to match the label of another
  315. task with which it hopes to communicate.
  316. Smack Netlabel Exceptions
  317. You will often find that your labeled application has to talk to the outside,
  318. unlabeled world. To do this there's a special file /smack/netlabel where you can
  319. add some exceptions in the form of :
  320. @IP1 LABEL1 or
  321. @IP2/MASK LABEL2
  322. It means that your application will have unlabeled access to @IP1 if it has
  323. write access on LABEL1, and access to the subnet @IP2/MASK if it has write
  324. access on LABEL2.
  325. Entries in the /smack/netlabel file are matched by longest mask first, like in
  326. classless IPv4 routing.
  327. A special label '@' and an option '-CIPSO' can be used there :
  328. @ means Internet, any application with any label has access to it
  329. -CIPSO means standard CIPSO networking
  330. If you don't know what CIPSO is and don't plan to use it, you can just do :
  331. echo 127.0.0.1 -CIPSO > /smack/netlabel
  332. echo 0.0.0.0/0 @ > /smack/netlabel
  333. If you use CIPSO on your 192.168.0.0/16 local network and need also unlabeled
  334. Internet access, you can have :
  335. echo 127.0.0.1 -CIPSO > /smack/netlabel
  336. echo 192.168.0.0/16 -CIPSO > /smack/netlabel
  337. echo 0.0.0.0/0 @ > /smack/netlabel
  338. Writing Applications for Smack
  339. There are three sorts of applications that will run on a Smack system. How an
  340. application interacts with Smack will determine what it will have to do to
  341. work properly under Smack.
  342. Smack Ignorant Applications
  343. By far the majority of applications have no reason whatever to care about the
  344. unique properties of Smack. Since invoking a program has no impact on the
  345. Smack label associated with the process the only concern likely to arise is
  346. whether the process has execute access to the program.
  347. Smack Relevant Applications
  348. Some programs can be improved by teaching them about Smack, but do not make
  349. any security decisions themselves. The utility ls(1) is one example of such a
  350. program.
  351. Smack Enforcing Applications
  352. These are special programs that not only know about Smack, but participate in
  353. the enforcement of system policy. In most cases these are the programs that
  354. set up user sessions. There are also network services that provide information
  355. to processes running with various labels.
  356. File System Interfaces
  357. Smack maintains labels on file system objects using extended attributes. The
  358. Smack label of a file, directory, or other file system object can be obtained
  359. using getxattr(2).
  360. len = getxattr("/", "security.SMACK64", value, sizeof (value));
  361. will put the Smack label of the root directory into value. A privileged
  362. process can set the Smack label of a file system object with setxattr(2).
  363. len = strlen("Rubble");
  364. rc = setxattr("/foo", "security.SMACK64", "Rubble", len, 0);
  365. will set the Smack label of /foo to "Rubble" if the program has appropriate
  366. privilege.
  367. Socket Interfaces
  368. The socket attributes can be read using fgetxattr(2).
  369. A privileged process can set the Smack label of outgoing packets with
  370. fsetxattr(2).
  371. len = strlen("Rubble");
  372. rc = fsetxattr(fd, "security.SMACK64IPOUT", "Rubble", len, 0);
  373. will set the Smack label "Rubble" on packets going out from the socket if the
  374. program has appropriate privilege.
  375. rc = fsetxattr(fd, "security.SMACK64IPIN, "*", strlen("*"), 0);
  376. will set the Smack label "*" as the object label against which incoming
  377. packets will be checked if the program has appropriate privilege.
  378. Administration
  379. Smack supports some mount options:
  380. smackfsdef=label: specifies the label to give files that lack
  381. the Smack label extended attribute.
  382. smackfsroot=label: specifies the label to assign the root of the
  383. file system if it lacks the Smack extended attribute.
  384. smackfshat=label: specifies a label that must have read access to
  385. all labels set on the filesystem. Not yet enforced.
  386. smackfsfloor=label: specifies a label to which all labels set on the
  387. filesystem must have read access. Not yet enforced.
  388. These mount options apply to all file system types.
  389. Smack auditing
  390. If you want Smack auditing of security events, you need to set CONFIG_AUDIT
  391. in your kernel configuration.
  392. By default, all denied events will be audited. You can change this behavior by
  393. writing a single character to the /smack/logging file :
  394. 0 : no logging
  395. 1 : log denied (default)
  396. 2 : log accepted
  397. 3 : log denied & accepted
  398. Events are logged as 'key=value' pairs, for each event you at least will get
  399. the subject, the object, the rights requested, the action, the kernel function
  400. that triggered the event, plus other pairs depending on the type of event
  401. audited.