オープンソース・ソフトウェアの開発とダウンロード

Subversion リポジトリの参照

Diff of /trunk/1.8.x/ccs-patch/security/ccsecurity/domain.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/1.6.x/ccs-patch/fs/tomoyo_domain.c revision 1903 by kumaneko, Mon Dec 1 06:16:16 2008 UTC trunk/1.7.x/ccs-patch/security/ccsecurity/domain.c revision 2951 by kumaneko, Tue Aug 25 04:26:20 2009 UTC
# Line 1  Line 1 
1  /*  /*
2   * fs/tomoyo_domain.c   * security/ccsecurity/domain.c
3   *   *
4   * Implementation of the Domain-Based Mandatory Access Control.   * Copyright (C) 2005-2009  NTT DATA CORPORATION
5   *   *
6   * Copyright (C) 2005-2008  NTT DATA CORPORATION   * Version: 1.7.0-pre   2009/08/24
  *  
  * Version: 1.6.6-pre   2008/12/01  
7   *   *
8   * This file is applicable to both 2.4.30 and 2.6.11 and later.   * This file is applicable to both 2.4.30 and 2.6.11 and later.
9   * See README.ccs for ChangeLog.   * See README.ccs for ChangeLog.
10   *   *
11   */   */
12    
13  #include <linux/ccs_common.h>  #include <linux/slab.h>
 #include <linux/tomoyo.h>  
 #include <linux/realpath.h>  
14  #include <linux/highmem.h>  #include <linux/highmem.h>
15  #include <linux/binfmts.h>  #include <linux/version.h>
16  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)
17  #include <linux/namei.h>  #include <linux/namei.h>
18  #include <linux/mount.h>  #include <linux/mount.h>
19  #endif  #endif
20    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30)
21    #include <linux/fs_struct.h>
22    #endif
23    #include "internal.h"
24    
25  /* For compatibility with older kernels. */  /* For compatibility with older kernels. */
26  #ifndef for_each_process  #ifndef for_each_process
# Line 30  Line 30 
30  /* Variables definitions.*/  /* Variables definitions.*/
31    
32  /* The initial domain. */  /* The initial domain. */
33  struct domain_info KERNEL_DOMAIN;  struct ccs_domain_info ccs_kernel_domain;
   
 /* The list for "struct domain_info". */  
 LIST1_HEAD(domain_list);  
   
 #ifdef CONFIG_TOMOYO  
   
 /* Domain creation lock. */  
 static DEFINE_MUTEX(domain_list_lock);  
   
 /* Structure for "initialize_domain" and "no_initialize_domain" keyword. */  
 struct domain_initializer_entry {  
         struct list1_head list;  
         const struct path_info *domainname;    /* This may be NULL */  
         const struct path_info *program;  
         bool is_deleted;  
         bool is_not;       /* True if this entry is "no_initialize_domain".  */  
         bool is_last_name; /* True if the domainname is ccs_get_last_name(). */  
 };  
   
 /* Structure for "keep_domain" and "no_keep_domain" keyword. */  
 struct domain_keeper_entry {  
         struct list1_head list;  
         const struct path_info *domainname;  
         const struct path_info *program;       /* This may be NULL */  
         bool is_deleted;  
         bool is_not;       /* True if this entry is "no_keep_domain".        */  
         bool is_last_name; /* True if the domainname is ccs_get_last_name(). */  
 };  
   
 /* Structure for "aggregator" keyword. */  
 struct aggregator_entry {  
         struct list1_head list;  
         const struct path_info *original_name;  
         const struct path_info *aggregated_name;  
         bool is_deleted;  
 };  
   
 /* Structure for "alias" keyword. */  
 struct alias_entry {  
         struct list1_head list;  
         const struct path_info *original_name;  
         const struct path_info *aliased_name;  
         bool is_deleted;  
 };  
   
 /**  
  * ccs_set_domain_flag - Set or clear domain's attribute flags.  
  *  
  * @domain:    Pointer to "struct domain_info".  
  * @is_delete: True if it is a delete request.  
  * @flags:     Flags to set or clear.  
  *  
  * Returns nothing.  
  */  
 void ccs_set_domain_flag(struct domain_info *domain, const bool is_delete,  
                          const u8 flags)  
 {  
         /* We need to serialize because this is bitfield operation. */  
         static DEFINE_SPINLOCK(lock);  
         /***** CRITICAL SECTION START *****/  
         spin_lock(&lock);  
         if (!is_delete)  
                 domain->flags |= flags;  
         else  
                 domain->flags &= ~flags;  
         spin_unlock(&lock);  
         /***** CRITICAL SECTION END *****/  
 }  
   
 /**  
  * ccs_get_last_name - Get last component of a domainname.  
  *  
  * @domain: Pointer to "struct domain_info".  
  *  
  * Returns the last component of the domainname.  
  */  
 const char *ccs_get_last_name(const struct domain_info *domain)  
 {  
         const char *cp0 = domain->domainname->name;  
         const char *cp1 = strrchr(cp0, ' ');  
         if (cp1)  
                 return cp1 + 1;  
         return cp0;  
 }  
   
 /**  
  * ccs_add_domain_acl - Add the given ACL to the given domain.  
  *  
  * @domain: Pointer to "struct domain_info". May be NULL.  
  * @acl:    Pointer to "struct acl_info".  
  *  
  * Returns 0.  
  */  
 int ccs_add_domain_acl(struct domain_info *domain, struct acl_info *acl)  
 {  
         if (domain) {  
                 /*  
                  * We need to serialize because this function is called by  
                  * various update functions.  
                  */  
                 static DEFINE_SPINLOCK(lock);  
                 /***** CRITICAL SECTION START *****/  
                 spin_lock(&lock);  
                 list1_add_tail_mb(&acl->list, &domain->acl_info_list);  
                 spin_unlock(&lock);  
                 /***** CRITICAL SECTION END *****/  
         } else {  
                 acl->type &= ~ACL_DELETED;  
         }  
         ccs_update_counter(CCS_UPDATES_COUNTER_DOMAIN_POLICY);  
         return 0;  
 }  
34    
35  /**  /* The list for "struct ccs_domain_info". */
36   * ccs_del_domain_acl - Delete the given ACL from the domain.  LIST_HEAD(ccs_domain_list);
  *  
  * @acl: Pointer to "struct acl_info". May be NULL.  
  *  
  * Returns 0.  
  */  
 int ccs_del_domain_acl(struct acl_info *acl)  
 {  
         if (acl)  
                 acl->type |= ACL_DELETED;  
         ccs_update_counter(CCS_UPDATES_COUNTER_DOMAIN_POLICY);  
         return 0;  
 }  
37    
38  /**  /**
39   * audit_execute_handler_log - Audit execute_handler log.   * ccs_audit_execute_handler_log - Audit execute_handler log.
40   *   *
41     * @ee:         Pointer to "struct ccs_execve_entry".
42   * @is_default: True if it is "execute_handler" log.   * @is_default: True if it is "execute_handler" log.
  * @handler:    The realpath of the handler.  
  * @bprm:       Pointer to "struct linux_binprm".  
43   *   *
44   * Returns 0 on success, negative value otherwise.   * Returns 0 on success, negative value otherwise.
45   */   */
46  static int audit_execute_handler_log(const bool is_default,  static int ccs_audit_execute_handler_log(struct ccs_execve_entry *ee,
47                                       const char *handler,                                           const bool is_default)
                                      struct linux_binprm *bprm)  
48  {  {
49          struct ccs_request_info r;          struct ccs_request_info *r = &ee->r;
50          ccs_init_request_info(&r, NULL, CCS_TOMOYO_MAC_FOR_FILE);          const char *handler = ee->handler->name;
51          r.bprm = bprm;          r->mode = ccs_get_mode(r->profile, CCS_MAC_FILE_EXECUTE);
52          return ccs_write_audit_log(true, &r, "%s %s\n",          return ccs_write_audit_log(true, r, "%s %s\n",
53                                     is_default ? KEYWORD_EXECUTE_HANDLER :                                     is_default ? CCS_KEYWORD_EXECUTE_HANDLER :
54                                     KEYWORD_DENIED_EXECUTE_HANDLER, handler);                                     CCS_KEYWORD_DENIED_EXECUTE_HANDLER, handler);
55  }  }
56    
57  /**  /**
58   * audit_domain_creation_log - Audit domain creation log.   * ccs_audit_domain_creation_log - Audit domain creation log.
59   *   *
60   * @domain:  Pointer to "struct domain_info".   * @domain:  Pointer to "struct ccs_domain_info".
61   *   *
62   * Returns 0 on success, negative value otherwise.   * Returns 0 on success, negative value otherwise.
63   */   */
64  static int audit_domain_creation_log(struct domain_info *domain)  static int ccs_audit_domain_creation_log(struct ccs_domain_info *domain)
65  {  {
66            int error;
67          struct ccs_request_info r;          struct ccs_request_info r;
68          ccs_init_request_info(&r, domain, CCS_TOMOYO_MAC_FOR_FILE);          ccs_init_request_info(&r, domain, CCS_MAC_FILE_EXECUTE);
69          return ccs_write_audit_log(false, &r, "use_profile %u\n", r.profile);          error = ccs_write_audit_log(false, &r, "use_profile %u\n", r.profile);
70            return error;
71  }  }
72    
73  /* The list for "struct domain_initializer_entry". */  /* The list for "struct ccs_domain_initializer_entry". */
74  static LIST1_HEAD(domain_initializer_list);  LIST_HEAD(ccs_domain_initializer_list);
75    
76  /**  /**
77   * update_domain_initializer_entry - Update "struct domain_initializer_entry" list.   * ccs_update_domain_initializer_entry - Update "struct ccs_domain_initializer_entry" list.
78   *   *
79   * @domainname: The name of domain. May be NULL.   * @domainname: The name of domain. May be NULL.
80   * @program:    The name of program.   * @program:    The name of program.
# Line 207  static LIST1_HEAD(domain_initializer_lis Line 83  static LIST1_HEAD(domain_initializer_lis
83   *   *
84   * Returns 0 on success, negative value otherwise.   * Returns 0 on success, negative value otherwise.
85   */   */
86  static int update_domain_initializer_entry(const char *domainname,  static int ccs_update_domain_initializer_entry(const char *domainname,
87                                             const char *program,                                                 const char *program,
88                                             const bool is_not,                                                 const bool is_not,
89                                             const bool is_delete)                                                 const bool is_delete)
90  {  {
91          struct domain_initializer_entry *new_entry;          struct ccs_domain_initializer_entry *entry = NULL;
92          struct domain_initializer_entry *ptr;          struct ccs_domain_initializer_entry *ptr;
93          static DEFINE_MUTEX(lock);          struct ccs_domain_initializer_entry e = { .is_not = is_not };
94          const struct path_info *saved_program;          int error = is_delete ? -ENOENT : -ENOMEM;
95          const struct path_info *saved_domainname = NULL;          if (!ccs_is_correct_path(program, 1, -1, -1))
         int error = -ENOMEM;  
         bool is_last_name = false;  
         if (!ccs_is_correct_path(program, 1, -1, -1, __func__))  
96                  return -EINVAL; /* No patterns allowed. */                  return -EINVAL; /* No patterns allowed. */
97          if (domainname) {          if (domainname) {
98                  if (!ccs_is_domain_def(domainname) &&                  if (!ccs_is_domain_def(domainname) &&
99                      ccs_is_correct_path(domainname, 1, -1, -1, __func__))                      ccs_is_correct_path(domainname, 1, -1, -1))
100                          is_last_name = true;                          e.is_last_name = true;
101                  else if (!ccs_is_correct_domain(domainname, __func__))                  else if (!ccs_is_correct_domain(domainname))
102                          return -EINVAL;                          return -EINVAL;
103                  saved_domainname = ccs_save_name(domainname);                  e.domainname = ccs_get_name(domainname);
104                  if (!saved_domainname)                  if (!e.domainname)
105                          return -ENOMEM;                          goto out;
106          }          }
107          saved_program = ccs_save_name(program);          e.program = ccs_get_name(program);
108          if (!saved_program)          if (!e.program)
109                  return -ENOMEM;                  goto out;
110          mutex_lock(&lock);          if (!is_delete)
111          list1_for_each_entry(ptr, &domain_initializer_list, list) {                  entry = kmalloc(sizeof(e), GFP_KERNEL);
112                  if (ptr->is_not != is_not ||          mutex_lock(&ccs_policy_lock);
113                      ptr->domainname != saved_domainname ||          list_for_each_entry_rcu(ptr, &ccs_domain_initializer_list, list) {
114                      ptr->program != saved_program)                  if (ccs_memcmp(ptr, &e, offsetof(typeof(e), is_not),
115                                   sizeof(e)))
116                          continue;                          continue;
117                  ptr->is_deleted = is_delete;                  ptr->is_deleted = is_delete;
118                  error = 0;                  error = 0;
119                  goto out;                  break;
120          }          }
121          if (is_delete) {          if (!is_delete && error && ccs_commit_ok(entry, &e, sizeof(e))) {
122                  error = -ENOENT;                  list_add_tail_rcu(&entry->list, &ccs_domain_initializer_list);
123                  goto out;                  entry = NULL;
124                    error = 0;
125          }          }
126          new_entry = ccs_alloc_element(sizeof(*new_entry));          mutex_unlock(&ccs_policy_lock);
         if (!new_entry)  
                 goto out;  
         new_entry->domainname = saved_domainname;  
         new_entry->program = saved_program;  
         new_entry->is_not = is_not;  
         new_entry->is_last_name = is_last_name;  
         list1_add_tail_mb(&new_entry->list, &domain_initializer_list);  
         error = 0;  
127   out:   out:
128          mutex_unlock(&lock);          ccs_put_name(e.domainname);
129          ccs_update_counter(CCS_UPDATES_COUNTER_EXCEPTION_POLICY);          ccs_put_name(e.program);
130            kfree(entry);
131          return error;          return error;
132  }  }
133    
134  /**  /**
135   * ccs_read_domain_initializer_policy - Read "struct domain_initializer_entry" list.   * ccs_read_domain_initializer_policy - Read "struct ccs_domain_initializer_entry" list.
136   *   *
137   * @head: Pointer to "struct ccs_io_buffer".   * @head: Pointer to "struct ccs_io_buffer".
138   *   *
139   * Returns true on success, false otherwise.   * Returns true on success, false otherwise.
140     *
141     * Caller holds ccs_read_lock().
142   */   */
143  bool ccs_read_domain_initializer_policy(struct ccs_io_buffer *head)  bool ccs_read_domain_initializer_policy(struct ccs_io_buffer *head)
144  {  {
145          struct list1_head *pos;          struct list_head *pos;
146          list1_for_each_cookie(pos, head->read_var2, &domain_initializer_list) {          bool done = true;
147            list_for_each_cookie(pos, head->read_var2,
148                                 &ccs_domain_initializer_list) {
149                  const char *no;                  const char *no;
150                  const char *from = "";                  const char *from = "";
151                  const char *domain = "";                  const char *domain = "";
152                  struct domain_initializer_entry *ptr;                  struct ccs_domain_initializer_entry *ptr;
153                  ptr = list1_entry(pos, struct domain_initializer_entry, list);                  ptr = list_entry(pos, struct ccs_domain_initializer_entry,
154                                     list);
155                  if (ptr->is_deleted)                  if (ptr->is_deleted)
156                          continue;                          continue;
157                  no = ptr->is_not ? "no_" : "";                  no = ptr->is_not ? "no_" : "";
# Line 286  bool ccs_read_domain_initializer_policy( Line 159  bool ccs_read_domain_initializer_policy(
159                          from = " from ";                          from = " from ";
160                          domain = ptr->domainname->name;                          domain = ptr->domainname->name;
161                  }                  }
162                  if (!ccs_io_printf(head,                  done = ccs_io_printf(head, "%s" CCS_KEYWORD_INITIALIZE_DOMAIN
163                                     "%s" KEYWORD_INITIALIZE_DOMAIN "%s%s%s\n",                                       "%s%s%s\n", no, ptr->program->name, from,
164                                     no, ptr->program->name, from, domain))                                       domain);
165                                  goto out;                  if (!done)
166                            break;
167          }          }
168          return true;          return done;
  out:  
         return false;  
