]> Pileus Git - ~andy/linux/blobdiff - security/tomoyo/mount.c
Merge branch 'next/dt' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/linux...
[~andy/linux] / security / tomoyo / mount.c
index 7649dbc6a56b507ed96f778b3e3f07e38cea317b..bee09d0620575a5ff5de8e681af1380beeb5ce44 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * security/tomoyo/mount.c
  *
- * Copyright (C) 2005-2010  NTT DATA CORPORATION
+ * Copyright (C) 2005-2011  NTT DATA CORPORATION
  */
 
 #include <linux/slab.h>
@@ -27,29 +27,11 @@ static const char * const tomoyo_mounts[TOMOYO_MAX_SPECIAL_MOUNT] = {
  */
 static int tomoyo_audit_mount_log(struct tomoyo_request_info *r)
 {
-       const char *dev = r->param.mount.dev->name;
-       const char *dir = r->param.mount.dir->name;
-       const char *type = r->param.mount.type->name;
-       const unsigned long flags = r->param.mount.flags;
-       if (r->granted)
-               return 0;
-       if (type == tomoyo_mounts[TOMOYO_MOUNT_REMOUNT])
-               tomoyo_warn_log(r, "mount -o remount %s 0x%lX", dir, flags);
-       else if (type == tomoyo_mounts[TOMOYO_MOUNT_BIND]
-                || type == tomoyo_mounts[TOMOYO_MOUNT_MOVE])
-               tomoyo_warn_log(r, "mount %s %s %s 0x%lX", type, dev, dir,
-                               flags);
-       else if (type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_UNBINDABLE] ||
-                type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_PRIVATE] ||
-                type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_SLAVE] ||
-                type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_SHARED])
-               tomoyo_warn_log(r, "mount %s %s 0x%lX", type, dir, flags);
-       else
-               tomoyo_warn_log(r, "mount -t %s %s %s 0x%lX", type, dev, dir,
-                               flags);
-       return tomoyo_supervisor(r, "allow_mount %s %s %s 0x%lX\n",
+       return tomoyo_supervisor(r, "file mount %s %s %s 0x%lX\n",
                                 r->param.mount.dev->name,
-                                r->param.mount.dir->name, type, flags);
+                                r->param.mount.dir->name,
+                                r->param.mount.type->name,
+                                r->param.mount.flags);
 }
 
 /**
@@ -80,7 +62,7 @@ static bool tomoyo_check_mount_acl(struct tomoyo_request_info *r,
  * tomoyo_mount_acl - Check permission for mount() operation.
  *
  * @r:        Pointer to "struct tomoyo_request_info".
- * @dev_name: Name of device file.
+ * @dev_name: Name of device file. Maybe NULL.
  * @dir:      Pointer to "struct path".
  * @type:     Name of filesystem type.
  * @flags:    Mount options.
@@ -93,6 +75,7 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name,
                            struct path *dir, const char *type,
                            unsigned long flags)
 {
+       struct tomoyo_obj_info obj = { };
        struct path path;
        struct file_system_type *fstype = NULL;
        const char *requested_type = NULL;
@@ -103,6 +86,7 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name,
        struct tomoyo_path_info rdir;
        int need_dev = 0;
        int error = -ENOMEM;
+       r->obj = &obj;
 
        /* Get fstype. */
        requested_type = tomoyo_encode(type);
@@ -112,6 +96,7 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name,
        tomoyo_fill_path_info(&rtype);
 
        /* Get mount point. */
+       obj.path2 = *dir;
        requested_dir_name = tomoyo_realpath_from_path(dir);
        if (!requested_dir_name) {
                error = -ENOMEM;
@@ -143,12 +128,12 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name,
        }
        if (need_dev) {
                /* Get mount point or device file. */
-               if (kern_path(dev_name, LOOKUP_FOLLOW, &path)) {
+               if (!dev_name || kern_path(dev_name, LOOKUP_FOLLOW, &path)) {
                        error = -ENOENT;
                        goto out;
                }
+               obj.path1 = path;
                requested_dev_name = tomoyo_realpath_from_path(&path);
-               path_put(&path);
                if (!requested_dev_name) {
                        error = -ENOENT;
                        goto out;
@@ -181,17 +166,20 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name,
        if (fstype)
                put_filesystem(fstype);
        kfree(requested_type);
+       /* Drop refcount obtained by kern_path(). */
+       if (obj.path1.dentry)
+               path_put(&obj.path1);
        return error;
 }
 
 /**
  * tomoyo_mount_permission - Check permission for mount() operation.
  *
- * @dev_name:  Name of device file.
+ * @dev_name:  Name of device file. Maybe NULL.
  * @path:      Pointer to "struct path".
- * @type:      Name of filesystem type. May be NULL.
+ * @type:      Name of filesystem type. Maybe NULL.
  * @flags:     Mount options.
- * @data_page: Optional data. May be NULL.
+ * @data_page: Optional data. Maybe NULL.
  *
  * Returns 0 on success, negative value otherwise.
  */
@@ -243,56 +231,3 @@ int tomoyo_mount_permission(char *dev_name, struct path *path,
        tomoyo_read_unlock(idx);
        return error;
 }
-
-/**
- * tomoyo_same_mount_acl - Check for duplicated "struct tomoyo_mount_acl" entry.
- *
- * @a: Pointer to "struct tomoyo_acl_info".
- * @b: Pointer to "struct tomoyo_acl_info".
- *
- * Returns true if @a == @b, false otherwise.
- */
-static bool tomoyo_same_mount_acl(const struct tomoyo_acl_info *a,
-                                 const struct tomoyo_acl_info *b)
-{
-       const struct tomoyo_mount_acl *p1 = container_of(a, typeof(*p1), head);
-       const struct tomoyo_mount_acl *p2 = container_of(b, typeof(*p2), head);
-       return tomoyo_same_name_union(&p1->dev_name, &p2->dev_name) &&
-               tomoyo_same_name_union(&p1->dir_name, &p2->dir_name) &&
-               tomoyo_same_name_union(&p1->fs_type, &p2->fs_type) &&
-               tomoyo_same_number_union(&p1->flags, &p2->flags);
-}
-
-/**
- * tomoyo_write_mount - Write "struct tomoyo_mount_acl" list.
- *
- * @data:      String to parse.
- * @domain:    Pointer to "struct tomoyo_domain_info".
- * @is_delete: True if it is a delete request.
- *
- * Returns 0 on success, negative value otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain,
-                      const bool is_delete)
-{
-       struct tomoyo_mount_acl e = { .head.type = TOMOYO_TYPE_MOUNT_ACL };
-       int error = is_delete ? -ENOENT : -ENOMEM;
-       char *w[4];
-       if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[3][0])
-               return -EINVAL;
-       if (!tomoyo_parse_name_union(w[0], &e.dev_name) ||
-           !tomoyo_parse_name_union(w[1], &e.dir_name) ||
-           !tomoyo_parse_name_union(w[2], &e.fs_type) ||
-           !tomoyo_parse_number_union(w[3], &e.flags))
-               goto out;
-       error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
-                                    tomoyo_same_mount_acl, NULL);
- out:
-       tomoyo_put_name_union(&e.dev_name);
-       tomoyo_put_name_union(&e.dir_name);
-       tomoyo_put_name_union(&e.fs_type);
-       tomoyo_put_number_union(&e.flags);
-       return error;
-}