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

Subversion リポジトリの参照

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

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

revision 2581 by kumaneko, Sun May 24 05:43:34 2009 UTC revision 2690 by kumaneko, Wed Jun 24 04:50:19 2009 UTC
# Line 5  Line 5 
5   *   *
6   * Copyright (C) 2005-2009  NTT DATA CORPORATION   * Copyright (C) 2005-2009  NTT DATA CORPORATION
7   *   *
8   * Version: 1.6.8-pre   2009/05/08   * Version: 1.6.8   2009/05/28
9   *   *
10   * 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.
11   * See README.ccs for ChangeLog.   * See README.ccs for ChangeLog.
# Line 80  static struct ccs_address_group_entry *c Line 80  static struct ccs_address_group_entry *c
80          if (!saved_group_name)          if (!saved_group_name)
81                  return NULL;                  return NULL;
82          entry = kzalloc(sizeof(*entry), GFP_KERNEL);          entry = kzalloc(sizeof(*entry), GFP_KERNEL);
83          /***** WRITER SECTION START *****/          mutex_lock(&ccs_policy_lock);
84          down_write(&ccs_policy_lock);          list_for_each_entry_rcu(group, &ccs_address_group_list, list) {
         list_for_each_entry(group, &ccs_address_group_list, list) {  
85                  if (saved_group_name != group->group_name)                  if (saved_group_name != group->group_name)
86                          continue;                          continue;
87                  atomic_inc(&group->users);                  atomic_inc(&group->users);
# Line 94  static struct ccs_address_group_entry *c Line 93  static struct ccs_address_group_entry *c
93                  entry->group_name = saved_group_name;                  entry->group_name = saved_group_name;
94                  saved_group_name = NULL;                  saved_group_name = NULL;
95                  atomic_set(&entry->users, 1);                  atomic_set(&entry->users, 1);
96                  list_add_tail(&entry->list, &ccs_address_group_list);                  list_add_tail_rcu(&entry->list, &ccs_address_group_list);
97                  group = entry;                  group = entry;
98                  entry = NULL;                  entry = NULL;
99                  error = 0;                  error = 0;
100          }          }
101          up_write(&ccs_policy_lock);          mutex_unlock(&ccs_policy_lock);
         /***** WRITER SECTION END *****/  
102          ccs_put_name(saved_group_name);          ccs_put_name(saved_group_name);
103          kfree(entry);          kfree(entry);
104          return !error ? group : NULL;          return !error ? group : NULL;
# Line 146  static int ccs_update_address_group_entr Line 144  static int ccs_update_address_group_entr
144          }          }
145          if (!is_delete)          if (!is_delete)
146                  entry = kzalloc(sizeof(*entry), GFP_KERNEL);                  entry = kzalloc(sizeof(*entry), GFP_KERNEL);
147          /***** WRITER SECTION START *****/          mutex_lock(&ccs_policy_lock);
148          down_write(&ccs_policy_lock);          list_for_each_entry_rcu(member, &group->address_group_member_list,
149          list_for_each_entry(member, &group->address_group_member_list, list) {                                  list) {
150                  if (member->is_ipv6 != is_ipv6)                  if (member->is_ipv6 != is_ipv6)
151                          continue;                          continue;
152                  if (is_ipv6) {                  if (is_ipv6) {
# Line 175  static int ccs_update_address_group_entr Line 173  static int ccs_update_address_group_entr
173                          entry->min.ipv4 = min_ipv4_address;                          entry->min.ipv4 = min_ipv4_address;
174                          entry->max.ipv4 = max_ipv4_address;                          entry->max.ipv4 = max_ipv4_address;
175                  }                  }
176                  list_add_tail(&entry->list, &group->address_group_member_list);                  list_add_tail_rcu(&entry->list,
177                                      &group->address_group_member_list);
178                  entry = NULL;                  entry = NULL;
179                  error = 0;                  error = 0;
180          }          }
181          up_write(&ccs_policy_lock);          mutex_unlock(&ccs_policy_lock);
         /***** WRITER SECTION END *****/  