169  }  }
170    
171  /**  /**
172   * ccs_write_domain_initializer_policy - Write "struct domain_initializer_entry" list.   * ccs_write_domain_initializer_policy - Write "struct ccs_domain_initializer_entry" list.
173   *   *
174   * @data:      String to parse.   * @data:      String to parse.
175   * @is_not:    True if it is "no_initialize_domain" entry.   * @is_not:    True if it is "no_initialize_domain" entry.
# Line 311  int ccs_write_domain_initializer_policy( Line 183  int ccs_write_domain_initializer_policy(
183          char *cp = strstr(data, " from ");          char *cp = strstr(data, " from ");
184          if (cp) {          if (cp) {
185                  *cp = '\0';                  *cp = '\0';
186                  return update_domain_initializer_entry(cp + 6, data, is_not,                  return ccs_update_domain_initializer_entry(cp + 6, data,
187                                                         is_delete);                                                             is_not, is_delete);
188          }          }
189          return update_domain_initializer_entry(NULL, data, is_not, is_delete);          return ccs_update_domain_initializer_entry(NULL, data, is_not,
190                                                       is_delete);
191  }  }
192    
193  /**  /**
194   * is_domain_initializer - Check whether the given program causes domainname reinitialization.   * ccs_is_domain_initializer - Check whether the given program causes domainname reinitialization.
195   *   *
196   * @domainname: The name of domain.   * @domainname: The name of domain.
197   * @program:    The name of program.   * @program:    The name of program.
# Line 326  int ccs_write_domain_initializer_policy( Line 199  int ccs_write_domain_initializer_policy(
199   *   *
200   * Returns true if executing @program reinitializes domain transition,   * Returns true if executing @program reinitializes domain transition,
201   * false otherwise.   * false otherwise.
202     *
203     * Caller holds ccs_read_lock().
204   */   */
205  static bool is_domain_initializer(const struct path_info *domainname,  static bool ccs_is_domain_initializer(const struct ccs_path_info *domainname,
206                                    const struct path_info *program,                                        const struct ccs_path_info *program,
207                                    const struct path_info *last_name)                                        const struct ccs_path_info *last_name)
208  {  {
209          struct domain_initializer_entry *ptr;          struct ccs_domain_initializer_entry *ptr;
210          bool flag = false;          bool flag = false;
211          list1_for_each_entry(ptr, &domain_initializer_list, list) {          list_for_each_entry_rcu(ptr, &ccs_domain_initializer_list, list) {
212                  if (ptr->is_deleted)                  if (ptr->is_deleted)
213                          continue;                          continue;
214                  if (ptr->domainname) {                  if (ptr->domainname) {
# Line 347  static bool is_domain_initializer(const Line 222  static bool is_domain_initializer(const
222                  }                  }
223                  if (ccs_pathcmp(ptr->program, program))                  if (ccs_pathcmp(ptr->program, program))
224                          continue;                          continue;
225                  if (ptr->is_not)                  if (ptr->is_not) {
226                          return false;                          flag = false;
227                            break;
228                    }
229                  flag = true;                  flag = true;
230          }          }
231          return flag;          return flag;
232  }  }
233    
234  /* The list for "struct domain_keeper_entry". */  /* The list for "struct ccs_domain_keeper_entry". */
235  static LIST1_HEAD(domain_keeper_list);  LIST_HEAD(ccs_domain_keeper_list);
236    
237  /**  /**
238   * update_domain_keeper_entry - Update "struct domain_keeper_entry" list.   * ccs_update_domain_keeper_entry - Update "struct ccs_domain_keeper_entry" list.
239   *   *
240   * @domainname: The name of domain.   * @domainname: The name of domain.
241   * @program:    The name of program. May be NULL.   * @program:    The name of program. May be NULL.
# Line 367  static LIST1_HEAD(domain_keeper_list); Line 244  static LIST1_HEAD(domain_keeper_list);
244   *   *
245   * Returns 0 on success, negative value otherwise.   * Returns 0 on success, negative value otherwise.
246   */   */
247  static int update_domain_keeper_entry(const char *domainname,  static int ccs_update_domain_keeper_entry(const char *domainname,
248                                        const char *program,                                            const char *program,
249                                        const bool is_not, const bool is_delete)                                            const bool is_not,
250  {                                            const bool is_delete)
251          struct domain_keeper_entry *new_entry;  {
252          struct domain_keeper_entry *ptr;          struct ccs_domain_keeper_entry *entry = NULL;
253          const struct path_info *saved_domainname;          struct ccs_domain_keeper_entry *ptr;
254          const struct path_info *saved_program = NULL;          struct ccs_domain_keeper_entry e = { .is_not = is_not };
255          static DEFINE_MUTEX(lock);          int error = is_delete ? -ENOENT : -ENOMEM;
         int error = -ENOMEM;  
         bool is_last_name = false;  
256          if (!ccs_is_domain_def(domainname) &&          if (!ccs_is_domain_def(domainname) &&
257              ccs_is_correct_path(domainname, 1, -1, -1, __func__))              ccs_is_correct_path(domainname, 1, -1, -1))
258                  is_last_name = true;                  e.is_last_name = true;
259          else if (!ccs_is_correct_domain(domainname, __func__))          else if (!ccs_is_correct_domain(domainname))
260                  return -EINVAL;                  return -EINVAL;
261          if (program) {          if (program) {
262                  if (!ccs_is_correct_path(program, 1, -1, -1, __func__))                  if (!ccs_is_correct_path(program, 1, -1, -1))
263                          return -EINVAL;                          return -EINVAL;
264                  saved_program = ccs_save_name(program);                  e.program = ccs_get_name(program);
265                  if (!saved_program)                  if (!e.program)
266                          return -ENOMEM;                          goto out;
267          }          }
268          saved_domainname = ccs_save_name(domainname);          e.domainname = ccs_get_name(domainname);
269          if (!saved_domainname)          if (!e.domainname)
270                  return -ENOMEM;                  goto out;
271          mutex_lock(&lock);          if (!is_delete)
272          list1_for_each_entry(ptr, &domain_keeper_list, list) {                  entry = kmalloc(sizeof(e), GFP_KERNEL);
273                  if (ptr->is_not != is_not ||          mutex_lock(&ccs_policy_lock);
274                      ptr->domainname != saved_domainname ||          list_for_each_entry_rcu(ptr, &ccs_domain_keeper_list, list) {
275                      ptr->program != saved_program)                  if (ccs_memcmp(ptr, &e, offsetof(typeof(e), is_not),
276                                   sizeof(e)))
277                          continue;                          continue;
278                  ptr->is_deleted = is_delete;                  ptr->is_deleted = is_delete;
279                  error = 0;                  error = 0;
280                  goto out;                  break;
281          }          }
282          if (is_delete) {          if (!is_delete && error && ccs_commit_ok(entry, &e, sizeof(e))) {
283                  error = -ENOENT;                  list_add_tail_rcu(&entry->list, &ccs_domain_keeper_list);
284                  goto out;                  entry = NULL;
285                    error = 0;
286          }          }
287          new_entry = ccs_alloc_element(sizeof(*new_entry));          mutex_unlock(&ccs_policy_lock);
         if (!new_entry)  
                 goto out;  
         new_entry->domainname = saved_domainname;  
         new_entry->program = saved_program;  
         new_entry->is_not = is_not;  
         new_entry->is_last_name = is_last_name;  
         list1_add_tail_mb(&new_entry->list, &domain_keeper_list);  
         error = 0;  
288   out:   out:
289          mutex_unlock(&lock);          ccs_put_name(e.domainname);
290          ccs_update_counter(CCS_UPDATES_COUNTER_EXCEPTION_POLICY);          ccs_put_name(e.program);
291            kfree(entry);
292          return error;          return error;
293  }  }
294    
295  /**  /**
296   * ccs_write_domain_keeper_policy - Write "struct domain_keeper_entry" list.   * ccs_write_domain_keeper_policy - Write "struct ccs_domain_keeper_entry" list.
297   *   *
298   * @data:      String to parse.   * @data:      String to parse.
299   * @is_not:    True if it is "no_keep_domain" entry.   * @is_not:    True if it is "no_keep_domain" entry.
# Line 436  int ccs_write_domain_keeper_policy(char Line 306  int ccs_write_domain_keeper_policy(char
306          char *cp = strstr(data, " from ");          char *cp = strstr(data, " from ");
307          if (cp) {          if (cp) {
308                  *cp = '\0';                  *cp = '\0';
309                  return update_domain_keeper_entry(cp + 6, data,                  return ccs_update_domain_keeper_entry(cp + 6, data,
310                                                    is_not, is_delete);                                                        is_not, is_delete);
311          }          }
312          return update_domain_keeper_entry(data, NULL, is_not, is_delete);          return ccs_update_domain_keeper_entry(data, NULL, is_not, is_delete);
313  }  }
314    
315  /**  /**
316   * ccs_read_domain_keeper_policy - Read "struct domain_keeper_entry" list.   * ccs_read_domain_keeper_policy - Read "struct ccs_domain_keeper_entry" list.
317   *   *
318   * @head: Pointer to "struct ccs_io_buffer".   * @head: Pointer to "struct ccs_io_buffer".
319   *   *
320   * Returns true on success, false otherwise.   * Returns true on success, false otherwise.
321     *
322     * Caller holds ccs_read_lock().
323   */   */
324  bool ccs_read_domain_keeper_policy(struct ccs_io_buffer *head)  bool ccs_read_domain_keeper_policy(struct ccs_io_buffer *head)
325  {  {
326          struct list1_head *pos;          struct list_head *pos;
327          list1_for_each_cookie(pos, head->read_var2, &domain_keeper_list) {          bool done = true;
328                  struct domain_keeper_entry *ptr;          list_for_each_cookie(pos, head->read_var2,
329                                 &ccs_domain_keeper_list) {
330                    struct ccs_domain_keeper_entry *ptr;
331                  const char *no;                  const char *no;
332                  const char *from = "";                  const char *from = "";
333                  const char *program = "";                  const char *program = "";
334                  ptr = list1_entry(pos, struct domain_keeper_entry, list);                  ptr = list_entry(pos, struct ccs_domain_keeper_entry, list);
335                  if (ptr->is_deleted)                  if (ptr->is_deleted)
336                          continue;                          continue;
337                  no = ptr->is_not ? "no_" : "";                  no = ptr->is_not ? "no_" : "";
# Line 465  bool ccs_read_domain_keeper_policy(struc Line 339  bool ccs_read_domain_keeper_policy(struc
339                          from = " from ";                          from = " from ";
340                          program = ptr->program->name;                          program = ptr->program->name;
341                  }                  }
342                  if (!ccs_io_printf(head,                  done = ccs_io_printf(head, "%s" CCS_KEYWORD_KEEP_DOMAIN
343                                     "%s" KEYWORD_KEEP_DOMAIN "%s%s%s\n", no,                                       "%s%s%s\n", no, program, from,
344                                     program, from, ptr->domainname->name))                                       ptr->domainname->name);
345                                  goto out;                  if (!done)
346                            break;
347          }          }
348          return true;          return done;
  out:  
         return false;  
