Merge branch 'smack-for-3.19' of git://git.gitorious.org/smack-next/kernel into next
authorJames Morris <james.l.morris@oracle.com>
Wed, 26 Nov 2014 13:35:32 +0000 (00:35 +1100)
committerJames Morris <james.l.morris@oracle.com>
Wed, 26 Nov 2014 13:35:32 +0000 (00:35 +1100)
security/smack/smack_access.c
security/smack/smack_lsm.c

index 5b970ffde024aff51a8f59bc54f47107916ce0de..1158430f5bb9b61b2c9a6e2cd79d79150e07c9f0 100644 (file)
@@ -142,8 +142,7 @@ int smk_access(struct smack_known *subject, struct smack_known *object,
         * Tasks cannot be assigned the internet label.
         * An internet subject can access any object.
         */
-       if (object == &smack_known_web ||
-           subject == &smack_known_web)
+       if (object == &smack_known_web || subject == &smack_known_web)
                goto out_audit;
        /*
         * A star object can be accessed by any subject.
@@ -157,10 +156,11 @@ int smk_access(struct smack_known *subject, struct smack_known *object,
        if (subject->smk_known == object->smk_known)
                goto out_audit;
        /*
-        * A hat subject can read any object.
-        * A floor object can be read by any subject.
+        * A hat subject can read or lock any object.
+        * A floor object can be read or locked by any subject.
         */
-       if ((request & MAY_ANYREAD) == request) {
+       if ((request & MAY_ANYREAD) == request ||
+           (request & MAY_LOCK) == request) {
                if (object == &smack_known_floor)
                        goto out_audit;
                if (subject == &smack_known_hat)
@@ -452,10 +452,9 @@ char *smk_parse_smack(const char *string, int len)
                return NULL;
 
        smack = kzalloc(i + 1, GFP_KERNEL);
-       if (smack != NULL) {
-               strncpy(smack, string, i + 1);
-               smack[i] = '\0';
-       }
+       if (smack != NULL)
+               strncpy(smack, string, i);
+
        return smack;
 }
 
index 93dc876734a4f7f7db8097bf014f52aba6ec05c4..2717cdd7872c30329773c0ffc8879a36dcb840aa 100644 (file)
@@ -53,6 +53,7 @@
 #define SMK_SENDING    2
 
 LIST_HEAD(smk_ipv6_port_list);
+static struct kmem_cache *smack_inode_cache;
 
 #ifdef CONFIG_SECURITY_SMACK_BRINGUP
 static void smk_bu_mode(int mode, char *s)
@@ -240,7 +241,7 @@ struct inode_smack *new_inode_smack(struct smack_known *skp)
 {
        struct inode_smack *isp;
 
-       isp = kzalloc(sizeof(struct inode_smack), GFP_NOFS);
+       isp = kmem_cache_zalloc(smack_inode_cache, GFP_NOFS);
        if (isp == NULL)
                return NULL;
 
@@ -767,7 +768,7 @@ static int smack_inode_alloc_security(struct inode *inode)
  */
 static void smack_inode_free_security(struct inode *inode)
 {
-       kfree(inode->i_security);
+       kmem_cache_free(smack_inode_cache, inode->i_security);
        inode->i_security = NULL;
 }
 
@@ -4265,10 +4266,16 @@ static __init int smack_init(void)
        if (!security_module_enable(&smack_ops))
                return 0;
 
+       smack_inode_cache = KMEM_CACHE(inode_smack, 0);
+       if (!smack_inode_cache)
+               return -ENOMEM;
+
        tsp = new_task_smack(&smack_known_floor, &smack_known_floor,
                                GFP_KERNEL);
-       if (tsp == NULL)
+       if (tsp == NULL) {
+               kmem_cache_destroy(smack_inode_cache);
                return -ENOMEM;
+       }
 
        printk(KERN_INFO "Smack:  Initializing.\n");