Smack: Transmute labels on specified directories
Subsystems (2)
PATCH 1/1 Smack: Transmute labels on specified directories
Subject: [PATCH] Smack: Transmute labels on specified directories
Applied to master branch of:
git://gitorious.org/smack-next/kernel.git
James, would you please pull for security-testing#next? I believe that the sign-off is correct.
In a situation where Smack access rules allow processes with multiple labels to write to a directory it is easy to get into a situation where the directory gets cluttered with files that the owner can't deal with because while they could be written to the directory a process at the label of the directory can't write them. This is generally the desired behavior, but when it isn't it is a real issue.
This patch introduces a new attribute SMACK64TRANSMUTE that instructs Smack to create the file with the label of the directory under certain circumstances.
A new access mode, "t" for transmute, is made available to Smack access rules, which are expanded from "rwxa" to "rwxat". If a file is created in a directory marked as transmutable and if access was granted to perform the operation by a rule that included the transmute mode, then the file gets the Smack label of the directory instead of the Smack label of the creating process.
Note that this is equivalent to creating an empty file at the label of the directory and then having the other process write to it. The transmute scheme requires that both the access rule allows transmutation and that the directory be explicitly marked.
--- include/linux/xattr.h | 2 + security/smack/smack.h | 17 +++++++++- security/smack/smack_access.c | 54 ++++++++++++++++++++++------- security/smack/smack_lsm.c | 74 +++++++++++++++++++++++++++------------- security/smack/smackfs.c | 37 +++++++++++++++++--- 5 files changed, 141 insertions(+), 43 deletions(-)
include/linux/xattr.h +2 -0
@@ -41,10 +41,12 @@#define XATTR_SMACK_IPIN "SMACK64IPIN"#define XATTR_SMACK_IPOUT "SMACK64IPOUT"#define XATTR_SMACK_EXEC "SMACK64EXEC" +#define XATTR_SMACK_TRANSMUTE "SMACK64TRANSMUTE"#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_CAPS_SUFFIX "capability"#define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
security/smack/smack.h +16 -1
@@ -62,6 +62,7 @@ struct task_smack { };#define SMK_INODE_INSTANT 0x01/* inode is instantiated */ +#define SMK_INODE_TRANSMUTE 0x02/* directory is transmuting */ /* * A label access rule.
@@ -167,6 +168,10 @@ struct smack_known {#define SMACK_CIPSO_MAXCATNUM 239/* CIPSO 2.2 standard */ /* +* Flag for transmute access +*/ +#define MAY_TRANSMUTE 64 +/* * Just to make the common cases easier to deal with */ #define MAY_ANY (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
@@ -197,6 +202,7 @@ struct inode_smack *new_inode_smack(char *);/* * These functions are in smack_access.c */ +int smk_access_entry (char *,char *);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 *);
@@ -240,6 +246,15 @@ static inline void smack_catset_bit(int cat, char *catsetp) }/* +* Is the directory transmuting? +*/ +static inline int smk_inode_transmutable (const struct inode *isp) +{ +struct inode_smack *sip = isp->i_security; +return (sip->smk_flags &SMK_INODE_TRANSMUTE ) !=0 ; +} + +/* * Present a pointer to the smack label in an inode blob. */ static inline char *smk_of_inode (const struct inode *isp)
@@ -265,7 +280,7 @@ static inline char *smk_of_forked(const struct task_smack *tsp) }/* -* Present a pointer to the smack label in the curren task blob. +* Present a pointer to the smack label in the current task blob. */ static inline char *smk_of_current (void ) {
security/smack/smack_access.c +41 -13
72 lines not on this page · raw message
security/smack/smack_lsm.c +50 -24
169 lines not on this page · raw message
security/smack/smackfs.c +32 -5
@@ -109,9 +109,12 @@ const char *smack_cipso_option = SMACK_CIPSO_OPTION;* SMK_ACCESSLEN: Maximum length for a rule access field * SMK_LOADLEN: Smack rule length */ -#define SMK_ACCESS "rwxa" -#define SMK_ACCESSLEN (sizeof(SMK_ACCESS) - 1) -#define SMK_LOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_ACCESSLEN) +#define SMK_OACCESS "rwxa" +#define SMK_ACCESS "rwxat" +#define SMK_OACCESSLEN (sizeof(SMK_OACCESS) - 1) +#define SMK_ACCESSLEN (sizeof(SMK_ACCESS) - 1) +#define SMK_OLOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_OACCESSLEN) +#define SMK_LOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_ACCESSLEN)/** * smk_netlabel_audit_set - fill a netlbl_audit struct
@@ -175,6 +178,8 @@ static int load_seq_show(struct seq_file *s, void *v)seq_putc (s,'x' );if (srp->smk_access &MAY_APPEND )seq_putc (s,'a' ); +if (srp->smk_access &MAY_TRANSMUTE ) +seq_putc (s,'t' );if (srp->smk_access ==0 )seq_putc (s,'-' );
@@ -273,10 +278,15 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf,if (!capable (CAP_MAC_ADMIN ))return -EPERM ; -if (*ppos !=0 || count !=SMK_LOADLEN ) +if (*ppos !=0 ) +return -EINVAL ; +/* +* Minor hack for backward compatability +*/ +if (count < (SMK_OLOADLEN ) || count >SMK_LOADLEN )return -EINVAL ; - data =kzalloc (count,GFP_KERNEL ); + data =kzalloc (SMK_LOADLEN ,GFP_KERNEL );if (data ==NULL )return -ENOMEM ;
@@ -285,6 +295,12 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf, goto out; } +/* +* More on the minor hack for backward compatability +*/ +if (count == (SMK_OLOADLEN )) + data[SMK_OLOADLEN ] ='-' ; + rule =kzalloc (sizeof (*rule),GFP_KERNEL );if (rule ==NULL ) { rc = -ENOMEM ;
@@ -345,6 +361,17 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf, goto out_free_rule; } +switch (data[SMK_LABELLEN +SMK_LABELLEN +4 ]) { +case '-' : +break ; +case 't' : +case 'T' : + rule->smk_access |=MAY_TRANSMUTE ; +break ; +default : + goto out_free_rule; + } + rc =smk_set_access (rule);if (!rc)
James Morris
maintainerQuoted 8 lines · Casey Schaufler
Subject: [PATCH] Smack: Transmute labels on specified directories
Applied to master branch of:
git://gitorious.org/smack-next/kernel.gitJames, would you please pull for security-testing#next? I believe that the sign-off is correct.
Done.
Signature · 2 lines
James Morris <[email protected]>