349  }  }
350    
351  /**  /**
352   * is_domain_keeper - Check whether the given program causes domain transition suppression.   * ccs_is_domain_keeper - Check whether the given program causes domain transition suppression.
353   *   *
354   * @domainname: The name of domain.   * @domainname: The name of domain.
355   * @program:    The name of program.   * @program:    The name of program.
# Line 484  bool ccs_read_domain_keeper_policy(struc Line 357  bool ccs_read_domain_keeper_policy(struc
357   *   *
358   * Returns true if executing @program supresses domain transition,   * Returns true if executing @program supresses domain transition,
359   * false otherwise.   * false otherwise.
360     *
361     * Caller holds ccs_read_lock().
362   */   */
363  static bool is_domain_keeper(const struct path_info *domainname,  static bool ccs_is_domain_keeper(const struct ccs_path_info *domainname,
364                               const struct path_info *program,                                   const struct ccs_path_info *program,
365                               const struct path_info *last_name)                                   const struct ccs_path_info *last_name)
366  {  {
367          struct domain_keeper_entry *ptr;          struct ccs_domain_keeper_entry *ptr;
368          bool flag = false;          bool flag = false;
369          list1_for_each_entry(ptr, &domain_keeper_list, list) {          list_for_each_entry_rcu(ptr, &ccs_domain_keeper_list, list) {
370                  if (ptr->is_deleted)                  if (ptr->is_deleted)
371                          continue;                          continue;
372                  if (!ptr->is_last_name) {                  if (!ptr->is_last_name) {
# Line 503  static bool is_domain_keeper(const struc Line 378  static bool is_domain_keeper(const struc
378                  }                  }
379                  if (ptr->program && ccs_pathcmp(ptr->program, program))                  if (ptr->program && ccs_pathcmp(ptr->program, program))
380                          continue;                          continue;
381                  if (ptr->is_not)                  if (ptr->is_not) {
382                          return false;                          flag = false;
383                            break;
384                    }
385                  flag = true;                  flag = true;
386          }          }
387          return flag;          return flag;
388  }  }
389    
390  /* The list for "struct alias_entry". */  /* The list for "struct ccs_aggregator_entry". */
391  static LIST1_HEAD(alias_list);  LIST_HEAD(ccs_aggregator_list);
392    
393  /**  /**
394   * update_alias_entry - Update "struct alias_entry" list.   * ccs_update_aggregator_entry - Update "struct ccs_aggregator_entry" list.
  *  
  * @original_name: The original program's real name.  
  * @aliased_name:  The symbolic program's symbolic link's name.  
  * @is_delete:     True if it is a delete request.  
  *  
  * Returns 0 on success, negative value otherwise.  
  */  
 static int update_alias_entry(const char *original_name,  
                               const char *aliased_name,  
                               const bool is_delete)  
 {  
         struct alias_entry *new_entry;  
         struct alias_entry *ptr;  
         static DEFINE_MUTEX(lock);  
         const struct path_info *saved_original_name;  
         const struct path_info *saved_aliased_name;  
         int error = -ENOMEM;  
         if (!ccs_is_correct_path(original_name, 1, -1, -1, __func__) ||  
             !ccs_is_correct_path(aliased_name, 1, -1, -1, __func__))  
                 return -EINVAL; /* No patterns allowed. */  
         saved_original_name = ccs_save_name(original_name);  
         saved_aliased_name = ccs_save_name(aliased_name);  
         if (!saved_original_name || !saved_aliased_name)  
                 return -ENOMEM;  
         mutex_lock(&lock);  
         list1_for_each_entry(ptr, &alias_list, list) {  
                 if (ptr->original_name != saved_original_name ||  
                     ptr->aliased_name != saved_aliased_name)  
                         continue;  
                 ptr->is_deleted = is_delete;  
                 error = 0;  
                 goto out;  
         }  
         if (is_delete) {  
                 error = -ENOENT;  
                 goto out;  
         }  
         new_entry = ccs_alloc_element(sizeof(*new_entry));  
         if (!new_entry)  
                 goto out;  
         new_entry->original_name = saved_original_name;  
         new_entry->aliased_name = saved_aliased_name;  
         list1_add_tail_mb(&new_entry->list, &alias_list);  
         error = 0;  
  out:  
         mutex_unlock(&lock);  
         ccs_update_counter(CCS_UPDATES_COUNTER_EXCEPTION_POLICY);  
         return error;  
 }  
   
 /**  
  * ccs_read_alias_policy - Read "struct alias_entry" list.  
  *  
  * @head: Pointer to "struct ccs_io_buffer".  
  *  
  * Returns true on success, false otherwise.  
  */  
 bool ccs_read_alias_policy(struct ccs_io_buffer *head)  
 {  
         struct list1_head *pos;  
         list1_for_each_cookie(pos, head->read_var2, &alias_list) {  
                 struct alias_entry *ptr;  
                 ptr = list1_entry(pos, struct alias_entry, list);  
                 if (ptr->is_deleted)  
                         continue;  
                 if (!ccs_io_printf(head, KEYWORD_ALIAS "%s %s\n",  
                                    ptr->original_name->name,  
                                    ptr->aliased_name->name))  
                         goto out;  
         }  
         return true;  
  out:  
         return false;  
 }  
   
 /**  
  * ccs_write_alias_policy - Write "struct alias_entry" list.  
  *  
  * @data:      String to parse.  
  * @is_delete: True if it is a delete request.  
  *  
  * Returns 0 on success, negative value otherwise.  
  */  
 int ccs_write_alias_policy(char *data, const bool is_delete)  
 {  
         char *cp = strchr(data, ' ');  
         if (!cp)  
                 return -EINVAL;  
         *cp++ = '\0';  
         return update_alias_entry(data, cp, is_delete);  
 }  
   
 /* The list for "struct aggregator_entry". */  
 static LIST1_HEAD(aggregator_list);  
   
 /**  
  * update_aggregator_entry - Update "struct aggregator_entry" list.  
395   *   *
396   * @original_name:   The original program's name.   * @original_name:   The original program's name.
397   * @aggregated_name: The aggregated program's name.   * @aggregated_name: The aggregated program's name.
# Line 619  static LIST1_HEAD(aggregator_list); Line 399  static LIST1_HEAD(aggregator_list);
399   *   *
400   * Returns 0 on success, negative value otherwise.   * Returns 0 on success, negative value otherwise.
401   */   */
402  static int update_aggregator_entry(const char *original_name,  static int ccs_update_aggregator_entry(const char *original_name,
403                                     const char *aggregated_name,                                         const char *aggregated_name,
404                                     const bool is_delete)                                         const bool is_delete)
405  {  {
406          struct aggregator_entry *new_entry;          struct ccs_aggregator_entry *entry = NULL;
407          struct aggregator_entry *ptr;          struct ccs_aggregator_entry *ptr;
408          static DEFINE_MUTEX(lock);          struct ccs_aggregator_entry e = { };
409          const struct path_info *saved_original_name;          int error = is_delete ? -ENOENT : -ENOMEM;
410          const struct path_info *saved_aggregated_name;          if (!ccs_is_correct_path(original_name, 1, 0, -1) ||
411          int error = -ENOMEM;              !ccs_is_correct_path(aggregated_name, 1, -1, -1))
         if (!ccs_is_correct_path(original_name, 1, 0, -1, __func__) ||  
             !ccs_is_correct_path(aggregated_name, 1, -1, -1, __func__))  
412                  return -EINVAL;                  return -EINVAL;
413          saved_original_name = ccs_save_name(original_name);          e.original_name = ccs_get_name(original_name);
414          saved_aggregated_name = ccs_save_name(aggregated_name);          e.aggregated_name = ccs_get_name(aggregated_name);
415          if (!saved_original_name || !saved_aggregated_name)          if (!e.original_name || !e.aggregated_name)
416                  return -ENOMEM;                  goto out;
417          mutex_lock(&lock);          if (!is_delete)
418          list1_for_each_entry(ptr, &aggregator_list, list) {                  entry = kmalloc(sizeof(e), GFP_KERNEL);
419                  if (ptr->original_name != saved_original_name ||          mutex_lock(&ccs_policy_lock);
420                      ptr->aggregated_name != saved_aggregated_name)          list_for_each_entry_rcu(ptr, &ccs_aggregator_list, list) {
421                    if (ccs_memcmp(ptr, &e, offsetof(typeof(e), original_name),
422                                   sizeof(e)))
423                          continue;                          continue;
424                  ptr->is_deleted = is_delete;                  ptr->is_deleted = is_delete;
425                  error = 0;                  error = 0;
426                  goto out;                  break;
427          }          }
428          if (is_delete) {          if (!is_delete && error && ccs_commit_ok(entry, &e, sizeof(e))) {
429                  error = -ENOENT;                  list_add_tail_rcu(&entry->list, &ccs_aggregator_list);
430                  goto out;                  entry = NULL;
431                    error = 0;
432          }          }
433          new_entry = ccs_alloc_element(sizeof(*new_entry));          mutex_unlock(&ccs_policy_lock);
         if (!new_entry)  
                 goto out;  
         new_entry->original_name = saved_original_name;  
         new_entry->aggregated_name = saved_aggregated_name;  
         list1_add_tail_mb(&new_entry->list, &aggregator_list);  
         error = 0;  
434   out:   out:
435          mutex_unlock(&lock);          ccs_put_name(e.original_name);
436          ccs_update_counter(CCS_UPDATES_COUNTER_EXCEPTION_POLICY);          ccs_put_name(e.aggregated_name);
437            kfree(entry);
438          return error;          return error;
439  }  }
440    
441  /**  /**
442   * ccs_read_aggregator_policy - Read "struct aggregator_entry" list.   * ccs_read_aggregator_policy - Read "struct ccs_aggregator_entry" list.
443   *   *
444   * @head: Pointer to "struct ccs_io_buffer".   * @head: Pointer to "struct ccs_io_buffer".
445   *   *
446   * Returns true on success, false otherwise.   * Returns true on success, false otherwise.
447     *
448     * Caller holds ccs_read_lock().
449   */   */
450  bool ccs_read_aggregator_policy(struct ccs_io_buffer *head)  bool ccs_read_aggregator_policy(struct ccs_io_buffer *head)
451  {  {
452          struct list1_head *pos;          struct list_head *pos;
453          list1_for_each_cookie(pos, head->read_var2, &aggregator_list) {          bool done = true;
454                  struct aggregator_entry *ptr;          list_for_each_cookie(pos, head->read_var2, &ccs_aggregator_list) {
455                  ptr = list1_entry(pos, struct aggregator_entry, list);                  struct ccs_aggregator_entry *ptr;
456                    ptr = list_entry(pos, struct ccs_aggregator_entry, list);
457                  if (ptr->is_deleted)                  if (ptr->is_deleted)
458                          continue;                          continue;
459                  if (!ccs_io_printf(head, KEYWORD_AGGREGATOR "%s %s\n",                  done = ccs_io_printf(head, CCS_KEYWORD_AGGREGATOR "%s %s\n",
460                                     ptr->original_name->name,                                       ptr->original_name->name,
461                                     ptr->aggregated_name->name))                                       ptr->aggregated_name->name);
462                          goto out;                  if (!done)
463                            break;
464          }          }
465          return true;          return done;
  out:  
         return false;  
466  }  }
467    
468  /**  /**
469   * ccs_write_aggregator_policy - Write "struct aggregator_entry" list.   * ccs_write_aggregator_policy - Write "struct ccs_aggregator_entry" list.
470   *   *
471   * @data:      String to parse.   * @data:      String to parse.
472   * @is_delete: True if it is a delete request.   * @is_delete: True if it is a delete request.
# Line 697  bool ccs_read_aggregator_policy(struct c Line 475  bool ccs_read_aggregator_policy(struct c
475   */   */
476  int ccs_write_aggregator_policy(char *data, const bool is_delete)  int ccs_write_aggregator_policy(char *data, const bool is_delete)
477  {  {
478          char *cp = strchr(data, ' ');          char *w[2];
479          if (!cp)          if (!ccs_tokenize(data, w, sizeof(w)) || !w[1][0])
480                  return -EINVAL;                  return -EINVAL;
481          *cp++ = '\0';          return ccs_update_aggregator_entry(w[0], w[1], is_delete);
         return update_aggregator_entry(data, cp, is_delete);  
482  }  }
483    
484  /* Domain create/delete/undelete handler. */  /* Domain create/delete handler. */
   
 /* #define DEBUG_DOMAIN_UNDELETE */  