182   out:   out:
183          ccs_put_ipv6_address(saved_min_address);          ccs_put_ipv6_address(saved_min_address);
184          ccs_put_ipv6_address(saved_max_address);          ccs_put_ipv6_address(saved_max_address);
# Line 281  static bool ccs_address_matches_group(co Line 279  static bool ccs_address_matches_group(co
279          struct ccs_address_group_member *member;          struct ccs_address_group_member *member;
280          const u32 ip = ntohl(*address);          const u32 ip = ntohl(*address);
281          bool matched = false;          bool matched = false;
282          list_for_each_entry(member, &group->address_group_member_list, list) {          list_for_each_entry_rcu(member, &group->address_group_member_list,
283                                    list) {
284                  if (member->is_deleted)                  if (member->is_deleted)
285                          continue;                          continue;
286                  if (member->is_ipv6) {                  if (member->is_ipv6) {
# Line 308  static bool ccs_address_matches_group(co Line 307  static bool ccs_address_matches_group(co
307   * @head: Pointer to "struct ccs_io_buffer".   * @head: Pointer to "struct ccs_io_buffer".
308   *   *
309   * Returns true on success, false otherwise.   * Returns true on success, false otherwise.
310     *
311     * Caller holds srcu_read_lock(&ccs_ss).
312   */   */
313  bool ccs_read_address_group_policy(struct ccs_io_buffer *head)  bool ccs_read_address_group_policy(struct ccs_io_buffer *head)
314  {  {
315          struct list_head *gpos;          struct list_head *gpos;
316          struct list_head *mpos;          struct list_head *mpos;
317          bool done = true;          bool done = true;
318          /***** READER SECTION START *****/          list_for_each_cookie(gpos, head->read_var1, &ccs_address_group_list) {
         down_read(&ccs_policy_lock);  
         list_for_each_cookie(gpos, head->read_var1.u.list,  
                               &ccs_address_group_list) {  
319                  struct ccs_address_group_entry *group;                  struct ccs_address_group_entry *group;
320                  group = list_entry(gpos, struct ccs_address_group_entry, list);                  group = list_entry(gpos, struct ccs_address_group_entry, list);
321                  list_for_each_cookie(mpos, head->read_var2.u.list,                  list_for_each_cookie(mpos, head->read_var2,
322                                        &group->address_group_member_list) {                                       &group->address_group_member_list) {
323                          char buf[128];                          char buf[128];
324                          struct ccs_address_group_member *member;                          struct ccs_address_group_member *member;
325                          member = list_entry(mpos,                          member = list_entry(mpos,
# Line 366  bool ccs_read_address_group_policy(struc Line 364  bool ccs_read_address_group_policy(struc
364                  if (!done)                  if (!done)
365                          break;                          break;
366          }          }
         up_read(&ccs_policy_lock);  
         /***** READER SECTION END *****/  
367          return done;          return done;
368  }  }
369    
# Line 485  static int ccs_update_network_entry(cons Line 481  static int ccs_update_network_entry(cons
481          if (is_delete)          if (is_delete)
482                  goto delete;                  goto delete;
483          entry = kzalloc(sizeof(*entry), GFP_KERNEL);          entry = kzalloc(sizeof(*entry), GFP_KERNEL);
484          /***** WRITER SECTION START *****/          mutex_lock(&ccs_policy_lock);
485          down_write(&ccs_policy_lock);          list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
         list_for_each_entry(ptr, &domain->acl_info_list, list) {  
486                  struct ccs_ip_network_acl_record *acl;                  struct ccs_ip_network_acl_record *acl;
487                  if (ccs_acl_type1(ptr) != TYPE_IP_NETWORK_ACL)                  if (ccs_acl_type1(ptr) != TYPE_IP_NETWORK_ACL)
488                          continue;                          continue;
# Line 535  static int ccs_update_network_entry(cons Line 530  static int ccs_update_network_entry(cons
530                  error = ccs_add_domain_acl(domain, &entry->head);                  error = ccs_add_domain_acl(domain, &entry->head);
531                  entry = NULL;                  entry = NULL;
532          }          }
533          up_write(&ccs_policy_lock);          mutex_unlock(&ccs_policy_lock);
         /***** WRITER SECTION END *****/  
534          goto out;          goto out;
535   delete:   delete:
536          /***** WRITER SECTION START *****/          mutex_lock(&ccs_policy_lock);
537          down_write(&ccs_policy_lock);          list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
         list_for_each_entry(ptr, &domain->acl_info_list, list) {  
538                  struct ccs_ip_network_acl_record *acl;                  struct ccs_ip_network_acl_record *acl;
539                  if (ccs_acl_type2(ptr) != TYPE_IP_NETWORK_ACL)                  if (ccs_acl_type2(ptr) != TYPE_IP_NETWORK_ACL)
540                          continue;                          continue;
# Line 567  static int ccs_update_network_entry(cons Line 560  static int ccs_update_network_entry(cons
560                  error = ccs_del_domain_acl(ptr);                  error = ccs_del_domain_acl(ptr);
561                  break;                  break;
562          }          }
563          up_write(&ccs_policy_lock);          mutex_unlock(&ccs_policy_lock);
         /***** WRITER SECTION END *****/  
564   out:   out:
565          ccs_put_ipv6_address(saved_min_address);          ccs_put_ipv6_address(saved_min_address);
566          ccs_put_ipv6_address(saved_max_address);          ccs_put_ipv6_address(saved_max_address);
# Line 586  static int ccs_update_network_entry(cons Line 578  static int ccs_update_network_entry(cons
578   * @port:      Port number.   * @port:      Port number.
579   *   *
580   * Returns 0 on success, negative value otherwise.   * Returns 0 on success, negative value otherwise.
581     *
582     * Caller holds srcu_read_lock(&ccs_ss).
583   */   */
584  static int ccs_check_network_entry(const bool is_ipv6, const u8 operation,  static int ccs_check_network_entry(const bool is_ipv6, const u8 operation,
585                                     const u32 *address, const u16 port)                                     const u32 *address, const u16 port)
# Line 608  static int ccs_check_network_entry(const Line 602  static int ccs_check_network_entry(const
602                  goto done;                  goto done;
603          }          }
604   retry:   retry:
605          /***** READER SECTION START *****/          list_for_each_entry_rcu(ptr, &r.domain->acl_info_list, list) {
         down_read(&ccs_policy_lock);  
         list_for_each_entry(ptr, &r.cookie.u.domain->acl_info_list, list) {  
606                  struct ccs_ip_network_acl_record *acl;                  struct ccs_ip_network_acl_record *acl;
607                  if (ccs_acl_type2(ptr) != TYPE_IP_NETWORK_ACL)                  if (ccs_acl_type2(ptr) != TYPE_IP_NETWORK_ACL)
608                          continue;                          continue;
# Line 632  static int ccs_check_network_entry(const Line 624  static int ccs_check_network_entry(const
624                              memcmp(address, acl->u.ipv6.max, 16) > 0)                              memcmp(address, acl->u.ipv6.max, 16) > 0)
625                                  continue;                                  continue;
626                  }                  }
627                  r.condition_cookie.u.cond = ptr->cond;                  r.cond = ptr->cond;
628                  found = true;                  found = true;
629                  break;                  break;
630          }          }
         up_read(&ccs_policy_lock);  
         /***** READER SECTION END *****/  
