TOMOYO: Use pathname specified by policy rather than execve()
[deliverable/linux.git] / security / tomoyo / common.h
index cdc9ef56fd86d35fee83d1b554cad30aebe146c4..04454cb7b24a534e84c8873a8babeb9614a8da60 100644 (file)
@@ -246,6 +246,8 @@ struct tomoyo_request_info {
        union {
                struct {
                        const struct tomoyo_path_info *filename;
+                       /* For using wildcards at tomoyo_find_next_domain(). */
+                       const struct tomoyo_path_info *matched_path;
                        u8 operation;
                } path;
                struct {
@@ -310,10 +312,10 @@ struct tomoyo_path_info {
 };
 
 /*
- * tomoyo_name_entry is a structure which is used for linking
+ * tomoyo_name is a structure which is used for linking
  * "struct tomoyo_path_info" into tomoyo_name_list .
  */
-struct tomoyo_name_entry {
+struct tomoyo_name {
        struct list_head list;
        atomic_t users;
        struct tomoyo_path_info entry;
@@ -524,28 +526,11 @@ struct tomoyo_mount_acl {
        struct tomoyo_number_union flags;
 };
 
+#define TOMOYO_MAX_IO_READ_QUEUE 32
+
 /*
- * tomoyo_io_buffer is a structure which is used for reading and modifying
- * configuration via /sys/kernel/security/tomoyo/ interface.
- * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as
- * cursors.
- *
- * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of
- * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info"
- * entry has a list of "struct tomoyo_acl_info", we need two cursors when
- * reading (one is for traversing tomoyo_domain_list and the other is for
- * traversing "struct tomoyo_acl_info"->acl_info_list ).
- *
- * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
- * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the
- * domain with the domainname specified by the rest of that line (NULL is set
- * if seek failed).
- * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
- * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that
- * line (->write_var1 is set to NULL if a domain was deleted).
- * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
- * neither "select " nor "delete ", an entry or a domain specified by that line
- * is appended.
+ * Structure for reading/writing policy via /sys/kernel/security/tomoyo
+ * interfaces.
  */
 struct tomoyo_io_buffer {
        void (*read) (struct tomoyo_io_buffer *);
@@ -555,24 +540,27 @@ struct tomoyo_io_buffer {
        struct mutex io_sem;
        /* Index returned by tomoyo_read_lock(). */
        int reader_idx;
-       /* The position currently reading from. */
-       struct list_head *read_var1;
-       /* Extra variables for reading.         */
-       struct list_head *read_var2;
+       char __user *read_user_buf;
+       int read_user_buf_avail;
+       struct {
+               struct list_head *domain;
+               struct list_head *group;
+               struct list_head *acl;
+               int avail;
+               int step;
+               int query_index;
+               u16 index;
+               u8 bit;
+               u8 w_pos;
+               bool eof;
+               bool print_this_domain_only;
+               bool print_execute_only;
+               const char *w[TOMOYO_MAX_IO_READ_QUEUE];
+       } r;
        /* The position currently writing to.   */
        struct tomoyo_domain_info *write_var1;
-       /* The step for reading.                */
-       int read_step;
        /* Buffer for reading.                  */
        char *read_buf;
-       /* EOF flag for reading.                */
-       bool read_eof;
-       /* Read domain ACL of specified PID?    */
-       bool read_single_domain;
-       /* Extra variable for reading.          */
-       u8 read_bit;
-       /* Bytes available for reading.         */
-       int read_avail;
        /* Size of read buffer.                 */
        int readbuf_size;
        /* Buffer for writing.                  */
@@ -586,20 +574,20 @@ struct tomoyo_io_buffer {
 };
 
 /*
- * tomoyo_globally_readable_file_entry is a structure which is used for holding
+ * tomoyo_readable_file is a structure which is used for holding
  * "allow_read" entries.
  * It has following fields.
  *
  *  (1) "head" is "struct tomoyo_acl_head".
  *  (2) "filename" is a pathname which is allowed to open(O_RDONLY).
  */
-struct tomoyo_globally_readable_file_entry {
+struct tomoyo_readable_file {
        struct tomoyo_acl_head head;
        const struct tomoyo_path_info *filename;
 };
 
 /*
- * tomoyo_pattern_entry is a structure which is used for holding
+ * tomoyo_no_pattern is a structure which is used for holding
  * "file_pattern" entries.
  * It has following fields.
  *
@@ -607,13 +595,13 @@ struct tomoyo_globally_readable_file_entry {
  *  (2) "pattern" is a pathname pattern which is used for converting pathnames
  *      to pathname patterns during learning mode.
  */
-struct tomoyo_pattern_entry {
+struct tomoyo_no_pattern {
        struct tomoyo_acl_head head;
        const struct tomoyo_path_info *pattern;
 };
 
 /*
- * tomoyo_no_rewrite_entry is a structure which is used for holding
+ * tomoyo_no_rewrite is a structure which is used for holding
  * "deny_rewrite" entries.
  * It has following fields.
  *
@@ -621,7 +609,7 @@ struct tomoyo_pattern_entry {
  *  (2) "pattern" is a pathname which is by default not permitted to modify
  *      already existing content.
  */
-struct tomoyo_no_rewrite_entry {
+struct tomoyo_no_rewrite {
        struct tomoyo_acl_head head;
        const struct tomoyo_path_info *pattern;
 };
@@ -650,7 +638,7 @@ struct tomoyo_transition_control {
 };
 
 /*
- * tomoyo_aggregator_entry is a structure which is used for holding
+ * tomoyo_aggregator is a structure which is used for holding
  * "aggregator" entries.
  * It has following fields.
  *
@@ -658,14 +646,14 @@ struct tomoyo_transition_control {
  *  (2) "original_name" which is originally requested name.
  *  (3) "aggregated_name" which is name to rewrite.
  */
-struct tomoyo_aggregator_entry {
+struct tomoyo_aggregator {
        struct tomoyo_acl_head head;
        const struct tomoyo_path_info *original_name;
        const struct tomoyo_path_info *aggregated_name;
 };
 
 /*
- * tomoyo_policy_manager_entry is a structure which is used for holding list of
+ * tomoyo_manager is a structure which is used for holding list of
  * domainnames or programs which are permitted to modify configuration via
  * /sys/kernel/security/tomoyo/ interface.
  * It has following fields.
@@ -675,7 +663,7 @@ struct tomoyo_aggregator_entry {
  *      otherwise.
  *  (3) "manager" is a domainname or a program's pathname.
  */
-struct tomoyo_policy_manager_entry {
+struct tomoyo_manager {
        struct tomoyo_acl_head head;
        bool is_domain;  /* True if manager is a domainname. */
        /* A path to program or a domainname. */
@@ -719,6 +707,8 @@ void tomoyo_check_profile(void);
 int tomoyo_open_control(const u8 type, struct file *file);
 /* Close /sys/kernel/security/tomoyo/ interface. */
 int tomoyo_close_control(struct file *file);
+/* Poll operation for /sys/kernel/security/tomoyo/ interface. */
+int tomoyo_poll_control(struct file *file, poll_table *wait);
 /* Read operation for /sys/kernel/security/tomoyo/ interface. */
 int tomoyo_read_control(struct file *file, char __user *buffer,
                        const int buffer_len);
@@ -730,14 +720,14 @@ bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
 /* Print out of memory warning message. */
 void tomoyo_warn_oom(const char *function);
 /* Check whether the given name matches the given name_union. */
-bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
-                              const struct tomoyo_name_union *ptr);
+const struct tomoyo_path_info *
+tomoyo_compare_name_union(const struct tomoyo_path_info *name,
+                         const struct tomoyo_name_union *ptr);
 /* Check whether the given number matches the given number_union. */
 bool tomoyo_compare_number_union(const unsigned long value,
                                 const struct tomoyo_number_union *ptr);
 int tomoyo_get_mode(const u8 profile, const u8 index);
-/* Transactional sprintf() for policy dump. */
-bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
+void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
        __attribute__ ((format(printf, 2, 3)));
 /* Check whether the domainname is correct. */
 bool tomoyo_correct_domain(const unsigned char *domainname);
@@ -749,8 +739,9 @@ bool tomoyo_domain_def(const unsigned char *buffer);
 bool tomoyo_parse_name_union(const char *filename,
                             struct tomoyo_name_union *ptr);
 /* Check whether the given filename matches the given path_group. */
-bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
-                              const struct tomoyo_group *group);
+const struct tomoyo_path_info *
+tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
+                         const struct tomoyo_group *group);
 /* Check whether the given value matches the given number_group. */
 bool tomoyo_number_matches_group(const unsigned long min,
                                 const unsigned long max,
@@ -759,15 +750,11 @@ bool tomoyo_number_matches_group(const unsigned long min,
 bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
                                 const struct tomoyo_path_info *pattern);
 
-bool tomoyo_print_number_union(struct tomoyo_io_buffer *head,
-                              const struct tomoyo_number_union *ptr);
 bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num);
 /* Tokenize a line. */
 bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
 /* Write domain policy violation warning message to console? */
 bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
-/* Get the last component of the given domainname. */
-const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain);
 /* Fill "struct tomoyo_request_info". */
 int tomoyo_init_request_info(struct tomoyo_request_info *r,
                             struct tomoyo_domain_info *domain,
@@ -776,7 +763,7 @@ int tomoyo_init_request_info(struct tomoyo_request_info *r,
 int tomoyo_mount_permission(char *dev_name, struct path *path, char *type,
                            unsigned long flags, void *data_page);
 /* Create "aggregator" entry in exception policy. */
-int tomoyo_write_aggregator_policy(char *data, const bool is_delete);
+int tomoyo_write_aggregator(char *data, const bool is_delete);
 int tomoyo_write_transition_control(char *data, const bool is_delete,
                                    const u8 type);
 /*
@@ -786,17 +773,17 @@ int tomoyo_write_transition_control(char *data, const bool is_delete,
  * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and
  * "allow_link" entry in domain policy.
  */
-int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain,
-                            const bool is_delete);
+int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain,
+                     const bool is_delete);
 /* Create "allow_read" entry in exception policy. */
-int tomoyo_write_globally_readable_policy(char *data, const bool is_delete);
+int tomoyo_write_globally_readable(char *data, const bool is_delete);
 /* Create "allow_mount" entry in domain policy. */
-int tomoyo_write_mount_policy(char *data, struct tomoyo_domain_info *domain,
-                             const bool is_delete);
+int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain,
+                      const bool is_delete);
 /* Create "deny_rewrite" entry in exception policy. */
-int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete);
+int tomoyo_write_no_rewrite(char *data, const bool is_delete);
 /* Create "file_pattern" entry in exception policy. */
-int tomoyo_write_pattern_policy(char *data, const bool is_delete);
+int tomoyo_write_pattern(char *data, const bool is_delete);
 /* Create "path_group"/"number_group" entry in exception policy. */
 int tomoyo_write_group(char *data, const bool is_delete, const u8 type);
 int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
@@ -804,9 +791,8 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
 /* Find a domain by the given name. */
 struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
 /* Find or create a domain by the given name. */
-struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
-                                                           domainname,
-                                                           const u8 profile);
+struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
+                                               const u8 profile);
 struct tomoyo_profile *tomoyo_profile(const u8 profile);
 /*
  * Allocate memory for "struct tomoyo_path_group"/"struct tomoyo_number_group".
@@ -837,7 +823,7 @@ char *tomoyo_realpath_nofollow(const char *pathname);
  */
 char *tomoyo_realpath_from_path(struct path *path);
 /* Get patterned pathname. */
-const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename);
+const char *tomoyo_pattern(const struct tomoyo_path_info *filename);
 
 /* Check memory quota. */
 bool tomoyo_memory_ok(void *ptr);
@@ -897,9 +883,8 @@ int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
                                                  const struct tomoyo_acl_head
                                                  *));
 void tomoyo_check_acl(struct tomoyo_request_info *r,
-                     bool (*check_entry) (const struct tomoyo_request_info *,
+                     bool (*check_entry) (struct tomoyo_request_info *,
                                           const struct tomoyo_acl_info *));
-const char *tomoyo_last_word(const char *name);
 
 /********** External variable definitions. **********/
 
@@ -976,8 +961,8 @@ static inline bool tomoyo_invalid(const unsigned char c)
 static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
 {
        if (name) {
-               struct tomoyo_name_entry *ptr =
-                       container_of(name, struct tomoyo_name_entry, entry);
+               struct tomoyo_name *ptr =
+                       container_of(name, typeof(*ptr), entry);
                atomic_dec(&ptr->users);
        }
 }
This page took 0.03066 seconds and 5 git commands to generate.