485    
486  /**  /**
487   * ccs_delete_domain - Delete a domain.   * ccs_delete_domain - Delete a domain.
# Line 717  int ccs_write_aggregator_policy(char *da Line 492  int ccs_write_aggregator_policy(char *da
492   */   */
493  int ccs_delete_domain(char *domainname)  int ccs_delete_domain(char *domainname)
494  {  {
495          struct domain_info *domain;          struct ccs_domain_info *domain;
496          struct path_info name;          struct ccs_path_info name;
497          name.name = domainname;          name.name = domainname;
498          ccs_fill_path_info(&name);          ccs_fill_path_info(&name);
499          mutex_lock(&domain_list_lock);          mutex_lock(&ccs_policy_lock);
 #ifdef DEBUG_DOMAIN_UNDELETE  
         printk(KERN_DEBUG "ccs_delete_domain %s\n", domainname);  
         list1_for_each_entry(domain, &domain_list, list) {  
                 if (ccs_pathcmp(domain->domainname, &name))  
                         continue;  
                 printk(KERN_DEBUG "List: %p %u\n", domain, domain->is_deleted);  
         }  
 #endif  
500          /* Is there an active domain? */          /* Is there an active domain? */
501          list1_for_each_entry(domain, &domain_list, list) {          list_for_each_entry_rcu(domain, &ccs_domain_list, list) {
502                  struct domain_info *domain2;                  /* Never delete ccs_kernel_domain */
503                  /* Never delete KERNEL_DOMAIN */                  if (domain == &ccs_kernel_domain)
                 if (domain == &KERNEL_DOMAIN)  
504                          continue;                          continue;
505                  if (domain->is_deleted ||                  if (domain->is_deleted ||
506                      ccs_pathcmp(domain->domainname, &name))                      ccs_pathcmp(domain->domainname, &name))
507                          continue;                          continue;
508                  /* Mark already deleted domains as non undeletable. */                  domain->is_deleted = true;
                 list1_for_each_entry(domain2, &domain_list, list) {  
                         if (!domain2->is_deleted ||  
                             ccs_pathcmp(domain2->domainname, &name))  
                                 continue;  
 #ifdef DEBUG_DOMAIN_UNDELETE  
                         if (domain2->is_deleted != 255)  
                                 printk(KERN_DEBUG  
                                        "Marked %p as non undeletable\n",  
                                        domain2);  
 #endif  
                         domain2->is_deleted = 255;  
                 }  
                 /* Delete and mark active domain as undeletable. */  
                 domain->is_deleted = 1;  
 #ifdef DEBUG_DOMAIN_UNDELETE  
                 printk(KERN_DEBUG "Marked %p as undeletable\n", domain);  
 #endif  
509                  break;                  break;
510          }          }
511          mutex_unlock(&domain_list_lock);          mutex_unlock(&ccs_policy_lock);
512          return 0;          return 0;
513  }  }
514    
515  /**  /**
  * ccs_undelete_domain - Undelete a domain.  
  *  
  * @domainname: The name of domain.  
  *  
  * Returns pointer to "struct domain_info" on success, NULL otherwise.  
  */  
 struct domain_info *ccs_undelete_domain(const char *domainname)  
 {  
         struct domain_info *domain;  
         struct domain_info *candidate_domain = NULL;  
         struct path_info name;  
         name.name = domainname;  
         ccs_fill_path_info(&name);  
         mutex_lock(&domain_list_lock);  
 #ifdef DEBUG_DOMAIN_UNDELETE  
         printk(KERN_DEBUG "ccs_undelete_domain %s\n", domainname);  
         list1_for_each_entry(domain, &domain_list, list) {  
                 if (ccs_pathcmp(domain->domainname, &name))  
                         continue;  
                 printk(KERN_DEBUG "List: %p %u\n", domain, domain->is_deleted);  
         }  
 #endif  
         list1_for_each_entry(domain, &domain_list, list) {  
                 if (ccs_pathcmp(&name, domain->domainname))  
                         continue;  
                 if (!domain->is_deleted) {  
                         /* This domain is active. I can't undelete. */  
                         candidate_domain = NULL;  
 #ifdef DEBUG_DOMAIN_UNDELETE  
                         printk(KERN_DEBUG "%p is active. I can't undelete.\n",  
                                domain);  
 #endif  
                         break;  
                 }  
                 /* Is this domain undeletable? */  
                 if (domain->is_deleted == 1)  
                         candidate_domain = domain;  
         }  
         if (candidate_domain) {  
                 candidate_domain->is_deleted = 0;  
 #ifdef DEBUG_DOMAIN_UNDELETE  
                 printk(KERN_DEBUG "%p was undeleted.\n", candidate_domain);  
 #endif  
         }  
         mutex_unlock(&domain_list_lock);  
         return candidate_domain;  
 }  
   
 /**  
516   * ccs_find_or_assign_new_domain - Create a domain.   * ccs_find_or_assign_new_domain - Create a domain.
517   *   *
518   * @domainname: The name of domain.   * @domainname: The name of domain.
519   * @profile:    Profile number to assign if the domain was newly created.   * @profile:    Profile number to assign if the domain was newly created.
520   *   *
521   * Returns pointer to "struct domain_info" on success, NULL otherwise.   * Returns pointer to "struct ccs_domain_info" on success, NULL otherwise.
522   */   */
523  struct domain_info *ccs_find_or_assign_new_domain(const char *domainname,  struct ccs_domain_info *ccs_find_or_assign_new_domain(const char *domainname,
524                                                    const u8 profile)                                                        const u8 profile)
525  {  {
526          struct domain_info *domain = NULL;          struct ccs_domain_info *entry;
527          const struct path_info *saved_domainname;          struct ccs_domain_info *domain;
528          mutex_lock(&domain_list_lock);          const struct ccs_path_info *saved_domainname;
529          domain = ccs_find_domain(domainname);          bool found = false;
530          if (domain)  
531                  goto out;          if (!ccs_is_correct_domain(domainname))
532          if (!ccs_is_correct_domain(domainname, __func__))                  return NULL;
533                  goto out;          saved_domainname = ccs_get_name(domainname);
         saved_domainname = ccs_save_name(domainname);  
534          if (!saved_domainname)          if (!saved_domainname)
535                  goto out;                  return NULL;
536          /* Can I reuse memory of deleted domain? */          entry = kzalloc(sizeof(*entry), GFP_KERNEL);
537          list1_for_each_entry(domain, &domain_list, list) {          mutex_lock(&ccs_policy_lock);
538                  struct task_struct *p;          list_for_each_entry_rcu(domain, &ccs_domain_list, list) {
539                  struct acl_info *ptr;                  if (domain->is_deleted ||
540                  bool flag;                      ccs_pathcmp(saved_domainname, domain->domainname))
                 if (!domain->is_deleted ||  
                     domain->domainname != saved_domainname)  
                         continue;  
                 flag = false;  
                 /***** CRITICAL SECTION START *****/  
                 read_lock(&tasklist_lock);  
                 for_each_process(p) {  
                         if (p->domain_info != domain)  
                                 continue;  
                         flag = true;  
                         break;  
                 }  
                 read_unlock(&tasklist_lock);  
                 /***** CRITICAL SECTION END *****/  
                 if (flag)  
541                          continue;                          continue;
542  #ifdef DEBUG_DOMAIN_UNDELETE                  found = true;
543                  printk(KERN_DEBUG "Reusing %p %s\n", domain,                  break;
                        domain->domainname->name);  
 #endif  
                 list1_for_each_entry(ptr, &domain->acl_info_list, list) {  
                         ptr->type |= ACL_DELETED;  
                 }  
                 ccs_set_domain_flag(domain, true, domain->flags);  
                 domain->profile = profile;  
                 domain->quota_warned = false;  
                 mb(); /* Avoid out-of-order execution. */  
                 domain->is_deleted = 0;  
                 goto out;  
         }  
         /* No memory reusable. Create using new memory. */  
         domain = ccs_alloc_element(sizeof(*domain));  
         if (domain) {  
                 INIT_LIST1_HEAD(&domain->acl_info_list);  
                 domain->domainname = saved_domainname;  
                 domain->profile = profile;  
                 list1_add_tail_mb(&domain->list, &domain_list);  
         }  
  out:  
         mutex_unlock(&domain_list_lock);  
         return domain;  
 }  
   
 /**  
  * get_argv0 - Get argv[0].  
  *  
  * @bprm: Pointer to "struct linux_binprm".  
  * @tmp:  Buffer for temporary use.  
  *  
  * Returns true on success, false otherwise.  
  */  
 static bool get_argv0(struct linux_binprm *bprm, struct ccs_page_buffer *tmp)  
 {  
         char *arg_ptr = tmp->buffer;  
         int arg_len = 0;  
         unsigned long pos = bprm->p;  
         int i = pos / PAGE_SIZE;  
         int offset = pos % PAGE_SIZE;  
         bool done = false;  
         if (!bprm->argc)  
                 goto out;  
         while (1) {  
                 struct page *page;  
                 const char *kaddr;  
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU)  
                 if (get_user_pages(current, bprm->mm, pos, 1, 0, 1, &page,  
                                    NULL) <= 0)  
                         goto out;  
                 pos += PAGE_SIZE - offset;  
 #else  
                 page = bprm->page[i];  
 #endif  
                 /* Map. */  
                 kaddr = kmap(page);  
                 if (!kaddr) { /* Mapping failed. */  
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU)  
                         put_page(page);  
 #endif  
                         goto out;  
                 }  
                 /* Read. */  
                 while (offset < PAGE_SIZE) {  
                         const unsigned char c = kaddr[offset++];  
                         if (c && arg_len < CCS_MAX_PATHNAME_LEN - 10) {  
                                 if (c == '\\') {  
                                         arg_ptr[arg_len++] = '\\';  
                                         arg_ptr[arg_len++] = '\\';  
                                 } else if (c == '/') {  
                                         arg_len = 0;  
                                 } else if (c > ' ' && c < 127) {  
                                         arg_ptr[arg_len++] = c;  
                                 } else {  
                                         arg_ptr[arg_len++] = '\\';  
                                         arg_ptr[arg_len++] = (c >> 6) + '0';  
                                         arg_ptr[arg_len++]  
                                                 = ((c >> 3) & 7) + '0';  
                                         arg_ptr[arg_len++] = (c & 7) + '0';  
                                 }  
                         } else {  
                                 arg_ptr[arg_len] = '\0';  
                                 done = true;  
                                 break;  
                         }  
                 }  
                 /* Unmap. */  
                 kunmap(page);  
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU)  
                 put_page(page);  
 #endif  
                 i++;  
                 offset = 0;  
                 if (done)  
                         break;  
544          }          }
545          return true;          if (!found && ccs_memory_ok(entry, sizeof(*entry))) {
546   out:                  INIT_LIST_HEAD(&entry->acl_info_list);
547          return false;                  entry->domainname = saved_domainname;
548                    saved_domainname = NULL;
549                    entry->profile = profile;
550                    list_add_tail_rcu(&entry->list, &ccs_domain_list);
551                    domain = entry;
552                    entry = NULL;
553                    found = true;
554            }
555            mutex_unlock(&ccs_policy_lock);
556            ccs_put_name(saved_domainname);
557            kfree(entry);
558            return found ? domain : NULL;
559  }  }
560    
561  /**  /**
562   * find_next_domain - Find a domain.   * ccs_find_next_domain - Find a domain.
563   *   *
564   * @r:       Pointer to "struct ccs_request_info".   * @ee: Pointer to "struct ccs_execve_entry".
  * @handler: Pathname to verify. May be NULL.  
565   *   *
566   * Returns 0 on success, negative value otherwise.   * Returns 0 on success, negative value otherwise.
567     *
568     * Caller holds ccs_read_lock().
569   */   */
570  static int find_next_domain(struct ccs_request_info *r,  static int ccs_find_next_domain(struct ccs_execve_entry *ee)
                             const struct path_info *handler)  
