Version 4 (2.6.23-rc8-mm2) Smack: Simplified Mandatory Access Control Kernel
Subsystems (5)
Casey Schaufler
maintainerPATCH 1/1 Version 4 (2.6.23-rc8-mm2) Smack: Simplified Mandatory Access Control Kernel
From: Casey Schaufler <[email protected]>
Smack is the Simplified Mandatory Access Control Kernel.
Smack implements mandatory access control (MAC) using labels attached to tasks and data containers, including files, SVIPC, and other tasks. Smack is a kernel based scheme that requires an absolute minimum of application support and a very small amount of configuration data.
Smack uses extended attributes and
provides a set of general mount options, borrowing technics used elsewhere. Smack uses netlabel for CIPSO labeling. Smack provides a pseudo-filesystem smackfs that is used for manipulation of system Smack attributes.
The patch, patches for ls and sshd, a README, a startup script, and x86 binaries for ls and sshd are also available on
http:/www.schaufler-ca.com
The patch has been tested with 2.6.22, 2.6.23-rc8, and 2.6.23-rc8-mm2. Development has been done using Fedora Core 7 in a virtual machine environment and on an old Sony laptop.
Smack provides mandatory access controls based on the label attached to a task and the label attached to the object it is attempting to access. Smack labels are deliberately short (1-23 characters) text strings. Single character labels using special characters are reserved for system use. The only operation applied to Smack labels is equality comparison. No wildcards or expressions, regular or otherwise, are used.
A file always gets the Smack label of the task that created it.
Smack defines and uses these labels:
"*" - pronounced "star"
"_" - pronounced "floor"
"^" - pronounced "hat"
"?" - pronounced "huh"The access rules enforced by Smack are, in order:
1. Any access requested by a task labeled "*" is denied.
2. A read or execute access requested by a task labeled "^" is permitted.
3. A read or execute access requested on an object labeled "_" is permitted.
4. Any access requested on an object labeled "*" is permitted.
5. Any access requested by a task on an object with the same label is permitted.
6. Any access requested that is explicitly defined in the loaded rule set is permitted.
7. Any other access is denied.
Rules may be explicitly defined by writing subject,object,access triples to /smack/load.
Smack rule sets can be easily defined that describe Bell&LaPadula sensitivity, Biba integrity, and a variety of interesting configurations. Smack rule sets can be modified on the fly to accomodate changes in the operating environment or even the time of day.
Some practical use cases:
Hierarchical levels. The less common of the two usual uses for MLS systems is to define hierarchical levels, often unclassified, confidential, secret, and so on. To set up smack to support this, these rules could be defined:
C Unclass rx S C rx S Unclass rx TS S rx TS C rx TS Unclass rx
A TS process can read S, C, and Unclass data, but cannot write it. An S process can read C and Unclass. Note that specifying that TS can read S and S can read C does not imply TS can read C, it has to be explicitly stated.
Non-hierarchical categories. This is the more common of the usual uses for an MLS system. Since the default rule is that a subject cannot access an object with a different label no access rules are required to implement compartmentalization.
A case that the Bell & LaPadula policy does not allow is demonstrated with this Smack access rule:
A case that Bell&LaPadula does not allow that Smack does:
ESPN ABC r
ABC ESPN rOn my portable video device I have two applications, one that shows ABC programming and the other ESPN programming. ESPN wants to show me sport stories that show up as news, and ABC will only provide minimal information about a sports story if ESPN is covering it. Each side can look at the other's info, neither can change the other. Neither can see what FOX is up to, which is just as well all things considered.
Another case that I especially like:
SatData Guard w
Guard Publish w
A program running with the Guard label opens a UDP socket and accepts messages sent by a program running with a SatData label. The Guard program inspects the message to ensure it is wholesome and if it is sends it to a program running with the Publish label. This program then puts the information passed in an appropriate place. Note that the Guard program cannot write to a Publish file system object because file system semanitic require read as well as write.
The four cases (categories, levels, mutual read, guardbox) here are all quite real, and problems I've been asked to solve over the years. The first two are easy to do with traditonal MLS systems while the last two you can't without invoking privilege, at least for a while.
---
This patch includes changes made by Paul Moore <[email protected]> in support of a more comfortable interface to initialize the CIPSO code from within the kernel. The changes in the net directory are Pauls, as is the update to netlabel.h
This is clean relative to checkpatch.pl.
The Documentation/Smack.txt is significantly expanded.
Thank you for all your kind words about Smack.
Documentation/Smack.txt | 521 +++++ include/net/netlabel.h | 47 net/ipv4/cipso_ipv4.c | 4 net/netlabel/netlabel_cipso_v4.c | 2 net/netlabel/netlabel_cipso_v4.h | 3 net/netlabel/netlabel_domainhash.h | 1 net/netlabel/netlabel_kapi.c | 174 + security/Kconfig | 1 security/Makefile | 2 security/smack/Kconfig | 10 security/smack/Makefile | 7 security/smack/smack.h | 226 ++ security/smack/smack_access.c | 340 +++ security/smack/smack_lsm.c | 2670 +++++++++++++++++++++++++++ security/smack/smackfs.c | 1165 +++++++++++ 15 files changed, 5164 insertions(+), 9 deletions(-)
Documentation/Smack.txt +521 -0
@@ -0,0 +1,521 @@ + + + "Good for you, you've decided to clean the elevator!" + - The Elevator, from Dark Star + +Smack is the the Simplified Mandatory Access Control Kernel. +Smack is a kernel based implementation of mandatory access +control that includes simplicity in its primary design goals. + +Smack does not implement Domain Type Enforcement (DTE). If +you want DTE Linux has an implementation called SELinux. +Those who really want DTE are encouraged to use SELinux. +Those who don't know what DTE is are encouraged to compare +SELinux with Smack to determine which mechanisms are best +suited to the problem at hand. + +Smack consists of three major components: + - The kernel + - A start-up script and a few modified applications + - Configuration data + +The kernel component of Smack is implemented as a Linux +Security Modules (LSM) module. It requires netlabel and +works best with file systems that support extended attributes, +although xattr support is not strictly required. The Smack +patch is (currently) self contained, except for Kconfig +and Makefile changes in the security directory. It is safe +to run a Smack kernel under a "vanilla" distribution. +Smack kernels use the CIPSO IP option. Some network +configurations are intolerant of IP options and can impede +access to systems that use them as Smack does. + +The startup script etc-init.d-smack should be installed +in /etc/init.d/smack and should be invoked early in the +start-up process. On Fedora rc5.d/S02smack is recommended. +This script ensures that certain devices have the correct +Smack attributes and loads the Smack configuration if +any is defined. + +A version of "ls" that provides a "-M" option to display +Smack labels on long listing is available. + +A hacked version of sshd that allows network logins by users +with specific Smack labels is available. This version does +not work for scp. You must set the /etc/ssh/sshd_config +line: + UsePrivilegeSeparation no + +The format of /etc/smack/usr is: + + username smack + +In keeping with the intent of Smack, configuration data is +minimal and not strictly required. The most important +configuration step is mounting the smackfs pseudo filesystem. + +Add this line to /etc/fstab: + + smackfs /smack smackfs smackfsdef=* 0 0 + +and create the /smack directory for mounting. + +Smack uses extended attributes (xattrs) to store file labels. +The command to set a Smack label on a file is: + + # attr -S -s SMACK64 -V "value" path + +NOTE: Smack labels are limited to 23 characters. The attr command + does not enforce this restriction and can be used to set + invalid Smack labels on files. + +The smackfs filesystem treats symbolic links in a special way. +The Smack label of the process is appended to the link value +during resolution. To provide a /tmp that is available to users +with multiple labels: + + # mkdir /moldy + # mv /tmp /moldy/_ + # ln -s /smack/tmp /tmp + +For each label users are going to use: + + # mkdir /moldy/label + # chmod <appropriate-value> /moldy/label + # attr -S -s SMACK64 -V "label" /moldy/label + +If you don't do anything special all users will get the floor ("_") +label when they log in. If you do want to log in via the hacked ssh +at other labels use the attr command to set the smack value on the +home directory and it's contents. + +You can add access rules in /etc/smack/accesses. They take the form: + + subjectlabel objectlabel access + +access is a combination of the letters rwxa which specify the +kind of access permitted a subject with subjectlabel on an +object with objectlabel. If there is no rule no access is allowed. + +A process can see the smack label it is running with by +reading /proc/self/attr/current. A privileged process can +set the process smack by writing there. + +From the Smack Whitepaper: + +The Simplified Mandatory Access Control Kernel + +Casey Schaufler [email protected] + +Mandatory Access Control + +Computer systems employ a variety of schemes to constrain how information is +shared among the people and services using the machine. Some of these schemes +allow the program or user to decide what other programs or users are allowed +access to pieces of data. These schemes are called discretionary access +control mechanisms because the access control is specified at the discretion +of the user. Other schemes do not leave the decision regarding what a user or +program can access up to users or programs. These schemes are called mandatory +access control mechanisms because you don't have a choice regarding the users +or programs that have access to pieces of data. + +Bell & LaPadula + +From the middle of the 1980's until the turn of the century Mandatory Access +Control (MAC) was very closely associated with the Bell & LaPadula security +model, a mathematical description of the United States Department of Defense +policy for marking paper documents. MAC in this form enjoyed a following +within the Capital Beltway and Scandinavian supercomputer centers but was +often sited as failing to address general needs. + +Domain Type Enforcement + +Around the turn of the century Domain Type Enforcement (DTE) became popular. +This scheme organizes users, programs, and data into domains that are +protected from each other. This scheme has been widely deployed as a component +of popular Linux distributions. The administrative overhead required to +maintain this scheme and the detailed understanding of the whole system +necessary to provide a secure domain mapping leads to the scheme being +disabled or used in limited ways in the majority of cases. + +Smack + +Smack is a Mandatory Access Control mechanism designed to provide useful MAC +while avoiding the pitfalls of its predecessors. The limitations of Bell & +LaPadula are addressed by providing a scheme whereby access can be controlled +according to the requirements of the system and its purpose rather than those +imposed by an arcane government policy. The complexity of Domain Type +Enforcement and avoided by defining access controls in terms of the access +modes already in use. + +Smack Terminology + +The jargon used to talk about Smack will be familiar to those who have dealt +with other MAC systems and shouldn't be too difficult for the uninitiated to +pick up. There are four terms that are used in a specific way and that are +especially important: + + Subject: A subject is an active entity on the computer system. + On Smack a subject is a task, which is in turn the basic unit + of execution. + + Object: An object is a passive entity on the computer system. + On Smack files of all types, IPC, and tasks can be objects. + + Access: Any attempt by a subject to put information into or get + information from an object is an access. + + Label: Data that identifies the Mandatory Access Control + characteristics of a subject or an object. + +These definitions are consistent with the traditional use in the security +community. There are also some terms from Linux that are likely to crop up: + + Capability: A task that possesses a capability has permission to + violate an aspect of the system security policy, as identified by + the specific capability. A task that possesses one or more + capabilities is a privileged task, whereas a task with no + capabilities is an unprivileged task. + + Privilege: A task that is allowed to violate the system security + policy is said to have privilege. As of this writing a task can + have privilege either by possessing capabilities or by having an + effective user of root. + +Smack Basics + +Smack is an extension to a Linux system. It enforces additional restrictions +on what subjects can access which objects, based on the labels attached to +each of the subject and the object. + +Labels + +Smack labels are ASCII character strings, one to twenty-three characters in +length. Single character labels using special characters, that being anything +other than a letter or digit, are reserved for use by the Smack development +team. Smack labels are unstructured, case sensitive, and the only operation +ever performed on them is comparison for equality. There are some predefined +labels: + + _ Pronounced "floor", a single underscore character. + ^ Pronounced "hat", a single circumflex character. + * Pronounced "star", a single asterisk character. + ? Pronounced "huh", a single question mark character. + +Every task on a Smack system is assigned a label. System tasks, such as +init(8) and systems daemons, are run with the floor ("_") label. User tasks +are assigned labels according to the specification found in the +/etc/smack/user configuration file. + +Access Rules + +Smack uses the traditional access modes of Linux. These modes are read, +execute, write, and occasionally append. There are a few cases where the +access mode may not be obvious. These include: + + Signals: A signal is a write operation from the subject task to + the object task. + Internet Domain IPC: Transmission of a packet is considered a + write operation from the source task to the destination task. + +Smack restricts access based on the label attached to a subject and the label +attached to the object it is trying to access. The rules enforced are, in +order: + + 1. Any access requested by a task labeled "*" is denied. + 2. A read or execute access requested by a task labeled "^" + is permitted. + 3. A read or execute access requested on an object labeled "_" + is permitted. + 4. Any access requested on an object labeled "*" is permitted. + 5. Any access requested by a task on an object with the same + label is permitted. + 6. Any access requested that is explicitly defined in the loaded + rule set is permitted. + 7. Any other access is denied. + +Smack Access Rules + +With the isolation provided by Smack access separation is simple. There are +many interesting cases where limited access by subjects to objects with +different labels is desired. One example is the familiar spy model of +sensitivity, where a scientist working on a highly classified project would be +able to read documents of lower classifications and anything she writes will +be "born" highly classified. To accommodate such schemes Smack includes a +mechanism for specifying rules allowing access between labels. + +Access Rule Format + +The format of an access rule is: + + subject-label object-label access + +Where subject-label is the Smack label of the task, object-label is the Smack +label of the thing being accessed, and access is a string specifying the sort +of access allowed. The Smack labels are limited to 23 characters. The access +specification is searched for letters that describe access modes: + + a: indicates that append access should be granted. + r: indicates that read access should be granted. + w: indicates that write access should be granted. + x: indicates that execute access should be granted. + +Access mode specifications can be in any order. Examples of acceptable rules +are: + + TopSecret Secret rx + Secret Unclass r + Manager Game x + User HR w + Odd spells waxbeans + New Old rrrrr + Closed Off none + +Order does matter and letters that do not specify an access mode are ignored. +Examples of unacceptable rules are: + + Top Secret Secret rx + Ace Ace r + +Spaces are not allowed in labels. Since a subject always has access to files +with the same label specifying a rule for that case is pointless. + +Applying Access Rules + +The developers of Linux rarely define new sorts of things, usually importing +schemes and concepts from other systems. Most often, the other systems are +variants of Unix. Unix has many endearing properties, but consistency of +access control models is not one of them. Smack strives to treat accesses as +uniformly as is sensible while keeping with the spirit of the underlying +mechanism. + +File system objects including files, directories, named pipes, symbolic links, +and devices require access permissions that closely match those used by mode +bit access. To open a file for reading read access is required on the file. To +search a directory requires execute access. Creating a file with write access +requires both read and write access on the containing directory. Deleting a +file requires read and write access to the file and to the containing +directory. It is possible that a user may be able to see that a file exists +but not any of its attributes by the circumstance of having read access to the +containing directory but not to the differently labeled file. This is an +artifact of the file name being data in the directory, not a part of the file. + +IPC objects, message queues, semaphore sets, and memory segments exist in flat +namespaces and access requests are only required to match the object in +question. + +Process objects reflect tasks on the system and the Smack label used to access +them is the same Smack label that the task would use for its own access +attempts. Sending a signal via the kill() system call is a write operation +from the signaler to the recipient. Debugging a process requires both reading +and writing. Creating a new task is an internal operation that results in two +tasks with identical Smack labels and requires no access checks. + +Sockets are data structures attached to processes and sending a packet from +one process to another requires that the sender have write access to the +receiver. The receiver is not required to have read access to the sender. + +Setting Access Rules + +The configuration file /etc/smack/accesses contains the rules to be set at +system startup. The contents are written to the special file /smack/load. +Rules can be written to /smack/load at any time and take effect immediately. +For any pair of subject and object labels there can be only one rule, with the +most recently specified overriding any earlier specification. + +Task Attribute + +The Smack label of a process can be read from /proc/<pid>/attr/current. A +process can read its own Smack label from /proc/self/attr/current. A +privileged process can change its own Smack label by writing to +/proc/self/attr/current but not the label of another process. + +File Attribute + +The Smack label of a filesystem object is stored as an extended attribute +named SMACK64 on the file. This attribute is in the security namespace. It can +only be changed by a process with privilege. + +Privilege + +A process with CAP_MAC_OVERRIDE is privileged. + +Smack Networking + +As mentioned before, Smack enforces access control on network protocol +transmissions. Every packet sent by a Smack process is tagged with its Smack +label. This is done by adding a CIPSO tag to the header of the IP packet. Each +packet received is expected to have a CIPSO tag that identifies the label and +if it lacks such a tag the network ambient label is assumed. Before the packet +is delivered a check is made to determine that a subject with the label on the +packet has write access to the receiving process and if that is not the case +the packet is dropped. + +CIPSO Configuration + +It is normally unnecessary to specify the CIPSO configuration. The default +values used by the system handle all internal cases. Smack will compose CIPSO +label values to match the Smack labels being used without administrative +intervention. Unlabeled packets that come into the system will be given the +ambient label. + +Smack requires configuration in the case where packets from a system that is +not smack that speaks CIPSO may be encountered. Usually this will be a Trusted +Solaris system, but there are other, less widely deployed systems out there. +CIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level, +and a category set with each packet. The DOI is intended to identify a group +of systems that use compatible labeling schemes, and the DOI specified on the +smack system must match that of the remote system or packets will be +discarded. The DOI is 3 by default. The value can be read from /smack/doi and +can be changed by writing to /smack/doi. + +The label and category set are mapped to a Smack label as defined in +/etc/smack/cipso. + +A Smack/CIPSO mapping has the form: + + smack level[/category[,category]*] + +Smack does not expect the level or category sets to be related in any +particular way and does not assume or assign accesses based on them. Some +examples of mappings: + + TopSecret 7 + TS/A,B 7/1,2 + SecBDE 5/2,4,6 + RAFTERS 7/12,26 + +The "/" and "," characters are permitted in a Smack label but have no special +meaning. + +The mapping of Smack labels to CIPSO values is defined by writing to +/smack/cipso. + +In addition to explicit mappings Smack supports direct CIPSO mappings. One +CIPSO level is used to indicate that the category set passed in the packet is +in fact an encoding of the Smack label. The level used is 250 by default. The +value can be read from /smack/direct and changed by writing to /smack/direct. + +Socket Attributes + +There are three attributes that are associated with sockets. These attributes +can only be set by privileged tasks, but any task can read them for their own +sockets. + + SMACK64IPIN: The Smack label of the task object. A privileged + program that will enforce policy may set this to the star label. + + SMACK64IPOUT: The Smack label transmitted with outgoing packets. + A privileged program may set this to match the label of another + task with which it hopes to communicate. + + SMACK64PACKET: The Smack label of the last received packet, but + only if it can be provided reliably. If a reliable value is not + available an attempt to retrieve this attribute will fail. + +Polyinstantiation + +The filesystem namespace is normally shared by all processes on the system +regardless of their attributes. Traditionally all processes are allowed to +create files in the special directory /tmp. This is a problem for any MAC +system because allowing all processes access to /tmp makes it easy for them to +see information that they would otherwise be isolated from. + +Symbolic links in the /smackfs file system behave differently than they do +elsewhere. A symlink in /smack will always have the Smack label of the task +accessing it appended to the content of the symlink when it is read. Thus, if +/smack/tmp is defined to point to /moldy/, an access by a floor process will +see /moldy/_ and an access by a task with the label cheese will see +/moldy/cheese. + +Currently Smack does nothing to ensure that the destinations pointed to by the +symlinks in /smack actually exist. In the default Smack configuration /tmp is +a symlink to /smack/tmp, which in turn is a symlink to /moldy/, but since it +is a symlink on smackfs it will append the label of the task to the content. +The directory /moldy should have a subdirectory created for each Smack label +that is expected to be used on the system, and at the very least /moldy/_ and +/moldy/^ should be made available. + +Writing Applications for Smack + +There are three sorts of applications that will run on a Smack system. How an +application interacts with Smack will determine what it will have to do to +work properly under Smack. + +Smack Ignorant Applications + +By far the majority of applications have no reason whatever to care about the +unique properties of Smack. Since invoking a program has no impact on the +Smack label associated with the process the only concern likely to arise is +whether the process has execute access to the program. + +Smack Relevant Applications + +Some programs can be improved by teaching them about Smack, but do not make +any security decisions themselves. The utility ls(1) is one example of such a +program. + +Smack Enforcing Applications + +These are special programs that not only know about Smack, but participate in +the enforcement of system policy. In most cases these are the programs that +set up user sessions. There are also network services that provide information +to processes running with various labels. + +File System Interfaces + +Smack maintains labels on file system objects using extended attributes. The +Smack label of a file, directory, or other file system object can be obtained +using getxattr(2). + + len = getxattr("/", "security.SMACK64", value, sizeof (value)); + +will put the Smack label of the root directory into value. A privileged +process can set the Smack label of a file system object with setxattr(2). + + len = strlen("Rubble"); + rc = setxattr("/foo", "security.SMACK64", "Rubble", len, 0); + +will set the Smack label of /foo to "Rubble" if the program has appropriate +privilege. + +Socket Interfaces + +The socket attributes can be read using fgetxattr(2). + + len = fgetxattr(fd, "security.SMACK64PACKET", value, sizeof (value)); + +will put the Smack label of the most recently received packet if it is +available into value. A privileged process can set the Smack label of outgoing +packets with fsetxattr(2). + + len = strlen("Rubble"); + rc = fsetxattr(fd, "security.SMACK64IPOUT", "Rubble", len, 0); + +will set the Smack label "Rubble" on packets going out from the socket if the +program has appropriate privilege. + + rc = fsetxattr(fd, "security.SMACK64IPIN, "*", strlen("*"), 0); + +will set the Smack label "*" as the object label against which incoming +packets will be checked if the program has appropriate privilege. + +Administration + +Smack supports some mount options: + + smackfsdef=label: specifies the label to give files that lack + the Smack label extended attribute. + + smackfsroot=label: specifies the label to assign the root of the + file system if it lacks the Smack extended attribute. + + smackfshat=label: specifies a label that must have read access to + all labels set on the filesystem. Not yet enforced. + + smackfsfloor=label: specifies a label to which all labels set on the + filesystem must have read access. Not yet enforced. + +These mount options apply to all file system types. +
include/net/netlabel.h +41 -6
71 lines not on this page · raw message
net/ipv4/cipso_ipv4.c +2 -2
@@ -557,8 +557,8 @@ int cipso_v4_doi_remove(u32 doi,spin_unlock (&cipso_v4_doi_list_lock);list_for_each_entry_rcu (dom_iter, &doi_def->dom_list, list)if (dom_iter->valid) -netlbl_domhsh_remove (dom_iter->domain, - audit_info); +netlbl_cfg_map_del (dom_iter->domain, + audit_info);cipso_v4_cache_invalidate ();rcu_read_unlock ();
net/netlabel/netlabel_cipso_v4.c +1 -1
@@ -89,7 +89,7 @@ static const struct nla_policy netlbl_ci* safely. * */ -static void netlbl_cipsov4_doi_free (struct rcu_head *entry) +void netlbl_cipsov4_doi_free (struct rcu_head *entry) {struct cipso_v4_doi *ptr;
net/netlabel/netlabel_cipso_v4.h +3 -0
@@ -163,4 +163,7 @@ enum {/* NetLabel protocol functions */ int netlbl_cipsov4_genl_init (void ); +/* Free the memory associated with a CIPSOv4 DOI definition */ +void netlbl_cipsov4_doi_free (struct rcu_head *entry); +#endif
net/netlabel/netlabel_domainhash.h +1 -0
@@ -61,6 +61,7 @@ int netlbl_domhsh_add(struct netlbl_dom_ struct netlbl_audit *audit_info);int netlbl_domhsh_add_default (struct netlbl_dom_map *entry,struct netlbl_audit *audit_info); +int netlbl_domhsh_remove (const char *domain,struct netlbl_audit *audit_info);int netlbl_domhsh_remove_default (struct netlbl_audit *audit_info);struct netlbl_dom_map *netlbl_domhsh_getentry (const char *domain); int netlbl_domhsh_walk(u32 *skip_bkt,
net/netlabel/netlabel_kapi.c +174 -0
190 lines not on this page · raw message
security/Kconfig +1 -0
@@ -104,6 +104,7 @@ config SECURITY_ROOTPLUG If you are unsure how to answer this question, answer N. source security/selinux/Kconfig +source security/smack/Kconfig endmenu
security/Makefile +2 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_KEYS) += keys/ subdir-$(CONFIG_SECURITY_SELINUX) += selinux +subdir-$(CONFIG_SECURITY_SMACK) += smack # if we don't select a security model, use the default capabilities ifneq ($(CONFIG_SECURITY),y)
@@ -14,5 +15,6 @@ endif obj-$(CONFIG_SECURITY) += security.o dummy.o inode.o # Must precede capability.o in order to stack properly. obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o +obj-$(CONFIG_SECURITY_SMACK) += commoncap.o smack/built-in.o obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o
security/smack/Kconfig +10 -0
@@ -0,0 +1,10 @@ +config SECURITY_SMACK + bool "Simplified Mandatory Access Control Kernel Support" + depends on NETLABEL && SECURITY_NETWORK + default n + help + This selects the Simplified Mandatory Access Control Kernel. + Smack is useful for sensitivity, integrity, and a variety + of other mandatory security schemes. + If you are unsure how to answer this question, answer N. +
security/smack/Makefile +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for the SMACK LSM +# + +obj-$(CONFIG_SECURITY_SMACK) := smack.o + +smack-y := smack_lsm.o smack_access.o smackfs.o
security/smack/smack_access.c +340 -0
340 lines not on this page · raw message
security/smack/smackfs.c +1165 -0
1,165 lines not on this page · raw message
security/smack/smack.h +226 -0
226 lines not on this page · raw message
security/smack/smack_lsm.c +2670 -0
418 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 10 lines · Casey Schaufler
From: Casey Schaufler <[email protected]>
Smack is the Simplified Mandatory Access Control Kernel.
Smack implements mandatory access control (MAC) using labels attached to tasks and data containers, including files, SVIPC, and other tasks. Smack is a kernel based scheme that requires an absolute minimum of application support and a very small amount of configuration data.
I _really_ don't like what you are doing with these symlinks. For one thing, you have no exclusion between reading the list entries and modifying them. For another... WTF is filesystem making assumptions about the locations where the things are mounted? Hell, even if you override your tmp symlink, what happens if we want it in two chroot jails with different layouts?
I really don't get it; why not simply have something like /smack/tmp.link resolve to tmp/<label> and have userland bind or mount whatever you bloody like on /smack/tmp? No problems with absolute paths, can be used in chroot jails with whatever layouts, ditto for namespaces, etc. and both symlink and directory get created at the same time (by one name). Hell, if you keep a reference to dentry of directory in the data associated with symlink, you can simply switch nd->dentry to that, drop the old one and grab the reference to page containing label and return it via nd_set_link(). No need to play with allocations, strcat, yadda, yadda. readlink() can stuff the ->d_name of the same dentry plus / plus label directly into user buffer; again, no allocations needed and works fine anywhere.
Casey Schaufler
maintainerQuoted 12 lines · --- Al Viro
Quoted 10 lines · Casey Schaufler
From: Casey Schaufler <[email protected]>
Smack is the Simplified Mandatory Access Control Kernel.
Smack implements mandatory access control (MAC) using labels attached to tasks and data containers, including files, SVIPC, and other tasks. Smack is a kernel based scheme that requires an absolute minimum of application support and a very small amount of configuration data.
Quoted 6 lines
I _really_ don't like what you are doing with these symlinks.
For one thing, you have no exclusion between reading the list entries and modifying them.
That's easy enough to fix. I'll do it.
Quoted 3 lines
For another... WTF is filesystem
making assumptions about the locations where the things are mounted?
I assume by this that you're objecting to the initialization of /smack/tmp to point to /moldy/<label>.
Over the years I've seen a number of cases where failure to set up /tmp result in unhappy consequences. If /tmp is anything other than a real directory on the root filesystem it is important that special care be taken for the case where things don't get set up right for some reason. By including a specific, if perhaps arbitrary, default it becomes easier to create a configuration that survives the unexpected.
Quoted 1 line
Hell, even if you override your tmp symlink,
Which is something that I expect virtually everyone to do.
Quoted 2 lines
what
happens if we want it in two chroot jails with different layouts?
As you can only have /smack mounted once, this isn't an issue, but it does present an interesting use case that brings the one mount limitation into question. I'll add addressing this to the short term todo list.
Quoted 3 lines
I really don't get it; why not simply have something like /smack/tmp.link resolve to tmp/<label> and have userland bind or mount whatever you bloody like on /smack/tmp?
Because you throw "simple" out the window when you require userland assistance to perform this function.
Quoted 11 lines
No problems with absolute
paths, can be used in chroot jails with whatever layouts, ditto for namespaces, etc. and both symlink and directory get created at the same time (by one name). Hell, if you keep a reference to dentry of directory in the data associated with symlink, you can simply switchnd->dentryto that, drop the old one and grab the reference to page containing label and return it viand_set_link(). No need to play with allocations, strcat, yadda, yadda.readlink()can stuff the ->d_name of the same dentry plus / plus label directly into user buffer; again, no allocations needed and works fine anywhere.
I'm having some trouble seeing how the 60 lines of code in smackfs dealing with symlinks would be improved by your suggestions. I certainly don't see how requiring userland intervention would do anything but make it bigger and less reliable.
Casey Schaufler
[email protected]
Quoted 7 lines · Casey Schaufler
Quoted 2 lines
what
happens if we want it in two chroot jails with different layouts?As you can only have /smack mounted once, this isn't an issue, but it does present an interesting use case that brings the one mount limitation into question. I'll add addressing this to the short term todo list.
Of course you can mount it more than once. Just bind the sucker and you are done.
Quoted 6 lines
Quoted 3 lines
I really don't get it; why not simply have something like /smack/tmp.link resolve to tmp/<label> and have userland bind or mount whatever you bloody like on /smack/tmp?
Because you throw "simple" out the window when you require userland assistance to perform this function.
Any more than having /tmp replaced with a symlink?
Quoted 4 lines
I'm having some trouble seeing how the 60 lines of code in smackfs dealing with symlinks would be improved by your suggestions. I certainly don't see how requiring userland intervention would do anything but make it bigger and less reliable.
_What_ userland intervention? Mounting stuff under /smack/tmp and not under your /moldy? Having /tmp replaced with symlink to /smack/tmp.link instead of replacing it with a symlink to /smack/tmp?
Absolute paths in that kind of thing are _wrong_. You know where the things are on your fs. You don't know if anything else will be visible, let alone whether it will be at the same place in all chroots or namespaces. And no, you _can't_ make sure that fs is visible only in one place. No fs can or has any business even trying.
Quoted 5 lines
Absolute paths in that kind of thing are _wrong_. You know where the things are on your fs. You don't know if anything else will be visible, let alone whether it will be at the same place in all chroots or namespaces. And no, you _can't_ make sure that fs is visible only in one place. No fs can or has any business even trying.
What I don't understand here is why we need the hacks when we already support sufficient mount magic to give each login session its own private /tmp ?
Quoted 9 lines · Alan Cox
Quoted 5 lines
Absolute paths in that kind of thing are _wrong_. You know where the things are on your fs. You don't know if anything else will be visible, let alone whether it will be at the same place in all chroots or namespaces. And no, you _can't_ make sure that fs is visible only in one place. No fs can or has any business even trying.
What I don't understand here is why we need the hacks when we already support sufficient mount magic to give each login session its own private /tmp ?
Presumably his context can change within a login session? If not, it's indeed simply worthless, absolute paths or not.
Casey Schaufler
maintainerQuoted 10 lines · --- Alan Cox
Quoted 1 line
Absolute paths in that kind of thing are _wrong_. You know where the
things
Quoted 4 lines
are on your fs. You don't know if anything else will be visible, let alone whether it will be at the same place in all chroots or namespaces. And no, you _can't_ make sure that fs is visible only in one place. No fs can or has any business even trying.
What I don't understand here is why we need the hacks when we already support sufficient mount magic to give each login session its own private /tmp ?
An embedded system that does not have user logins but that does have applications that require separation, perhaps a moble communication device with application download capability, is just one example where the smack symlink implementation provides the required function without requiring application support.
Casey Schaufler
[email protected]
Quoted 5 lines
An embedded system that does not have user logins but that does have applications that require separation, perhaps a moble communication device with application download capability, is just one example where the smack symlink implementation provides the required function without requiring application support.
I don't see what is such a problem here. For your mobile example you'd give the application download side its own /tmp via mount.
Its actually better this is done in user space as its more flexible that way and can be tuned arbitarily to meet interesting or bizarre real world cases.
Alan
Casey Schaufler
maintainerQuoted 6 lines · --- Alan Cox
Quoted 5 lines
An embedded system that does not have user logins but that does have applications that require separation, perhaps a moble communication device with application download capability, is just one example where the smack symlink implementation provides the required function without requiring application support.
Quoted 6 lines
I don't see what is such a problem here. For your mobile example you'd give the application download side its own /tmp via mount.
Its actually better this is done in user space as its more flexible that way and can be tuned arbitarily to meet interesting or bizarre real world cases.
I admit to being impressed by the wide variety of mount options currently available. In many cases this will be the best approach. /tmp is a typical use for a smack symlink, but not the only one.
Casey Schaufler
[email protected]
Casey Schaufler
maintainerQuoted 12 lines · --- Al Viro
Quoted 7 lines · Casey Schaufler
Quoted 2 lines
what
happens if we want it in two chroot jails with different layouts?As you can only have /smack mounted once, this isn't an issue, but it does present an interesting use case that brings the one mount limitation into question. I'll add addressing this to the short term todo list.
Of course you can mount it more than once. Just bind the sucker and you are done.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I really don't get it; why not simply have something like /smack/tmp.link resolve to tmp/<label> and have userland bind or mount whatever you bloody like on /smack/tmp?
Because you throw "simple" out the window when you require userland assistance to perform this function.
Any more than having /tmp replaced with a symlink?
Yes. By the way, there's nothing that really requires that you use a /smack symlink if you don't want to. /tmp can still be a real directory, a mount point, a symlink to /var/tmp, or whatever else you want it to be if that suits your needs better. For the simplest scenarios /tmp -> /smack/tmp -> /moldy/<label> has every other scheme I've seen throughly beaten.
Quoted 7 lines
Quoted 4 lines
I'm having some trouble seeing how the 60 lines of code in smackfs dealing with symlinks would be improved by your suggestions. I certainly don't see how requiring userland intervention would do anything but make it bigger and less reliable.
_What_ userland intervention? Mounting stuff under /smack/tmp and not under your /moldy?
Who said anything about mounting under /moldy? I never did.
Quoted 8 lines
Having /tmp replaced with symlink to /smack/tmp.link instead of replacing it with a symlink to /smack/tmp?
Absolute paths in that kind of thing are _wrong_. You know where the things are on your fs. You don't know if anything else will be visible, let alone whether it will be at the same place in all chroots or namespaces. And no, you _can't_ make sure that fs is visible only in one place. No fs can or has any business even trying.
Is the objection that there is a default value coded in?
Casey Schaufler
[email protected]
Quoted 11 lines · Casey Schaufler
Quoted 4 lines
Quoted 2 lines
Because you throw "simple" out the window when you require userland assistance to perform this function.
Any more than having /tmp replaced with a symlink?
Yes. By the way, there's nothing that really requires that you use a /smack symlink if you don't want to. /tmp can still be a real directory, a mount point, a symlink to
/var/tmp, or whatever else you want it to be if that suits your needs better. For the simplest scenarios /tmp -> /smack/tmp -> /moldy/<label> has every other scheme I've seen throughly beaten.
And your point is? If you don't use it, you get exact same complexity in both setups.
Quoted 4 lines
Quoted 2 lines
_What_ userland intervention? Mounting stuff under /smack/tmp and not under your /moldy?
Who said anything about mounting under /moldy? I never did.
Sigh... So put the binding into fstab and be done with that.
Quoted 10 lines
Quoted 8 lines
Having /tmp replaced with symlink to /smack/tmp.link instead of replacing it with a symlink to /smack/tmp?
Absolute paths in that kind of thing are _wrong_. You know where the things are on your fs. You don't know if anything else will be visible, let alone whether it will be at the same place in all chroots or namespaces. And no, you _can't_ make sure that fs is visible only in one place. No fs can or has any business even trying.
Is the objection that there is a default value coded in?
Right now the main objection is about your lack of ability to read. Which part of "it can be mounted in different chroots/namespaces, therefore having absolute paths doesn't work" is too hard to understand?
No, it's not about having a default. It's about keeping an absolute pathname in virtual fs, having all instances autosoddingmatically sharing it _and_ having change attempt in any instance automatically affect all of them. If you have that kind of sharing, don't pretend that your mechanism really allows absolute pathnames.
Casey Schaufler
maintainerQuoted 13 lines · --- Al Viro
Quoted 11 lines · Casey Schaufler
Quoted 4 lines
Quoted 2 lines
Because you throw "simple" out the window when you require userland assistance to perform this function.
Any more than having /tmp replaced with a symlink?
Yes. By the way, there's nothing that really requires that you use a /smack symlink if you don't want to. /tmp can still be a real directory, a mount point, a symlink to
/var/tmp, or whatever else you want it to be if that suits your needs better. For the simplest scenarios /tmp -> /smack/tmp -> /moldy/<label> has every other scheme I've seen throughly beaten.
Quoted 2 lines
And your point is? If you don't use it, you get exact same complexity in both setups.
Thank you for your patience. Let me see if I can get my point across.
The intended Smack scenario:
1. Create /moldy at "_"
2. For each label you care about
2a. Create /moldy/<label>
2b. Set the label of /moldy/<label> to <label>
3. ln -s /smack/tmp /tmp
All processes are now redirected into the appropriate place regardless of how they come into being. It doesn't matter if the "session" starts from busybox, login, sshd, xdm, crontab, or out of an init script.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
_What_ userland intervention? Mounting stuff under /smack/tmp and not
under
Quoted 3 lines
Quoted 1 line
your /moldy?
Who said anything about mounting under /moldy? I never did.
Sigh... So put the binding into fstab and be done with that.
Are you suggesting that /smack/tmp.link below is a mount point, and that appropriate directories get mounted there?
1. Create /moldy at "_"
2. For each label you care about
2a. Create /moldy/<label>
2b. Set the label of /moldy/<label> to <label> 2c. mount --bind /moldy/<label> /smack/tmp.link/<label>
3. ln -s /smack/tmp.link /tmp
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Having /tmp replaced with symlink to /smack/tmp.link instead of replacing it with a symlink to /smack/tmp?
Absolute paths in that kind of thing are _wrong_. You know where the
things
Quoted 1 line
Quoted 1 line
are on your fs. You don't know if anything else will be visible, let
alone
Quoted 8 lines
Quoted 1 line
Quoted 1 line
whether it will be at the same place in all chroots or namespaces. And
no,
Quoted 4 lines
Quoted 2 lines
you _can't_ make sure that fs is visible only in one place. No fs can or has any business even trying.
Is the objection that there is a default value coded in?
Right now the main objection is about your lack of ability to read.
Now you sound like my daughter. :-)
Quoted 3 lines
Which
part of "it can be mounted in different chroots/namespaces, therefore having absolute paths doesn't work" is too hard to understand?
It's the content of a symlink, and that can be just about anything and is not required to point to anything, which is one reason why I made that choice. If you don't have a /tmp, or can't write to the /tmp that exists, or have a /tmp that's a dangling symlink under any circumstances you may have an issue. That's true regardless of the presence or absense of /smack. All of the traditional mechanisms for dealing with /tmp in a chrooted or namespaced environment remain.
Quoted 1 line
No, it's not about having a default.
Nuts. That would have made addressing your concern easy.
Quoted 1 line
It's about keeping an absolute pathname in virtual fs,
It's in a symlink on the filesystem, and it doesn't have to be an absolute pathname, although since it's a symlink and the semantics for a symlink allow that be be absolute, relative, or dangling I don't see any reason to restrict it from being absolute.
Quoted 4 lines
having all instances autosoddingmatically sharing it _and_ having change attempt in any instance automatically affect all of them. If you have that kind of sharing, don't pretend that your mechanism really allows absolute pathnames.
Could allowing multiple distinct mounts and symlink assignments of /smackfs address those issues? I think it would, but as you pointed out earlier, my lack of ability to read may be clouding my understanding.
Thank you.
Casey Schaufler
[email protected]
Quoted 11 lines · Casey Schaufler
1. Create /moldy at "_"
2. For each label you care about
2a. Create /moldy/<label>
2b. Set the label of /moldy/<label> to <label>
3. ln -s /smack/tmp /tmp1. Create /moldy at "_"
2. For each label you care about
2a. Create /moldy/<label>
2b. Set the label of /moldy/<label> to <label>
3. ln -s /smack/tmp.link /tmp
4. mount --bind /moldy /smack/tmp
or add
/moldy /smack/tmp none bind,rw 0 2
to /etc/fstab (same effect as (4))
Compare with your variant; the difference is in one argument of ln(1) and one additional line in rc script or /etc/fstab. Sorry, but I don't buy the "extra setup complexity" argument at all.
Quoted 7 lines
It's the content of a symlink, and that can be just about anything and is not required to point to anything, which is one reason why I made that choice. If you don't have a /tmp, or can't write to the /tmp that exists, or have a /tmp that's a dangling symlink under any circumstances you may have an issue. That's true regardless of the presence or absense of /smack. All of the traditional mechanisms for dealing with /tmp in a chrooted or namespaced environment remain.
It's not about symlink pointing to /smack/<something>; it's about the place where /smack/<something> itself points to. And _that_ can bloody well be different in different chroots.
Look, if you allow to change where it goes, you certainly allow different prefices on different boxen; moreover, admin can change it freely according to his layout on given box. OTOH, you _can't_ have it different in different chroots and changing it in one will affect all of them. See why that's a problem?
Quoted 4 lines
It's in a symlink on the filesystem, and it doesn't have to be an absolute pathname, although since it's a symlink and the semantics for a symlink allow that be be absolute, relative, or dangling I don't see any reason to restrict it from being absolute.
Fixed-contents symlink (with or without variable tail - it's irrelevant here) is a bloody wrong tool for that kind of fs for the reasons described above. And if you go for "prefix should point to location on the same fs" you can trivially configure the rest in userland (one line describing a binding), leaving the kernel-side stuff with something like "userland can ask for a pair of symlink and directory, having symlink resolve to directory + <label>" instead of your "userland can ask for a symlink resolving to <prefix> + <label>". And _that_ is chroot-neutral - you don't need to do any extra work...
Quoted 2 lines
Could allowing multiple distinct mounts and symlink assignments of /smackfs address those issues?
... like that one. Leave it to normal userland mechanisms; it's a matter of a single line in whatever script you are using to set chroot up and it involves _way_ fewer caveats.
That said, Alan's point still stands - if you don't get processes changing context back and forth, you don't need anything at all - we already have all we need for that kind of setups (and no, selinux is not involved ;-).
Casey Schaufler
maintainerQuoted 12 lines · --- Al Viro
Quoted 11 lines · Casey Schaufler
1. Create /moldy at "_"
2. For each label you care about
2a. Create /moldy/<label>
2b. Set the label of /moldy/<label> to <label>
3. ln -s /smack/tmp /tmp1. Create /moldy at "_"
2. For each label you care about
2a. Create /moldy/<label>
2b. Set the label of /moldy/<label> to <label>
3. ln -s /smack/tmp.link /tmp
Quoted 8 lines
4. mount --bind /moldy /smack/tmp
or add
/moldy /smack/tmp none bind,rw 0 2
to/etc/fstab(same effect as (4))Compare with your variant; the difference is in one argument of ln(1) and one additional line in rc script or
/etc/fstab. Sorry, but I don't buy the "extra setup complexity" argument at all.
What I'm confused about is how that results in a process labeled "foo" getting a different /tmp from a process labeled "bar".
I guess I'll have to review your first post.
Quoted 11 lines
Quoted 7 lines
It's the content of a symlink, and that can be just about anything and is not required to point to anything, which is one reason why I made that choice. If you don't have a /tmp, or can't write to the /tmp that exists, or have a /tmp that's a dangling symlink under any circumstances you may have an issue. That's true regardless of the presence or absense of /smack. All of the traditional mechanisms for dealing with /tmp in a chrooted or namespaced environment remain.
It's not about symlink pointing to /smack/<something>; it's about the place where /smack/<something> itself points to. And _that_ can bloody well be different in different chroots.
Which is completely OK with me.
Quoted 5 lines
Look, if you allow to change where it goes, you certainly allow different prefices on different boxen; moreover, admin can change it freely according to his layout on given box. OTOH, you _can't_ have it different in different chroots and changing it in one will affect all of them. See why that's a problem?
Yes, I can see that could be an unexpected behavior.
Quoted 8 lines
Quoted 4 lines
It's in a symlink on the filesystem, and it doesn't have to be an absolute pathname, although since it's a symlink and the semantics for a symlink allow that be be absolute, relative, or dangling I don't see any reason to restrict it from being absolute.
Fixed-contents symlink (with or without variable tail - it's irrelevant here) is a bloody wrong tool for that kind of fs for the reasons described above.
I do not understand where the concept of Fixed-contents symlink comes from. Yes, "tmp" is initialized to "/moldy/", but that can be changed by writing to /smack/links. Please help me understand the what you mean by fixed-contents symlinks.
Quoted 11 lines
And if you go for "prefix should point to location on the same fs" you can trivially configure the rest in userland (one line describing a binding), leaving the kernel-side stuff with something like "userland can ask for a pair of symlink and directory, having symlink resolve to directory + <label>" instead of your "userland can ask for a symlink resolving to <prefix> + <label>". And _that_ is chroot-neutral - you don't need to do any extra work...
Quoted 2 lines
Could allowing multiple distinct mounts and symlink assignments of /smackfs address those issues?
Quoted 7 lines
... like that one. Leave it to normal userland mechanisms; it's a matter of a single line in whatever script you are using to set chroot up and it involves _way_ fewer caveats.
That said, Alan's point still stands - if you don't get processes changing context back and forth, you don't need anything at all - we already have all we need for that kind of setups (and no, selinux is not involved ;-).
Casey Schaufler
[email protected]
Quoted 10 lines · Casey Schaufler
From: Casey Schaufler <[email protected]>
Smack is the Simplified Mandatory Access Control Kernel.
Smack implements mandatory access control (MAC) using labels attached to tasks and data containers, including files, SVIPC, and other tasks. Smack is a kernel based scheme that requires an absolute minimum of application support and a very small amount of configuration data.
Quoted 6 lines
{snip}
This patch includes changes made by Paul Moore <[email protected]> in support of a more comfortable interface to initialize the CIPSO code from within the kernel. The changes in the net directory are Pauls, as is the update to
netlabel.h
My sign-off got lost when Casey smooshed the patch I sent him into the SMACK mega-patch so I'll throw it back in the thread for accounting purposes.
As for SMACK's use of NetLabel - it looks fine to me, especially now that there is better preservation of the NetLabel/LSM boundary. As has been discussed on the various lists during earlier revisions of the patch I believe there are still some optimizations that can be made regarding how SMACK uses NetLabel but that is something we can always work on at a later date.
Signature · 2 lines
paul moore linux security @ hp