631          memset(buf, 0, sizeof(buf));          memset(buf, 0, sizeof(buf));
632          if (is_ipv6)          if (is_ipv6)
633                  ccs_print_ipv6(buf, sizeof(buf),                  ccs_print_ipv6(buf, sizeof(buf),
# Line 649  static int ccs_check_network_entry(const Line 639  static int ccs_check_network_entry(const
639                  error = 0;                  error = 0;
640                  goto done;                  goto done;
641          }          }
642          if (ccs_verbose_mode(r.cookie.u.domain))          if (ccs_verbose_mode(r.domain))
643                  printk(KERN_WARNING "TOMOYO-%s: %s to %s %u denied for %s\n",                  printk(KERN_WARNING "TOMOYO-%s: %s to %s %u denied for %s\n",
644                         ccs_get_msg(is_enforce), keyword, buf, port,                         ccs_get_msg(is_enforce), keyword, buf, port,
645                         ccs_get_last_name(r.cookie.u.domain));                         ccs_get_last_name(r.domain));
646          if (is_enforce) {          if (is_enforce) {
647                  int err = ccs_check_supervisor(&r, KEYWORD_ALLOW_NETWORK                  int err = ccs_check_supervisor(&r, KEYWORD_ALLOW_NETWORK
648                                                 "%s %s %u\n", keyword, buf,                                                 "%s %s %u\n", keyword, buf,
# Line 662  static int ccs_check_network_entry(const Line 652  static int ccs_check_network_entry(const
652                  error = err;                  error = err;
653                  goto done;                  goto done;
654          }          }
655          if (r.mode == 1 && ccs_domain_quota_ok(r.cookie.u.domain)) {          if (r.mode == 1 && ccs_domain_quota_ok(r.domain)) {
656                  struct ccs_condition *cond = ccs_handler_cond();                  struct ccs_condition *cond = ccs_handler_cond();
657                  ccs_update_network_entry(operation, is_ipv6 ?                  ccs_update_network_entry(operation, is_ipv6 ?
658                                           IP_RECORD_TYPE_IPv6 :                                           IP_RECORD_TYPE_IPv6 :
659                                           IP_RECORD_TYPE_IPv4,                                           IP_RECORD_TYPE_IPv4,
660                                           NULL, address, address, port, port,                                           NULL, address, address, port, port,
661                                           r.cookie.u.domain, cond, false);                                           r.domain, cond, false);
662                  ccs_put_condition(cond);                  ccs_put_condition(cond);
663          }          }
664          error = 0;          error = 0;

Legend:
Removed from v.2581  
changed lines
  Added in v.2690

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