571  {  {
572          /*          struct ccs_request_info *r = &ee->r;
573           * This function assumes that the size of buffer returned by          const struct ccs_path_info *handler = ee->handler;
574           * ccs_realpath() = CCS_MAX_PATHNAME_LEN.          struct ccs_domain_info *domain = NULL;
          */  
         struct domain_info *domain = NULL;  
575          const char *old_domain_name = r->domain->domainname->name;          const char *old_domain_name = r->domain->domainname->name;
576          struct linux_binprm *bprm = r->bprm;          struct linux_binprm *bprm = ee->bprm;
577          struct ccs_page_buffer *tmp = r->obj->tmp;          const u32 ccs_flags = current->ccs_flags;
578          const char *original_name = bprm->filename;          struct ccs_path_info rn = { }; /* real name */
579          const u8 mode = r->mode;          struct ccs_path_info ln; /* last name */
         const bool is_enforce = (mode == 3);  
         const u32 tomoyo_flags = current->tomoyo_flags;  
         char *new_domain_name = NULL;  
         char *real_program_name = NULL;  
         char *symlink_program_name = NULL;  
         struct path_info rn; /* real name */  
         struct path_info sn; /* symlink name */  
         struct path_info ln; /* last name */  
580          int retval;          int retval;
581            bool need_kfree = false;
582          {          ln.name = ccs_last_word(old_domain_name);
583                  /*          ccs_fill_path_info(&ln);
                  * Built-in initializers. This is needed because policies are  
                  * not loaded until starting /sbin/init.  
                  */  
                 static bool first = true;  
                 if (first) {  
                         update_domain_initializer_entry(NULL, "/sbin/hotplug",  
                                                         false, false);  
                         update_domain_initializer_entry(NULL, "/sbin/modprobe",  
                                                         false, false);  
                         first = false;  
                 }  
         }  
   
584   retry:   retry:
585          current->tomoyo_flags = tomoyo_flags;          current->ccs_flags = ccs_flags;
586          r->cond = NULL;          r->cond = NULL;
587          /* Get ccs_realpath of program. */          if (need_kfree) {
588          retval = -ENOENT; /* I hope ccs_realpath() won't fail with -ENOMEM. */                  kfree(rn.name);
589          ccs_free(real_program_name);                  need_kfree = false;
590          real_program_name = ccs_realpath(original_name);          }
         if (!real_program_name)  
                 goto out;  
         /* Get ccs_realpath of symbolic link. */  
         ccs_free(symlink_program_name);  
         symlink_program_name = ccs_realpath_nofollow(original_name);  
         if (!symlink_program_name)  
                 goto out;  
591    
592          rn.name = real_program_name;          /* Get symlink's pathname of program. */
593          ccs_fill_path_info(&rn);          retval = ccs_symlink_path(bprm->filename, &rn);
594          sn.name = symlink_program_name;          if (retval < 0)
595          ccs_fill_path_info(&sn);                  goto out;
596          ln.name = ccs_get_last_name(r->domain);          need_kfree = true;
         ccs_fill_path_info(&ln);  
597    
598          if (handler) {          if (handler) {
599                  if (ccs_pathcmp(&rn, handler)) {                  if (ccs_pathcmp(&rn, handler)) {
# Line 1037  static int find_next_domain(struct ccs_r Line 606  static int find_next_domain(struct ccs_r
606                          }                          }
607                          goto out;                          goto out;
608                  }                  }
609                  goto calculate_domain;          } else {
610          }                  struct ccs_aggregator_entry *ptr;
611                    /* Check 'aggregator' directive. */
612          /* Check 'alias' directive. */                  list_for_each_entry_rcu(ptr, &ccs_aggregator_list, list) {
         if (ccs_pathcmp(&rn, &sn)) {  
                 struct alias_entry *ptr;  
                 /* Is this program allowed to be called via symbolic links? */  
                 list1_for_each_entry(ptr, &alias_list, list) {  
613                          if (ptr->is_deleted ||                          if (ptr->is_deleted ||
614                              ccs_pathcmp(&rn, ptr->original_name) ||                              !ccs_path_matches_pattern(&rn, ptr->original_name))
                             ccs_pathcmp(&sn, ptr->aliased_name))  
615                                  continue;                                  continue;
616                          memset(real_program_name, 0, CCS_MAX_PATHNAME_LEN);                          kfree(rn.name);
617                          strncpy(real_program_name, ptr->aliased_name->name,                          need_kfree = false;
618                                  CCS_MAX_PATHNAME_LEN - 1);                          /* This is OK because it is read only. */
619                          ccs_fill_path_info(&rn);                          rn = *ptr->aggregated_name;
620                          break;                          break;
621                  }                  }
         }  
622    
623          /* Compare basename of real_program_name and argv[0] */                  /* Check execute permission. */
624          r->mode = ccs_check_flags(r->domain, CCS_TOMOYO_MAC_FOR_ARGV0);                  retval = ccs_exec_perm(r, &rn);
625          if (bprm->argc > 0 && r->mode) {                  if (retval == 1)
626                  char *base_argv0 = tmp->buffer;                          goto retry;
627                  const char *base_filename;                  if (retval < 0)
                 retval = -ENOMEM;  
                 if (!get_argv0(bprm, tmp))  
628                          goto out;                          goto out;
                 base_filename = strrchr(real_program_name, '/');  
                 if (!base_filename)  
                         base_filename = real_program_name;  
                 else  
                         base_filename++;  
                 if (strcmp(base_argv0, base_filename)) {  
                         retval = ccs_check_argv0_perm(r, &rn, base_argv0);  
                         if (retval == 1)  
                                 goto retry;  
                         if (retval < 0)  
                                 goto out;  
                 }  
         }  
   
         /* Check 'aggregator' directive. */  
         {  
                 struct aggregator_entry *ptr;  
                 /* Is this program allowed to be aggregated? */  
                 list1_for_each_entry(ptr, &aggregator_list, list) {  
                         if (ptr->is_deleted ||  
                             !ccs_path_matches_pattern(&rn, ptr->original_name))  
                                 continue;  
                         memset(real_program_name, 0, CCS_MAX_PATHNAME_LEN);  
                         strncpy(real_program_name, ptr->aggregated_name->name,  
                                 CCS_MAX_PATHNAME_LEN - 1);  
                         ccs_fill_path_info(&rn);  
                         break;  
                 }  
629          }          }
630    
631          /* Check execute permission. */          /* Calculate domain to transit to. */
632          r->mode = mode;          if (ccs_is_domain_initializer(r->domain->domainname, &rn, &ln)) {
633          retval = ccs_check_exec_perm(r, &rn);                  /* Transit to the child of ccs_kernel_domain domain. */
634          if (retval == 1)                  snprintf(ee->tmp, CCS_EXEC_TMPSIZE - 1, ROOT_NAME " " "%s",
635                  goto retry;                           rn.name);
636          if (retval < 0)          } else if (r->domain == &ccs_kernel_domain && !ccs_policy_loaded) {
                 goto out;  
   
  calculate_domain:  
         new_domain_name = tmp->buffer;  
         if (is_domain_initializer(r->domain->domainname, &rn, &ln)) {  
                 /* Transit to the child of KERNEL_DOMAIN domain. */  
                 snprintf(new_domain_name, CCS_MAX_PATHNAME_LEN + 1,  
                          ROOT_NAME " " "%s", real_program_name);  
         } else if (r->domain == &KERNEL_DOMAIN && !sbin_init_started) {  
637                  /*                  /*
638                   * Needn't to transit from kernel domain before starting                   * Needn't to transit from kernel domain before starting
639                   * /sbin/init. But transit from kernel domain if executing                   * /sbin/init. But transit from kernel domain if executing
640                   * initializers because they might start before /sbin/init.                   * initializers because they might start before /sbin/init.
641                   */                   */
642                  domain = r->domain;                  domain = r->domain;
643          } else if (is_domain_keeper(r->domain->domainname, &rn, &ln)) {          } else if (ccs_is_domain_keeper(r->domain->domainname, &rn, &ln)) {
644                  /* Keep current domain. */                  /* Keep current domain. */
645                  domain = r->domain;                  domain = r->domain;
646          } else {          } else {
647                  /* Normal domain transition. */                  /* Normal domain transition. */
648                  snprintf(new_domain_name, CCS_MAX_PATHNAME_LEN + 1,                  snprintf(ee->tmp, CCS_EXEC_TMPSIZE - 1, "%s %s",
649                           "%s %s", old_domain_name, real_program_name);                           old_domain_name, rn.name);
650          }          }
651          if (domain || strlen(new_domain_name) >= CCS_MAX_PATHNAME_LEN)          if (domain || strlen(ee->tmp) >= CCS_EXEC_TMPSIZE - 10)
652                  goto done;                  goto done;
653          domain = ccs_find_domain(new_domain_name);          domain = ccs_find_domain(ee->tmp);
654          if (domain)          if (domain)
655                  goto done;                  goto done;
656          if (is_enforce) {          if (r->mode == CCS_MAC_MODE_ENFORCING) {
657                  int error = ccs_check_supervisor(r,                  int error = ccs_supervisor(r, "# wants to create domain\n"
658                                                   "# wants to create domain\n"                                             "%s\n", ee->tmp);
                                                  "%s\n", new_domain_name);  
659                  if (error == 1)                  if (error == 1)
660                          goto retry;                          goto retry;
661                  if (error < 0)                  if (error < 0)
662                          goto done;                          goto done;
663          }          }
664          domain = ccs_find_or_assign_new_domain(new_domain_name, r->profile);          domain = ccs_find_or_assign_new_domain(ee->tmp, r->profile);
665          if (domain)          if (domain)
666                  audit_domain_creation_log(domain);                  ccs_audit_domain_creation_log(r->domain);
667   done:   done:
668          if (!domain) {          if (!domain) {
669                  printk(KERN_WARNING "TOMOYO-ERROR: Domain '%s' not defined.\n",                  printk(KERN_WARNING "ERROR: Domain '%s' not defined.\n",
670                         new_domain_name);                         ee->tmp);
671                  if (is_enforce)                  if (r->mode == CCS_MAC_MODE_ENFORCING)
672                          retval = -EPERM;                          retval = -EPERM;
673                  else {                  else {
674                          retval = 0;                          retval = 0;
675                          ccs_set_domain_flag(r->domain, false,                          r->domain->domain_transition_failed = true;
                                             DOMAIN_FLAGS_TRANSITION_FAILED);  
676                  }                  }
677          } else {          } else {
678                  retval = 0;                  retval = 0;
679          }          }
680   out:   out:
         ccs_free(real_program_name);  
         ccs_free(symlink_program_name);  
