]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - security/smack/smackfs.c
[MIPS] Alchemy: move UART platform code to its proper place
[linux-2.6-omap-h63xx.git] / security / smack / smackfs.c
index 358c92c1a153df7f943d09fdc3634ffffc47a632..6ba283783b70af178d7c66bca1e44eb632674f2b 100644 (file)
@@ -73,18 +73,26 @@ struct smk_list_entry *smack_list;
 
 #define        SEQ_READ_FINISHED       1
 
-/*
- * Disable concurrent writing open() operations
- */
-static struct semaphore smack_write_sem;
-
 /*
  * Values for parsing cipso rules
  * SMK_DIGITLEN: Length of a digit field in a rule.
- * SMK_CIPSOMEN: Minimum possible cipso rule length.
+ * SMK_CIPSOMIN: Minimum possible cipso rule length.
+ * SMK_CIPSOMAX: Maximum possible cipso rule length.
  */
 #define SMK_DIGITLEN 4
-#define SMK_CIPSOMIN (SMK_MAXLEN + 2 * SMK_DIGITLEN)
+#define SMK_CIPSOMIN (SMK_LABELLEN + 2 * SMK_DIGITLEN)
+#define SMK_CIPSOMAX (SMK_CIPSOMIN + SMACK_CIPSO_MAXCATNUM * SMK_DIGITLEN)
+
+/*
+ * Values for parsing MAC rules
+ * SMK_ACCESS: Maximum possible combination of access permissions
+ * 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)
+
 
 /*
  * Seq_file read operations for /smack/load
@@ -155,32 +163,7 @@ static struct seq_operations load_seq_ops = {
  */
 static int smk_open_load(struct inode *inode, struct file *file)
 {
-       if ((file->f_flags & O_ACCMODE) == O_RDONLY)
-               return seq_open(file, &load_seq_ops);
-
-       if (down_interruptible(&smack_write_sem))
-               return -ERESTARTSYS;
-
-       return 0;
-}
-
-/**
- * smk_release_load - release() for /smack/load
- * @inode: inode structure representing file
- * @file: "load" file pointer
- *
- * For a reading session, use the seq_file release
- * implementation.
- * Otherwise, we are at the end of a writing session so
- * clean everything up.
- */
-static int smk_release_load(struct inode *inode, struct file *file)
-{
-       if ((file->f_flags & O_ACCMODE) == O_RDONLY)
-               return seq_release(inode, file);
-
-       up(&smack_write_sem);
-       return 0;
+       return seq_open(file, &load_seq_ops);
 }
 
 /**
@@ -229,14 +212,10 @@ static void smk_set_access(struct smack_rule *srp)
  * The format is exactly:
  *     char subject[SMK_LABELLEN]
  *     char object[SMK_LABELLEN]
- *     char access[SMK_ACCESSKINDS]
+ *     char access[SMK_ACCESSLEN]
  *
- *     Anything following is commentary and ignored.
- *
- * writes must be SMK_LABELLEN+SMK_LABELLEN+4 bytes.
+ * writes must be SMK_LABELLEN+SMK_LABELLEN+SMK_ACCESSLEN bytes.
  */
-#define MINIMUM_LOAD (SMK_LABELLEN + SMK_LABELLEN + SMK_ACCESSKINDS)
-
 static ssize_t smk_write_load(struct file *file, const char __user *buf,
                              size_t count, loff_t *ppos)
 {
@@ -253,7 +232,7 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf,
                return -EPERM;
        if (*ppos != 0)
                return -EINVAL;
-       if (count < MINIMUM_LOAD)
+       if (count != SMK_LOADLEN)
                return -EINVAL;
 
        data = kzalloc(count, GFP_KERNEL);
@@ -332,7 +311,7 @@ static const struct file_operations smk_load_ops = {
        .read           = seq_read,
        .llseek         = seq_lseek,
        .write          = smk_write_load,
-       .release        = smk_release_load,
+       .release        = seq_release,
 };
 
 /**
@@ -513,7 +492,7 @@ static ssize_t smk_write_cipso(struct file *file, const char __user *buf,
                return -EPERM;
        if (*ppos != 0)
                return -EINVAL;
-       if (count <= SMK_CIPSOMIN)
+       if (count < SMK_CIPSOMIN || count > SMK_CIPSOMAX)
                return -EINVAL;
 
        data = kzalloc(count + 1, GFP_KERNEL);
@@ -547,7 +526,7 @@ static ssize_t smk_write_cipso(struct file *file, const char __user *buf,
        if (ret != 1 || catlen > SMACK_CIPSO_MAXCATNUM)
                goto out;
 
-       if (count <= (SMK_CIPSOMIN + catlen * SMK_DIGITLEN))
+       if (count != (SMK_CIPSOMIN + catlen * SMK_DIGITLEN))
                goto out;
 
        memset(mapcatset, 0, sizeof(mapcatset));
@@ -986,12 +965,21 @@ static struct vfsmount *smackfs_mount;
  *
  * register the smackfs
  *
- * Returns 0 unless the registration fails.
+ * Do not register smackfs if Smack wasn't enabled
+ * on boot. We can not put this method normally under the
+ * smack_init() code path since the security subsystem get
+ * initialized before the vfs caches.
+ *
+ * Returns true if we were not chosen on boot or if
+ * we were chosen and filesystem registration succeeded.
  */
 static int __init init_smk_fs(void)
 {
        int err;
 
+       if (!security_module_enable(&smack_ops))
+               return 0;
+
        err = register_filesystem(&smk_fs_type);
        if (!err) {
                smackfs_mount = kern_mount(&smk_fs_type);
@@ -1002,7 +990,6 @@ static int __init init_smk_fs(void)
                }
        }
 
-       sema_init(&smack_write_sem, 1);
        smk_cipso_doi();
        smk_unlbl_ambient(NULL);