Subject: [PATCH] Smack: mmap controls for library containment
Subsystems (2)
Subject: [PATCH] Smack: mmap controls for library containment
Applied to master branch of:
git://gitorious.org/smack-next/kernel.git
James, would you please pull for security-testing#next?
In the embedded world there are often situations where libraries are updated from a variety of sources, for a variety of reasons, and with any number of security characteristics. These differences might include privilege required for a given library provided interface to function properly, as occurs from time to time in graphics libraries. There are also cases where it is important to limit use of libraries based on the provider of the library and the security aware application may make choices based on that criteria.
These issues are addressed by providing an additional Smack label that may optionally be assigned to an object, the SMACK64MMAP attribute. An mmap operation is allowed if there is no such attribute.
If there is a SMACK64MMAP attribute the mmap is permitted only if a subject with that label has all of the access permitted a subject with the current task label.
Security aware applications may from time to time wish to reduce their "privilege" to avoid accidental use of privilege. One case where this arises is the environment in which multiple sources provide libraries to perform the same functions. An application may know that it should eschew services made available from a particular vendor, or of a particular version.
In support of this a secondary list of Smack rules has been added that is local to the task. This list is consulted only in the case where the global list has approved access. It can only further restrict access. Unlike the global last, if no entry is found on the local list access is granted. An application can add entries to its own list by writing to /smack/load-self.
The changes appear large as they involve refactoring the list handling to accomodate there being more than one rule list.
--- include/linux/xattr.h | 2 + security/smack/smack.h | 9 +- security/smack/smack_access.c | 52 ++++-- security/smack/smack_lsm.c | 269 +++++++++++++++++++++++++----- security/smack/smackfs.c | 370 ++++++++++++++++++++++++++++------------- 5 files changed, 524 insertions(+), 178 deletions(-)
include/linux/xattr.h +2 -0
@@ -42,11 +42,13 @@#define XATTR_SMACK_IPOUT "SMACK64IPOUT"#define XATTR_SMACK_EXEC "SMACK64EXEC"#define XATTR_SMACK_TRANSMUTE "SMACK64TRANSMUTE" +#define XATTR_SMACK_MMAP "SMACK64MMAP"#define XATTR_NAME_SMACK XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX#define XATTR_NAME_SMACKIPIN XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN#define XATTR_NAME_SMACKIPOUT XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT#define XATTR_NAME_SMACKEXEC XATTR_SECURITY_PREFIX XATTR_SMACK_EXEC#define XATTR_NAME_SMACKTRANSMUTE XATTR_SECURITY_PREFIX XATTR_SMACK_TRANSMUTE +#define XATTR_NAME_SMACKMMAP XATTR_SECURITY_PREFIX XATTR_SMACK_MMAP#define XATTR_CAPS_SUFFIX "capability"#define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
security/smack/smack.h +6 -3
@@ -52,13 +52,16 @@ struct socket_smack {struct inode_smack {char *smk_inode;/* label of the fso */ char *smk_task;/* label of the task */ +char *smk_mmap;/* label of the mmap domain */ struct mutex smk_lock;/* initialization lock */ int smk_flags;/* smack inode flags */ };struct task_smack { -char *smk_task;/* label used for access control */ -char *smk_forked;/* label when forked */ +char *smk_task;/* label for access control */ +char *smk_forked;/* label when forked */ +struct list_head smk_rules;/* per task access rules */ +struct mutex smk_rules_lock;/* lock for the rules */ };#define SMK_INODE_INSTANT 0x01/* inode is instantiated */
@@ -202,7 +205,7 @@ struct inode_smack *new_inode_smack(char *);/* * These functions are in smack_access.c */ -int smk_access_entry (char *,char *); +int smk_access_entry (char *,char *,struct list_head *);int smk_access (char *,char *,int ,struct smk_audit_info *);int smk_curacc (char *,u32 ,struct smk_audit_info *);int smack_to_cipso (const char *,struct smack_cipso *);
security/smack/smack_access.c +34 -18
103 lines not on this page · raw message
security/smack/smack_lsm.c +227 -42
433 lines not on this page · raw message
security/smack/smackfs.c +255 -115
451 lines not on this page · raw message
James Morris
maintainerQuoted 7 lines · Casey Schaufler
Subject: [PATCH] Smack: mmap controls for library containment
Applied to master branch of:
git://gitorious.org/smack-next/kernel.gitJames, would you please pull for security-testing#next?
Applied togit://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next-queue
(Which will be merged into #next after the merge window closes).
Signature · 2 lines
James Morris <[email protected]>
Casey Schaufler
maintainerSubject: [PATCH] Smack: correct behavior in the mmap hook
The mmap policy enforcement was not properly handling the interaction between the global and local rule lists. Instead of going through one and then the other, which missed the important case where a rule specified that there should be no access, combine the access limitations where there is a rule in each list.
--- security/smack/smack_lsm.c | 85 +++++++++++++++++++++++++------------------ 1 files changed, 49 insertions(+), 36 deletions(-)
security/smack/smack_lsm.c +49 -36
@@ -1110,38 +1110,6 @@ static int smack_file_fcntl(struct file *file, unsigned int cmd, }/** -* smk_mmap_list_check - the mmap check -* @sub: subject label -* @obj: object label -* @access: access mode -* @local: the task specific rule list -* -* Returns 0 if acces is permitted, -EACCES otherwise -*/ -static int smk_mmap_list_check (char *sub,char *obj,int access, -struct list_head *local) -{ -int may; - -/* -* If there is not a global rule that -* allows access say no. -*/ - may =smk_access_entry (sub, obj, &smack_rule_list); -if (may == -ENOENT || (may & access) != access) -return -EACCES ; -/* -* If there is a task local rule that -* denies access say no. -*/ - may =smk_access_entry (sub, obj, local); -if (may != -ENOENT && (may & access) != access) -return -EACCES ; - -return 0 ; -} - -/** * smack_file_mmap : * Check permissions for a mmap operation. The @file may be NULL, e.g. * if mapping anonymous memory.
@@ -1160,8 +1128,12 @@ static int smack_file_mmap(struct file *file,struct task_smack *tsp;char *sp;char *msmack; +char *osmack;struct inode_smack *isp;struct dentry *dp; +int may; +int mmay; +int tmay;int rc;/* do DAC check on address space usage */
@@ -1199,16 +1171,57 @@ static int smack_file_mmap(struct file *file,list_for_each_entry_rcu (srp, &smack_rule_list, list) {if (srp->smk_subject != sp)continue ; + + osmack = srp->smk_object;/* * Matching labels always allows access. */ -if (msmack == srp->smk_object) +if (msmack == osmack) +continue ; +/* +* If there is a matching local rule take +* that into account as well. +*/ + may =smk_access_entry (srp->smk_subject, osmack, + &tsp->smk_rules); +if (may == -ENOENT ) + may = srp->smk_access; +else + may &= srp->smk_access; +/* +* If may is zero the SMACK64MMAP subject can't +* possibly have less access. +*/ +if (may ==0 )continue ; - rc =smk_mmap_list_check (msmack, srp->smk_object, - srp->smk_access, &tsp->smk_rules); -if (rc !=0 ) +/* +* Fetch the global list entry. +* If there isn't one a SMACK64MMAP subject +* can't have as much access as current. +*/ + mmay =smk_access_entry (msmack, osmack, &smack_rule_list); +if (mmay == -ENOENT ) { + rc = -EACCES ;break ; + } +/* +* If there is a local entry it modifies the +* potential access, too. +*/ + tmay =smk_access_entry (msmack, osmack, &tsp->smk_rules); +if (tmay != -ENOENT ) + mmay &= tmay; + +/* +* If there is any access available to current that is +* not available to a SMACK64MMAP subject +* deny access. +*/ +if ((may | mmay) != may) { + rc = -EACCES ; +break ; + } }rcu_read_unlock ();
James Morris
maintainerQuoted 11 lines · Casey Schaufler
Subject: [PATCH] Smack: correct behavior in the mmap hook
The mmap policy enforcement was not properly handling the interaction between the global and local rule lists. Instead of going through one and then the other, which missed the important case where a rule specified that there should be no access, combine the access limitations where there is a rule in each list.
Signed-off-by Casey Schaufler <[email protected]>
Applied togit://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next
Signature · 2 lines
James Morris <[email protected]>
Casey Schaufler
maintainerQuoted 11 lines · James Morris
On Tue, 8 Feb 2011, Casey Schaufler wrote:
Subject: [PATCH] Smack: correct behavior in the mmap hook
The mmap policy enforcement was not properly handling the interaction between the global and local rule lists. Instead of going through one and then the other, which missed the important case where a rule specified that there should be no access, combine the access limitations where there is a rule in each list.
Quoted 4 lines
Signed-off-by Casey Schaufler <[email protected]>Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next
James, I made an error and failed to say that this and Shan Wei's clean-up should be pulled from git://gitorious.org/smack-next/kernel.git
James Morris
maintainerQuoted 7 lines · Casey Schaufler
Quoted 4 lines
Signed-off-by Casey Schaufler <[email protected]>Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#nextJames, I made an error and failed to say that this and Shan Wei's clean-up should be pulled from
git://gitorious.org/smack-next/kernel.git
Please use git-request-pull to generate the message.
Signature · 2 lines
James Morris <[email protected]>
Casey Schaufler
maintainerQuoted 9 lines · James Morris
Quoted 6 lines · Casey Schaufler
Quoted 4 lines
Signed-off-by Casey Schaufler <[email protected]>Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#nextJames, I made an error and failed to say that this and Shan Wei's clean-up should be pulled from
git://gitorious.org/smack-next/kernel.gitPlease use git-request-pull to generate the message.
The following changes since commit 7898e1f8e9eb1bee88c92d636e0ab93f2cbe31c6:
Casey Schaufler (1):
Subject: [PATCH] Smack: mmap controls for library containment
are available in the git repository at:
git://gitorious.org/smack-next/kernel.git master
Casey Schaufler (2):
Smack: correct behavior in the mmap hook
Smack: correct final mmap check comparison
Shan Wei (1):
security:smack: kill unused SMACK_LIST_MAX, MAY_ANY and MAY_ANYWRITE
security/smack/smack.h | 8 ---- security/smack/smack_lsm.c | 85 +++++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 44 deletions(-)
James Morris
maintainerQuoted 2 lines · Casey Schaufler
Shan Wei (1):
security:smack: kill unusedSMACK_LIST_MAX,MAY_ANYandMAY_ANYWRITE
This one is missing a signoff by you. You need to use git-am -s
Also, I already have 'Smack: correct behavior in the mmap hook' in my tree. Create a for-security-next (or whatever) branch for me to pull from, based on my current tree, without that patch. (Otherwise I have to ask everyone else to rebase).
Signature · 2 lines
James Morris <[email protected]>
Casey Schaufler
maintainer[PULL] Smack: please pull for security-testing next
In reply to James MorrisThe following changes since commit 0e0a070d3a47d279de66e08244769556deae2eee:
Casey Schaufler (1):
Smack: correct behavior in the mmap hook
are available in the git repository at:
git://gitorious.org/smack-next/kernel.git next
Casey Schaufler (1):
Smack: correct final mmap check comparison
Shan Wei (1):
security:smack: kill unused SMACK_LIST_MAX, MAY_ANY and MAY_ANYWRITE
security/smack/smack.h | 8 -------- security/smack/smack_lsm.c | 2 +- 2 files changed, 1 insertions(+), 9 deletions(-)
James Morris
maintainerRe: [PULL] Smack: please pull for security-testing next
Quoted 6 lines · Casey Schaufler
The following changes since commit
0e0a070d3a47d279de66e08244769556deae2eee:
Casey Schaufler (1):
Smack: correct behavior in the mmap hookare available in the git repository at:
Quoted 7 lines
git://gitorious.org/smack-next/kernel.gitnextCasey Schaufler (1):
Smack: correct final mmap check comparisonShan Wei (1):
security:smack: kill unusedSMACK_LIST_MAX,MAY_ANYandMAY_ANYWRITE
Thanks, looks good :-)
Signature · 2 lines
James Morris <[email protected]>