681          if (domain)          if (domain)
682                  r->domain = domain;                  r->domain = domain;
683            if (need_kfree)
684                    kfree(rn.name);
685          return retval;          return retval;
686  }  }
687    
688  /**  /**
689   * check_environ - Check permission for environment variable names.   * ccs_environ - Check permission for environment variable names.
690   *   *
691   * @r: Pointer to "struct ccs_request_info".   * @ee: Pointer to "struct ccs_execve_entry".
692   *   *
693   * Returns 0 on success, negative value otherwise.   * Returns 0 on success, negative value otherwise.
694   */   */
695  static int check_environ(struct ccs_request_info *r)  static int ccs_environ(struct ccs_execve_entry *ee)
696  {  {
697          struct linux_binprm *bprm = r->bprm;          struct ccs_request_info *r = &ee->r;
698          struct ccs_page_buffer *tmp = r->obj->tmp;          struct linux_binprm *bprm = ee->bprm;
699          char *arg_ptr = tmp->buffer;          char *arg_ptr = ee->tmp;
700          int arg_len = 0;          int arg_len = 0;
701          unsigned long pos = bprm->p;          unsigned long pos = bprm->p;
         int i = pos / PAGE_SIZE;  
702          int offset = pos % PAGE_SIZE;          int offset = pos % PAGE_SIZE;
703          int argv_count = bprm->argc;          int argv_count = bprm->argc;
704          int envp_count = bprm->envc;          int envp_count = bprm->envc;
# Line 1186  static int check_environ(struct ccs_requ Line 707  static int check_environ(struct ccs_requ
707          if (!r->mode || !envp_count)          if (!r->mode || !envp_count)
708                  return 0;                  return 0;
709          while (error == -ENOMEM) {          while (error == -ENOMEM) {
710                  struct page *page;                  if (!ccs_dump_page(bprm, pos, &ee->dump))
                 const char *kaddr;  
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU)  
                 if (get_user_pages(current, bprm->mm, pos, 1, 0, 1, &page,  
                                    NULL) <= 0)  
711                          goto out;                          goto out;
712                  pos += PAGE_SIZE - offset;                  pos += PAGE_SIZE - offset;
 #else  
                 page = bprm->page[i];  
 #endif  
                 /* Map. */  
                 kaddr = kmap(page);  
                 if (!kaddr) { /* Mapping failed. */  
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU)  
                         put_page(page);  
 #endif  
                         goto out;  
                 }  
713                  /* Read. */                  /* Read. */
714                  while (argv_count && offset < PAGE_SIZE) {                  while (argv_count && offset < PAGE_SIZE) {
715                            const char *kaddr = ee->dump.data;
716                          if (!kaddr[offset++])                          if (!kaddr[offset++])
717                                  argv_count--;                                  argv_count--;
718                  }                  }
719                  if (argv_count)                  if (argv_count) {
720                          goto unmap_page;                          offset = 0;
721                            continue;
722                    }
723                  while (offset < PAGE_SIZE) {                  while (offset < PAGE_SIZE) {
724                            const char *kaddr = ee->dump.data;
725                          const unsigned char c = kaddr[offset++];                          const unsigned char c = kaddr[offset++];
726                          if (c && arg_len < CCS_MAX_PATHNAME_LEN - 10) {                          if (c && arg_len < CCS_EXEC_TMPSIZE - 10) {
727                                  if (c == '=') {                                  if (c == '=') {
728                                          arg_ptr[arg_len++] = '\0';                                          arg_ptr[arg_len++] = '\0';
729                                  } else if (c == '\\') {                                  } else if (c == '\\') {
# Line 1233  static int check_environ(struct ccs_requ Line 743  static int check_environ(struct ccs_requ
743                          }                          }
744                          if (c)                          if (c)
745                                  continue;                                  continue;
746                          if (ccs_check_env_perm(r, arg_ptr)) {                          if (ccs_env_perm(r, arg_ptr)) {
747                                  error = -EPERM;                                  error = -EPERM;
748                                  break;                                  break;
749                          }                          }
# Line 1243  static int check_environ(struct ccs_requ Line 753  static int check_environ(struct ccs_requ
753                          }                          }
754                          arg_len = 0;                          arg_len = 0;
755                  }                  }
  unmap_page:  
                 /* Unmap. */  
                 kunmap(page);  
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU)  
                 put_page(page);  
 #endif  
                 i++;  
756                  offset = 0;                  offset = 0;
757          }          }
758   out:   out:
# Line 1259  static int check_environ(struct ccs_requ Line 762  static int check_environ(struct ccs_requ
762  }  }
763    
764  /**  /**
765   * unescape - Unescape escaped string.   * ccs_unescape - Unescape escaped string.
766   *   *
767   * @dest: String to unescape.   * @dest: String to unescape.
768   *   *
769   * Returns nothing.   * Returns nothing.
770   */   */
771  static void unescape(unsigned char *dest)  static void ccs_unescape(unsigned char *dest)
772  {  {
773          unsigned char *src = dest;          unsigned char *src = dest;
774          unsigned char c;          unsigned char c;
# Line 1298  static void unescape(unsigned char *dest Line 801  static void unescape(unsigned char *dest
801  }  }
802    
803  /**  /**
804   * root_depth - Get number of directories to strip.   * ccs_root_depth - Get number of directories to strip.
805   *   *
806   * @dentry: Pointer to "struct dentry".   * @dentry: Pointer to "struct dentry".
807   * @vfsmnt: Pointer to "struct vfsmount".   * @vfsmnt: Pointer to "struct vfsmount".
808   *   *
809   * Returns number of directories to strip.   * Returns number of directories to strip.
810   */   */
811  static inline int root_depth(struct dentry *dentry, struct vfsmount *vfsmnt)  static inline int ccs_root_depth(struct dentry *dentry, struct vfsmount *vfsmnt)
812  {  {
813          int depth = 0;          int depth = 0;
         /***** CRITICAL SECTION START *****/  
814          ccs_realpath_lock();          ccs_realpath_lock();
815          for (;;) {          for (;;) {
816                  if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {                  if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
# Line 1323  static inline int root_depth(struct dent Line 825  static inline int root_depth(struct dent
825                  depth++;                  depth++;
826          }          }
827          ccs_realpath_unlock();          ccs_realpath_unlock();
         /***** CRITICAL SECTION END *****/  
828          return depth;          return depth;
829  }  }
830    
831  /**  /**
832   * get_root_depth - return the depth of root directory.   * ccs_get_root_depth - return the depth of root directory.
833   *   *
834   * Returns number of directories to strip.   * Returns number of directories to strip.
835   */   */
836  static int get_root_depth(void)  static int ccs_get_root_depth(void)
837  {  {
838          int depth;          int depth;
839          struct dentry *dentry;          struct dentry *dentry;
# Line 1340  static int get_root_depth(void) Line 841  static int get_root_depth(void)
841  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
842          struct path root;          struct path root;
843  #endif  #endif
         /***** CRITICAL SECTION START *****/  
844          read_lock(&current->fs->lock);          read_lock(&current->fs->lock);
845  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
846          root = current->fs->root;          root = current->fs->root;
# Line 1352  static int get_root_depth(void) Line 852  static int get_root_depth(void)
852          vfsmnt = mntget(current->fs->rootmnt);          vfsmnt = mntget(current->fs->rootmnt);
853  #endif  #endif
854          read_unlock(&current->fs->lock);          read_unlock(&current->fs->lock);
855          /***** CRITICAL SECTION END *****/          depth = ccs_root_depth(dentry, vfsmnt);
         depth = root_depth(dentry, vfsmnt);  
856  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
857          path_put(&root);          path_put(&root);
858  #else  #else
# Line 1363  static int get_root_depth(void) Line 862  static int get_root_depth(void)
862          return depth;          return depth;
863  }  }
864    
865    static LIST_HEAD(ccs_execve_list);
866    static DEFINE_SPINLOCK(ccs_execve_list_lock);
867    
868    /**
869     * ccs_allocate_execve_entry - Allocate memory for execve().
870     *
871     * Returns pointer to "struct ccs_execve_entry" on success, NULL otherwise.
872     */
873    static struct ccs_execve_entry *ccs_allocate_execve_entry(void)
874    {
875            struct ccs_execve_entry *ee = kzalloc(sizeof(*ee), GFP_KERNEL);
876            if (!ee)
877                    return NULL;
878            ee->tmp = kzalloc(CCS_EXEC_TMPSIZE, GFP_KERNEL);
879            if (!ee->tmp) {
880                    kfree(ee);
881                    return NULL;
882            }
883            ee->reader_idx = ccs_read_lock();
884            /* ee->dump->data is allocated by ccs_dump_page(). */
885            ee->task = current;
886            spin_lock(&ccs_execve_list_lock);
887            list_add(&ee->list, &ccs_execve_list);
888            spin_unlock(&ccs_execve_list_lock);
889            return ee;
890    }
891    
892    /**
893     * ccs_find_execve_entry - Find ccs_execve_entry of current process.
894     *
895     * Returns pointer to "struct ccs_execve_entry" on success, NULL otherwise.
896     */
897    static struct ccs_execve_entry *ccs_find_execve_entry(void)
898    {
899            struct task_struct *task = current;
900            struct ccs_execve_entry *ee = NULL;
901            struct ccs_execve_entry *p;
902            spin_lock(&ccs_execve_list_lock);
903            list_for_each_entry(p, &ccs_execve_list, list) {
904                    if (p->task != task)
905                            continue;
906                    ee = p;
907                    break;
908            }
909            spin_unlock(&ccs_execve_list_lock);
910            return ee;
911    }
912    
913  /**  /**
914   * try_alt_exec - Try to start execute handler.   * ccs_free_execve_entry - Free memory for execve().
915   *   *
916   * @r:           Pointer to "struct ccs_request_info".   * @ee: Pointer to "struct ccs_execve_entry".
917   * @handler:     Pointer to the name of execute handler.   */
918   * @eh_path:     Pointer to pointer to the name of execute handler.  static void ccs_free_execve_entry(struct ccs_execve_entry *ee)
919    {
920            if (!ee)
921                    return;
922            spin_lock(&ccs_execve_list_lock);
923            list_del(&ee->list);
924            spin_unlock(&ccs_execve_list_lock);
925            kfree(ee->handler_path);
926            kfree(ee->tmp);
927            kfree(ee->dump.data);
928            ccs_read_unlock(ee->reader_idx);
929            kfree(ee);
930    }
931    
932    /**
933     * ccs_try_alt_exec - Try to start execute handler.
934     *
935     * @ee: Pointer to "struct ccs_execve_entry".
936   *   *
937   * Returns 0 on success, negative value otherwise.   * Returns 0 on success, negative value otherwise.
938   */   */
939  static int try_alt_exec(struct ccs_request_info *r,  static int ccs_try_alt_exec(struct ccs_execve_entry *ee)
                         const struct path_info *handler, char **eh_path)  
940  {  {
941          /*          /*
942           * Contents of modified bprm.           * Contents of modified bprm.
# Line 1389  static int try_alt_exec(struct ccs_reque Line 952  static int try_alt_exec(struct ccs_reque
952           * modified bprm->argv[0]           * modified bprm->argv[0]
953           *    = the program's name specified by execute_handler           *    = the program's name specified by execute_handler
954           * modified bprm->argv[1]           * modified bprm->argv[1]
955           *    = current->domain_info->domainname->name           *    = ccs_current_domain()->domainname->name
956           * modified bprm->argv[2]           * modified bprm->argv[2]
957           *    = the current process's name           *    = the current process's name
958           * modified bprm->argv[3]           * modified bprm->argv[3]
# Line 1411  static int try_alt_exec(struct ccs_reque Line 974  static int try_alt_exec(struct ccs_reque
974           * modified bprm->argv[bprm->envc + bprm->argc + 6]           * modified bprm->argv[bprm->envc + bprm->argc + 6]
975           *     = original bprm->envp[bprm->envc - 1]           *     = original bprm->envp[bprm->envc - 1]
976           */           */
977          struct linux_binprm *bprm = r->bprm;          struct linux_binprm *bprm = ee->bprm;
978          struct file *filp;          struct file *filp;
979          int retval;          int retval;
980          const int original_argc = bprm->argc;          const int original_argc = bprm->argc;
981          const int original_envc = bprm->envc;          const int original_envc = bprm->envc;
982          struct task_struct *task = current;          struct task_struct *task = current;
         char *buffer = r->obj->tmp->buffer;  
         /* Allocate memory for execute handler's pathname. */  
         char *execute_handler = ccs_alloc(sizeof(struct ccs_page_buffer),  
                                           false);  
         *eh_path = execute_handler;  
         if (!execute_handler)  
                 return -ENOMEM;  
         strncpy(execute_handler, handler->name,  
                 sizeof(struct ccs_page_buffer) - 1);  
         unescape(execute_handler);  
983    
984          /* Close the requested program's dentry. */          /* Close the requested program's dentry. */
985          allow_write_access(bprm->file);          allow_write_access(bprm->file);
986          fput(bprm->file);          fput(bprm->file);
987          bprm->file = NULL;          bprm->file = NULL;
988    
989          { /* Adjust root directory for open_exec(). */          /* Invalidate page dump cache. */
990                  int depth = get_root_depth();          ee->dump.page = NULL;
                 char *cp = execute_handler;  
                 if (!*cp || *cp != '/')  
                         return -ENOENT;  
                 while (depth) {  
                         cp = strchr(cp + 1, '/');  
                         if (!cp)  
                                 return -ENOENT;  
                         depth--;  
                 }  
                 memmove(execute_handler, cp, strlen(cp) + 1);  
         }  
991    
992          /* Move envp[] to argv[] */          /* Move envp[] to argv[] */
993          bprm->argc += bprm->envc;          bprm->argc += bprm->envc;
# Line 1453  static int try_alt_exec(struct ccs_reque Line 995  static int try_alt_exec(struct ccs_reque
995    
996          /* Set argv[6] */          /* Set argv[6] */
997          {          {
998                  snprintf(buffer, sizeof(struct ccs_page_buffer) - 1, "%d",                  char *cp = ee->tmp;
999                           original_envc);                  snprintf(ee->tmp, CCS_EXEC_TMPSIZE - 1, "%d", original_envc);
1000                  retval = copy_strings_kernel(1, &buffer, bprm);                  retval = copy_strings_kernel(1, &cp, bprm);
1001                  if (retval < 0)                  if (retval < 0)
1002                          goto out;                          goto out;
1003                  bprm->argc++;                  bprm->argc++;
# Line 1463  static int try_alt_exec(struct ccs_reque Line 1005  static int try_alt_exec(struct ccs_reque
1005    
1006          /* Set argv[5] */          /* Set argv[5] */
1007          {          {
1008                  snprintf(buffer, sizeof(struct ccs_page_buffer) - 1, "%d",                  char *cp = ee->tmp;
1009                           original_argc);                  snprintf(ee->tmp, CCS_EXEC_TMPSIZE - 1, "%d", original_argc);
1010                  retval = copy_strings_kernel(1, &buffer, bprm);                  retval = copy_strings_kernel(1, &cp, bprm);
1011                  if (retval < 0)                  if (retval < 0)
1012                          goto out;                          goto out;
1013                  bprm->argc++;                  bprm->argc++;
# Line 1481  static int try_alt_exec(struct ccs_reque Line 1023  static int try_alt_exec(struct ccs_reque
1023    
1024          /* Set argv[3] */          /* Set argv[3] */
1025          {          {
1026                  const u32 tomoyo_flags = task->tomoyo_flags;                  char *cp = ee->tmp;
1027                  snprintf(buffer, sizeof(struct ccs_page_buffer) - 1,                  const u32 ccs_flags = task->ccs_flags;
1028                    snprintf(ee->tmp, CCS_EXEC_TMPSIZE - 1,
1029                           "pid=%d uid=%d gid=%d euid=%d egid=%d suid=%d "                           "pid=%d uid=%d gid=%d euid=%d egid=%d suid=%d "
1030                           "sgid=%d fsuid=%d fsgid=%d state[0]=%u "                           "sgid=%d fsuid=%d fsgid=%d state[0]=%u "
1031                           "state[1]=%u state[2]=%u",                           "state[1]=%u state[2]=%u",
1032                           (pid_t) sys_getpid(), task->uid, task->gid, task->euid,                           (pid_t) sys_getpid(), current_uid(), current_gid(),
1033                           task->egid, task->suid, task->sgid, task->fsuid,                           current_euid(), current_egid(), current_suid(),
1034                           task->fsgid, (u8) (tomoyo_flags >> 24),                           current_sgid(), current_fsuid(), current_fsgid(),
1035                           (u8) (tomoyo_flags >> 16), (u8) (tomoyo_flags >> 8));                           (u8) (ccs_flags >> 24), (u8) (ccs_flags >> 16),
1036                  retval = copy_strings_kernel(1, &buffer, bprm);                           (u8) (ccs_flags >> 8));
1037                    retval = copy_strings_kernel(1, &cp, bprm);
1038                  if (retval < 0)                  if (retval < 0)
1039                          goto out;                          goto out;
1040                  bprm->argc++;                  bprm->argc++;
# Line 1501  static int try_alt_exec(struct ccs_reque Line 1045  static int try_alt_exec(struct ccs_reque
1045                  char *exe = (char *) ccs_get_exe();                  char *exe = (char *) ccs_get_exe();
1046                  if (exe) {                  if (exe) {
1047                          retval = copy_strings_kernel(1, &exe, bprm);                          retval = copy_strings_kernel(1, &exe, bprm);
1048                          ccs_free(exe);                          kfree(exe);
1049                  } else {                  } else {
1050                          snprintf(buffer, sizeof(struct ccs_page_buffer) - 1,                          exe = ee->tmp;
1051                                   "<unknown>");                          snprintf(ee->tmp, CCS_EXEC_TMPSIZE - 1, "<unknown>");
1052                          retval = copy_strings_kernel(1, &buffer, bprm);                          retval = copy_strings_kernel(1, &exe, bprm);
1053                  }                  }
1054                  if (retval < 0)                  if (retval < 0)
1055                          goto out;                          goto out;
# Line 1514  static int try_alt_exec(struct ccs_reque Line 1058  static int try_alt_exec(struct ccs_reque
1058    
1059          /* Set argv[1] */          /* Set argv[1] */
1060          {          {
1061                  strncpy(buffer, task->domain_info->domainname->name,                  char *cp = ee->tmp;
1062                          sizeof(struct ccs_page_buffer) - 1);                  snprintf(ee->tmp, CCS_EXEC_TMPSIZE - 1, "%s",
1063                  retval = copy_strings_kernel(1, &buffer, bprm);                           ccs_current_domain()->domainname->name);
1064                    retval = copy_strings_kernel(1, &cp, bprm);
1065                  if (retval < 0)                  if (retval < 0)
1066                          goto out;                          goto out;
1067                  bprm->argc++;                  bprm->argc++;
# Line 1524  static int try_alt_exec(struct ccs_reque Line 1069  static int try_alt_exec(struct ccs_reque
1069    
1070          /* Set argv[0] */          /* Set argv[0] */
1071          {          {
1072                  retval = copy_strings_kernel(1, &execute_handler, bprm);                  int depth = ccs_get_root_depth();
1073                    int len = ee->handler->total_len + 1;
1074                    char *cp = kmalloc(len, GFP_KERNEL);
1075                    if (!cp) {
1076                            retval = ENOMEM;
1077                            goto out;
1078                    }
1079                    ee->handler_path = cp;
1080                    memmove(cp, ee->handler->name, len);
1081                    ccs_unescape(cp);
1082                    retval = -ENOENT;
1083                    if (!*cp || *cp != '/')
1084                            goto out;
1085                    /* Adjust root directory for open_exec(). */
1086                    while (depth) {
1087                            cp = strchr(cp + 1, '/');
1088                            if (!cp)
1089                                    goto out;
1090                            depth--;
1091                    }
1092                    memmove(ee->handler_path, cp, strlen(cp) + 1);
1093                    cp = ee->handler_path;
1094                    retval = copy_strings_kernel(1, &cp, bprm);
1095                  if (retval < 0)                  if (retval < 0)
1096                          goto out;                          goto out;
1097                  bprm->argc++;                  bprm->argc++;
# Line 1536  static int try_alt_exec(struct ccs_reque Line 1103  static int try_alt_exec(struct ccs_reque
1103  #endif  #endif
1104    
1105          /* OK, now restart the process with execute handler program's dentry. */          /* OK, now restart the process with execute handler program's dentry. */
1106          filp = open_exec(execute_handler);          filp = open_exec(ee->handler_path);
1107          if (IS_ERR(filp)) {          if (IS_ERR(filp)) {
1108                  retval = PTR_ERR(filp);                  retval = PTR_ERR(filp);
1109                  goto out;                  goto out;
1110          }          }
1111          bprm->file = filp;          bprm->file = filp;
1112          bprm->filename = execute_handler;          bprm->filename = ee->handler_path;
1113  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)
1114          bprm->interp = execute_handler;          bprm->interp = bprm->filename;
1115  #endif  #endif
1116          retval = prepare_binprm(bprm);          retval = prepare_binprm(bprm);
1117          if (retval < 0)          if (retval < 0)
1118                  goto out;                  goto out;
1119          task->tomoyo_flags |= CCS_DONT_SLEEP_ON_ENFORCE_ERROR;          task->ccs_flags |= CCS_DONT_SLEEP_ON_ENFORCE_ERROR;
1120          retval = find_next_domain(r, handler);          retval = ccs_find_next_domain(ee);
1121          task->tomoyo_flags &= ~CCS_DONT_SLEEP_ON_ENFORCE_ERROR;          task->ccs_flags &= ~CCS_DONT_SLEEP_ON_ENFORCE_ERROR;
1122   out:   out:
1123          return retval;          return retval;
1124  }  }
1125    
1126  /**  /**
1127   * find_execute_handler - Find an execute handler.   * ccs_find_execute_handler - Find an execute handler.
1128   *   *
1129     * @ee:   Pointer to "struct ccs_execve_entry".
1130   * @type: Type of execute handler.   * @type: Type of execute handler.
1131   *   *
1132   * Returns pointer to "struct path_info" if found, NULL otherwise.   * Returns true if found, false otherwise.
1133     *
1134     * Caller holds ccs_read_lock().
1135   */   */
1136  static const struct path_info *find_execute_handler(const u8 type)  static bool ccs_find_execute_handler(struct ccs_execve_entry *ee,
1137                                         const u8 type)
1138  {  {
1139          struct task_struct *task = current;          struct task_struct *task = current;
1140          const struct domain_info *domain = task->domain_info;          const struct ccs_domain_info *domain = ccs_current_domain();
1141          struct acl_info *ptr;          struct ccs_acl_info *ptr;
1142            bool found = false;
1143          /*          /*
1144           * Don't use execute handler if the current process is           * Don't use execute handler if the current process is
1145           * marked as execute handler to avoid infinite execute handler loop.           * marked as execute handler to avoid infinite execute handler loop.
1146           */           */
1147          if (task->tomoyo_flags & TOMOYO_TASK_IS_EXECUTE_HANDLER)          if (task->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)
1148                  return NULL;                  return false;
1149          list1_for_each_entry(ptr, &domain->acl_info_list, list) {          list_for_each_entry(ptr, &domain->acl_info_list, list) {
1150                  struct execute_handler_record *acl;                  struct ccs_execute_handler_record *acl;
1151                  if (ptr->type != type)                  if (ptr->type != type)
1152                          continue;                          continue;
1153                  acl = container_of(ptr, struct execute_handler_record, head);                  acl = container_of(ptr, struct ccs_execute_handler_record,
1154                  return acl->handler;                                     head);
1155                    ee->handler = acl->handler;
1156                    found = true;
1157                    break;
1158          }          }
1159          return NULL;          return found;
1160  }  }
1161    
 /* List of next_domain which is used for checking interpreter's permissions. */  
 struct execve_entry {  
         struct list_head list;  
         struct task_struct *task;  
         struct domain_info *next_domain;  
 };  
   
 static LIST_HEAD(execve_list);  
 static DEFINE_SPINLOCK(execve_list_lock);  
   
1162  /**  /**
1163   * ccs_register_next_domain - Remember next_domain.   * ccs_dump_page - Dump a page to buffer.
1164   *   *
1165   * @next_domain: Pointer to "struct domain_info".   * @bprm: Pointer to "struct linux_binprm".
1166     * @pos:  Location to dump.
1167     * @dump: Poiner to "struct ccs_page_dump".
1168   *   *
1169   * Returns 0 on success, -ENOMEM otherwise.   * Returns true on success, false otherwise.
1170   */   */
1171  static int ccs_register_next_domain(struct domain_info *next_domain)  bool ccs_dump_page(struct linux_binprm *bprm, unsigned long pos,
1172                       struct ccs_page_dump *dump)
1173  {  {
1174          struct execve_entry *ee = kmalloc(sizeof(*ee), GFP_KERNEL);          struct page *page;
1175          if (!ee)          /* dump->data is released by ccs_free_execve_entry(). */
1176                  return -ENOMEM;          if (!dump->data) {
1177          ee->task = current;                  dump->data = kzalloc(PAGE_SIZE, GFP_KERNEL);
1178          ee->next_domain = next_domain;                  if (!dump->data)
1179          /***** CRITICAL SECTION START *****/                          return false;
1180          spin_lock(&execve_list_lock);          }
1181          list_add(&ee->list, &execve_list);          /* Same with get_arg_page(bprm, pos, 0) in fs/exec.c */
1182          spin_unlock(&execve_list_lock);  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU)
1183          /***** CRITICAL SECTION END *****/          if (get_user_pages(current, bprm->mm, pos, 1, 0, 1, &page, NULL) <= 0)
1184          return 0;                  return false;
1185    #elif defined(RHEL_MAJOR) && RHEL_MAJOR == 5 && defined(RHEL_MINOR) && RHEL_MINOR == 3 && defined(CONFIG_MMU)
1186            if (get_user_pages(current, bprm->mm, pos, 1, 0, 1, &page, NULL) <= 0)
1187                    return false;
1188    #else
1189            page = bprm->page[pos / PAGE_SIZE];
1190    #endif
1191            if (page != dump->page) {
1192                    const unsigned int offset = pos % PAGE_SIZE;
1193                    /*
1194                     * Maybe kmap()/kunmap() should be used here.
1195                     * But remove_arg_zero() uses kmap_atomic()/kunmap_atomic().
1196                     * So do I.
1197                     */
1198                    char *kaddr = kmap_atomic(page, KM_USER0);
1199                    dump->page = page;
1200                    memcpy(dump->data + offset, kaddr + offset, PAGE_SIZE - offset);
1201                    kunmap_atomic(kaddr, KM_USER0);
1202            }
1203            /* Same with put_arg_page(page) in fs/exec.c */
1204    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) && defined(CONFIG_MMU)
1205            put_page(page);
1206    #elif defined(RHEL_MAJOR) && RHEL_MAJOR == 5 && defined(RHEL_MINOR) && RHEL_MINOR == 3 && defined(CONFIG_MMU)
1207            put_page(page);
1208    #endif
1209            return true;
1210  }  }
1211    
1212  /**  /**
1213   * ccs_fetch_next_domain - Fetch next_domain from the list.   * ccs_fetch_next_domain - Fetch next_domain from the list.
1214   *   *
1215   * Returns pointer to "struct domain_info" which will be used if execve()   * Returns pointer to "struct ccs_domain_info" which will be used if execve()
1216   * succeeds. This function does not return NULL.   * succeeds. This function does not return NULL.
1217   */   */
1218  struct domain_info *ccs_fetch_next_domain(void)  struct ccs_domain_info *ccs_fetch_next_domain(void)
1219  {  {
1220          struct task_struct *task = current;          struct ccs_execve_entry *ee = ccs_find_execve_entry();
1221          struct domain_info *next_domain = task->domain_info;          struct ccs_domain_info *next_domain = NULL;
1222          struct execve_entry *p;          if (ee)
1223          /***** CRITICAL SECTION START *****/                  next_domain = ee->r.domain;
1224          spin_lock(&execve_list_lock);          if (!next_domain)
1225          list_for_each_entry(p, &execve_list, list) {                  next_domain = ccs_current_domain();
                 if (p->task != task)  
                         continue;  
                 next_domain = p->next_domain;  
                 break;  
         }  
         spin_unlock(&execve_list_lock);  
         /***** CRITICAL SECTION END *****/  
1226          return next_domain;          return next_domain;
1227  }  }
1228    
1229  /**  /**
1230   * ccs_unregister_next_domain - Forget next_domain.   * ccs_start_execve - Prepare for execve() operation.
  */  
 static void ccs_unregister_next_domain(void)  
 {  
         struct task_struct *task = current;  
         struct execve_entry *p;  
         struct execve_entry *ee = NULL;  
         /***** CRITICAL SECTION START *****/  
         spin_lock(&execve_list_lock);  
         list_for_each_entry(p, &execve_list, list) {  
                 if (p->task != task)  
                         continue;  
                 list_del(&p->list);  
                 ee = p;  
                 break;  
         }  
         spin_unlock(&execve_list_lock);  
         /***** CRITICAL SECTION END *****/  
         kfree(ee);  
 }  
   
 /**  
  * search_binary_handler_with_transition - Perform domain transition.  
1231   *   *
1232   * @bprm: Pointer to "struct linux_binprm".   * @bprm: Pointer to "struct linux_binprm".
  * @regs: Pointer to "struct pt_regs".  
1233   *   *
1234   * Returns result of search_binary_handler() on success,   * Returns 0 on success, negative value otherwise.
  * negative value otherwise.  
1235   */   */
1236  int search_binary_handler_with_transition(struct linux_binprm *bprm,  int ccs_start_execve(struct linux_binprm *bprm)
                                           struct pt_regs *regs)  
1237  {  {
1238          int retval;          int retval;
1239          struct task_struct *task = current;          struct task_struct *task = current;
1240          const struct path_info *handler;          struct ccs_execve_entry *ee = ccs_allocate_execve_entry();
1241          struct ccs_request_info r;          if (!ccs_policy_loaded)
         struct obj_info obj;  
         /*  
          * "eh_path" holds path to execute handler program.  
          * Thus, keep valid until search_binary_handler() finishes.  
          */  
         char *eh_path = NULL;  
         struct ccs_page_buffer *tmp = ccs_alloc(sizeof(struct ccs_page_buffer),  
                                                 false);  
         memset(&obj, 0, sizeof(obj));  
         if (!sbin_init_started)  
1242                  ccs_load_policy(bprm->filename);                  ccs_load_policy(bprm->filename);
1243          if (!tmp)          if (!ee)
1244                  return -ENOMEM;                  return -ENOMEM;
1245            ccs_init_request_info(&ee->r, NULL, CCS_MAC_FILE_EXECUTE);
1246          ccs_init_request_info(&r, NULL, CCS_TOMOYO_MAC_FOR_FILE);          ee->r.ee = ee;
1247          r.bprm = bprm;          ee->bprm = bprm;
1248          r.obj = &obj;          ee->r.obj = &ee->obj;
1249          obj.path1_dentry = bprm->file->f_dentry;          ee->obj.path1.dentry = bprm->file->f_dentry;
1250          obj.path1_vfsmnt = bprm->file->f_vfsmnt;          ee->obj.path1.mnt = bprm->file->f_vfsmnt;
         obj.tmp = tmp;  
   
1251          /* Clear manager flag. */          /* Clear manager flag. */
1252          task->tomoyo_flags &= ~CCS_TASK_IS_POLICY_MANAGER;          task->ccs_flags &= ~CCS_TASK_IS_POLICY_MANAGER;
1253          handler = find_execute_handler(TYPE_EXECUTE_HANDLER);          if (ccs_find_execute_handler(ee, CCS_TYPE_EXECUTE_HANDLER)) {
1254          if (handler) {                  retval = ccs_try_alt_exec(ee);
                 retval = try_alt_exec(&r, handler, &eh_path);  
1255                  if (!retval)                  if (!retval)
1256                          audit_execute_handler_log(true, handler->name, bprm);                          ccs_audit_execute_handler_log(ee, true);
1257                  goto ok;                  goto ok;
1258          }          }
1259          retval = find_next_domain(&r, NULL);          retval = ccs_find_next_domain(ee);
1260          if (retval != -EPERM)          if (retval != -EPERM)
1261                  goto ok;                  goto ok;
1262          handler = find_execute_handler(TYPE_DENIED_EXECUTE_HANDLER);          if (ccs_find_execute_handler(ee, CCS_TYPE_DENIED_EXECUTE_HANDLER)) {
1263          if (handler) {                  retval = ccs_try_alt_exec(ee);
                 retval = try_alt_exec(&r, handler, &eh_path);  
1264                  if (!retval)                  if (!retval)
1265                          audit_execute_handler_log(false, handler->name, bprm);                          ccs_audit_execute_handler_log(ee, false);
1266          }          }
1267   ok:   ok:
1268          if (retval < 0)          if (retval < 0)
1269                  goto out;                  goto out;
1270          r.mode = ccs_check_flags(r.domain, CCS_TOMOYO_MAC_FOR_ENV);          ee->r.mode = ccs_get_mode(ee->r.profile, CCS_MAC_ENVIRON);
1271          retval = check_environ(&r);          retval = ccs_environ(ee);
         if (retval < 0)  
                 goto out;  
         retval = ccs_register_next_domain(r.domain);  
1272          if (retval < 0)          if (retval < 0)
1273                  goto out;                  goto out;
1274          task->tomoyo_flags |= TOMOYO_CHECK_READ_FOR_OPEN_EXEC;          task->ccs_flags |= CCS_CHECK_READ_FOR_OPEN_EXEC;
1275          retval = search_binary_handler(bprm, regs);          retval = 0;
         task->tomoyo_flags &= ~TOMOYO_CHECK_READ_FOR_OPEN_EXEC;  
         if (retval < 0)  
                 goto out;  
         /* Proceed to next domain if execution suceeded. */  
         task->domain_info = r.domain;  
         mb(); /* Make domain transition visible to other CPUs. */  
         /* Mark the current process as execute handler. */  
         if (handler)  
                 task->tomoyo_flags |= TOMOYO_TASK_IS_EXECUTE_HANDLER;  
         /* Mark the current process as normal process. */  
         else  
                 task->tomoyo_flags &= ~TOMOYO_TASK_IS_EXECUTE_HANDLER;  
1276   out:   out:
1277          ccs_unregister_next_domain();          if (retval)
1278          ccs_free(eh_path);                  ccs_finish_execve(retval);
         ccs_free(tmp);  
1279          return retval;          return retval;
1280  }  }
1281    
 #else  
   
1282  /**  /**
1283   * search_binary_handler_with_transition - Wrapper for search_binary_handler().   * ccs_finish_execve - Clean up execve() operation.
1284   *   *
1285   * @bprm: Pointer to "struct linux_binprm".   * @retval: Return code of an execve() operation.
  * @regs: Pointer to "struct pt_regs".  
1286   *   *
1287   * Returns the result of search_binary_handler().   * Caller holds ccs_read_lock().
1288   */   */
1289  int search_binary_handler_with_transition(struct linux_binprm *bprm,  void ccs_finish_execve(int retval)
                                           struct pt_regs *regs)  
1290  {  {
1291  #ifdef CONFIG_SAKURA          struct task_struct *task = current;
1292          /* Clear manager flag. */          struct ccs_execve_entry *ee = ccs_find_execve_entry();
1293          current->tomoyo_flags &= ~CCS_TASK_IS_POLICY_MANAGER;          task->ccs_flags &= ~CCS_CHECK_READ_FOR_OPEN_EXEC;
1294          ccs_load_policy(bprm->filename);          if (!ee)
1295  #endif                  return;
1296          return search_binary_handler(bprm, regs);          if (retval < 0)
1297                    goto out;
1298            /* Proceed to next domain if execution suceeded. */
1299            task->ccs_domain_info = ee->r.domain;
1300            /* Mark the current process as execute handler. */
1301            if (ee->handler)
1302                    task->ccs_flags |= CCS_TASK_IS_EXECUTE_HANDLER;
1303            /* Mark the current process as normal process. */
1304            else
1305                    task->ccs_flags &= ~CCS_TASK_IS_EXECUTE_HANDLER;
1306     out:
1307            ccs_free_execve_entry(ee);
1308  }  }
   
 #endif  

Legend:
Removed from v.1903  
changed lines
  Added in v.2951

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26