direct-io.hg
changeset 13669:21d6135f522f
Merge
author | Tim Deegan <Tim.Deegan@xensource.com> |
---|---|
date | Mon Jan 29 16:50:22 2007 +0000 (2007-01-29) |
parents | 99d36a153024 44eb80f50725 |
children | e7ceed4ebcd9 |
files | xen/arch/x86/hvm/intercept.c |
line diff
1.1 --- a/xen/acm/acm_chinesewall_hooks.c Mon Jan 29 16:49:29 2007 +0000 1.2 +++ b/xen/acm/acm_chinesewall_hooks.c Mon Jan 29 16:50:22 2007 +0000 1.3 @@ -132,26 +132,26 @@ static int chwall_dump_policy(u8 * buf, 1.4 if (buf_size < sizeof(struct acm_chwall_policy_buffer)) 1.5 return -EINVAL; 1.6 1.7 - chwall_buf->chwall_max_types = htonl(chwall_bin_pol.max_types); 1.8 - chwall_buf->chwall_max_ssidrefs = htonl(chwall_bin_pol.max_ssidrefs); 1.9 - chwall_buf->policy_code = htonl(ACM_CHINESE_WALL_POLICY); 1.10 + chwall_buf->chwall_max_types = cpu_to_be32(chwall_bin_pol.max_types); 1.11 + chwall_buf->chwall_max_ssidrefs = cpu_to_be32(chwall_bin_pol.max_ssidrefs); 1.12 + chwall_buf->policy_code = cpu_to_be32(ACM_CHINESE_WALL_POLICY); 1.13 chwall_buf->chwall_ssid_offset = 1.14 - htonl(sizeof(struct acm_chwall_policy_buffer)); 1.15 + cpu_to_be32(sizeof(struct acm_chwall_policy_buffer)); 1.16 chwall_buf->chwall_max_conflictsets = 1.17 - htonl(chwall_bin_pol.max_conflictsets); 1.18 + cpu_to_be32(chwall_bin_pol.max_conflictsets); 1.19 chwall_buf->chwall_conflict_sets_offset = 1.20 - htonl(ntohl(chwall_buf->chwall_ssid_offset) + 1.21 + cpu_to_be32(be32_to_cpu(chwall_buf->chwall_ssid_offset) + 1.22 sizeof(domaintype_t) * chwall_bin_pol.max_ssidrefs * 1.23 chwall_bin_pol.max_types); 1.24 chwall_buf->chwall_running_types_offset = 1.25 - htonl(ntohl(chwall_buf->chwall_conflict_sets_offset) + 1.26 + cpu_to_be32(be32_to_cpu(chwall_buf->chwall_conflict_sets_offset) + 1.27 sizeof(domaintype_t) * chwall_bin_pol.max_conflictsets * 1.28 chwall_bin_pol.max_types); 1.29 chwall_buf->chwall_conflict_aggregate_offset = 1.30 - htonl(ntohl(chwall_buf->chwall_running_types_offset) + 1.31 + cpu_to_be32(be32_to_cpu(chwall_buf->chwall_running_types_offset) + 1.32 sizeof(domaintype_t) * chwall_bin_pol.max_types); 1.33 1.34 - ret = ntohl(chwall_buf->chwall_conflict_aggregate_offset) + 1.35 + ret = be32_to_cpu(chwall_buf->chwall_conflict_aggregate_offset) + 1.36 sizeof(domaintype_t) * chwall_bin_pol.max_types; 1.37 1.38 ret = (ret + 7) & ~7; 1.39 @@ -160,21 +160,21 @@ static int chwall_dump_policy(u8 * buf, 1.40 return -EINVAL; 1.41 1.42 /* now copy buffers over */ 1.43 - arrcpy16((u16 *) (buf + ntohl(chwall_buf->chwall_ssid_offset)), 1.44 + arrcpy16((u16 *) (buf + be32_to_cpu(chwall_buf->chwall_ssid_offset)), 1.45 chwall_bin_pol.ssidrefs, 1.46 chwall_bin_pol.max_ssidrefs * chwall_bin_pol.max_types); 1.47 1.48 arrcpy16((u16 *) (buf + 1.49 - ntohl(chwall_buf->chwall_conflict_sets_offset)), 1.50 + be32_to_cpu(chwall_buf->chwall_conflict_sets_offset)), 1.51 chwall_bin_pol.conflict_sets, 1.52 chwall_bin_pol.max_conflictsets * chwall_bin_pol.max_types); 1.53 1.54 arrcpy16((u16 *) (buf + 1.55 - ntohl(chwall_buf->chwall_running_types_offset)), 1.56 + be32_to_cpu(chwall_buf->chwall_running_types_offset)), 1.57 chwall_bin_pol.running_types, chwall_bin_pol.max_types); 1.58 1.59 arrcpy16((u16 *) (buf + 1.60 - ntohl(chwall_buf->chwall_conflict_aggregate_offset)), 1.61 + be32_to_cpu(chwall_buf->chwall_conflict_aggregate_offset)), 1.62 chwall_bin_pol.conflict_aggregate_set, 1.63 chwall_bin_pol.max_types); 1.64 return ret; 1.65 @@ -267,20 +267,20 @@ static int chwall_set_policy(u8 * buf, u 1.66 return -EINVAL; 1.67 1.68 /* rewrite the policy due to endianess */ 1.69 - chwall_buf->policy_code = ntohl(chwall_buf->policy_code); 1.70 - chwall_buf->policy_version = ntohl(chwall_buf->policy_version); 1.71 - chwall_buf->chwall_max_types = ntohl(chwall_buf->chwall_max_types); 1.72 + chwall_buf->policy_code = be32_to_cpu(chwall_buf->policy_code); 1.73 + chwall_buf->policy_version = be32_to_cpu(chwall_buf->policy_version); 1.74 + chwall_buf->chwall_max_types = be32_to_cpu(chwall_buf->chwall_max_types); 1.75 chwall_buf->chwall_max_ssidrefs = 1.76 - ntohl(chwall_buf->chwall_max_ssidrefs); 1.77 + be32_to_cpu(chwall_buf->chwall_max_ssidrefs); 1.78 chwall_buf->chwall_max_conflictsets = 1.79 - ntohl(chwall_buf->chwall_max_conflictsets); 1.80 - chwall_buf->chwall_ssid_offset = ntohl(chwall_buf->chwall_ssid_offset); 1.81 + be32_to_cpu(chwall_buf->chwall_max_conflictsets); 1.82 + chwall_buf->chwall_ssid_offset = be32_to_cpu(chwall_buf->chwall_ssid_offset); 1.83 chwall_buf->chwall_conflict_sets_offset = 1.84 - ntohl(chwall_buf->chwall_conflict_sets_offset); 1.85 + be32_to_cpu(chwall_buf->chwall_conflict_sets_offset); 1.86 chwall_buf->chwall_running_types_offset = 1.87 - ntohl(chwall_buf->chwall_running_types_offset); 1.88 + be32_to_cpu(chwall_buf->chwall_running_types_offset); 1.89 chwall_buf->chwall_conflict_aggregate_offset = 1.90 - ntohl(chwall_buf->chwall_conflict_aggregate_offset); 1.91 + be32_to_cpu(chwall_buf->chwall_conflict_aggregate_offset); 1.92 1.93 /* policy type and version checks */ 1.94 if ((chwall_buf->policy_code != ACM_CHINESE_WALL_POLICY) ||
2.1 --- a/xen/acm/acm_core.c Mon Jan 29 16:49:29 2007 +0000 2.2 +++ b/xen/acm/acm_core.c Mon Jan 29 16:50:22 2007 +0000 2.3 @@ -62,35 +62,20 @@ struct acm_binary_policy acm_bin_pol; 2.4 /* acm binary policy lock */ 2.5 DEFINE_RWLOCK(acm_bin_pol_rwlock); 2.6 2.7 -/* until we have endian support in Xen, we discover it at runtime */ 2.8 -u8 little_endian = 1; 2.9 -void 2.10 -acm_set_endian(void) 2.11 -{ 2.12 - u32 test = 1; 2.13 - if (*((u8 *)&test) == 1) 2.14 - { 2.15 - printkd("ACM module running in LITTLE ENDIAN.\n"); 2.16 - little_endian = 1; 2.17 - } 2.18 - else 2.19 - { 2.20 - printkd("ACM module running in BIG ENDIAN.\n"); 2.21 - little_endian = 0; 2.22 - } 2.23 -} 2.24 - 2.25 int 2.26 -acm_set_policy_reference(u8 * buf, u32 buf_size) 2.27 +acm_set_policy_reference(u8 *buf, u32 buf_size) 2.28 { 2.29 struct acm_policy_reference_buffer *pr = (struct acm_policy_reference_buffer *)buf; 2.30 - acm_bin_pol.policy_reference_name = (char *)xmalloc_array(u8, ntohl(pr->len)); 2.31 + acm_bin_pol.policy_reference_name = (char *)xmalloc_array(u8, be32_to_cpu(pr->len)); 2.32 2.33 if (!acm_bin_pol.policy_reference_name) 2.34 return -ENOMEM; 2.35 2.36 - strcpy(acm_bin_pol.policy_reference_name, (char *)(buf + sizeof(struct acm_policy_reference_buffer))); 2.37 - printk("%s: Activating policy %s\n", __func__, acm_bin_pol.policy_reference_name); 2.38 + strlcpy(acm_bin_pol.policy_reference_name, 2.39 + (char *)(buf + sizeof(struct acm_policy_reference_buffer)), 2.40 + be32_to_cpu(pr->len)); 2.41 + printk("%s: Activating policy %s\n", __func__, 2.42 + acm_bin_pol.policy_reference_name); 2.43 return 0; 2.44 } 2.45 2.46 @@ -105,9 +90,10 @@ acm_dump_policy_reference(u8 *buf, u32 b 2.47 return -EINVAL; 2.48 2.49 memset(buf, 0, ret); 2.50 - pr_buf->len = htonl(strlen(acm_bin_pol.policy_reference_name) + 1); /* including stringend '\0' */ 2.51 - strcpy((char *)(buf + sizeof(struct acm_policy_reference_buffer)), 2.52 - acm_bin_pol.policy_reference_name); 2.53 + pr_buf->len = cpu_to_be32(strlen(acm_bin_pol.policy_reference_name) + 1); /* including stringend '\0' */ 2.54 + strlcpy((char *)(buf + sizeof(struct acm_policy_reference_buffer)), 2.55 + acm_bin_pol.policy_reference_name, 2.56 + be32_to_cpu(pr_buf->len)); 2.57 return ret; 2.58 } 2.59 2.60 @@ -198,7 +184,7 @@ acm_is_policy(char *buf, unsigned long l 2.61 return 0; 2.62 2.63 pol = (struct acm_policy_buffer *)buf; 2.64 - return ntohl(pol->magic) == ACM_MAGIC; 2.65 + return be32_to_cpu(pol->magic) == ACM_MAGIC; 2.66 } 2.67 2.68 2.69 @@ -213,7 +199,7 @@ acm_setup(char *policy_start, 2.70 return rc; 2.71 2.72 pol = (struct acm_policy_buffer *)policy_start; 2.73 - if (ntohl(pol->magic) != ACM_MAGIC) 2.74 + if (be32_to_cpu(pol->magic) != ACM_MAGIC) 2.75 return rc; 2.76 2.77 rc = do_acm_set_policy((void *)policy_start, (u32)policy_len); 2.78 @@ -237,8 +223,6 @@ acm_init(char *policy_start, 2.79 { 2.80 int ret = ACM_OK; 2.81 2.82 - acm_set_endian(); 2.83 - 2.84 /* first try to load the boot policy (uses its own locks) */ 2.85 acm_setup(policy_start, policy_len); 2.86
3.1 --- a/xen/acm/acm_policy.c Mon Jan 29 16:49:29 2007 +0000 3.2 +++ b/xen/acm/acm_policy.c Mon Jan 29 16:50:22 2007 +0000 3.3 @@ -63,9 +63,9 @@ do_acm_set_policy(void *buf, u32 buf_siz 3.4 { 3.5 struct acm_policy_buffer *pol = (struct acm_policy_buffer *)buf; 3.6 /* some sanity checking */ 3.7 - if ((ntohl(pol->magic) != ACM_MAGIC) || 3.8 - (buf_size != ntohl(pol->len)) || 3.9 - (ntohl(pol->policy_version) != ACM_POLICY_VERSION)) 3.10 + if ((be32_to_cpu(pol->magic) != ACM_MAGIC) || 3.11 + (buf_size != be32_to_cpu(pol->len)) || 3.12 + (be32_to_cpu(pol->policy_version) != ACM_POLICY_VERSION)) 3.13 { 3.14 printk("%s: ERROR in Magic, Version, or buf size.\n", __func__); 3.15 goto error_free; 3.16 @@ -73,8 +73,8 @@ do_acm_set_policy(void *buf, u32 buf_siz 3.17 3.18 if (acm_active_security_policy == ACM_POLICY_UNDEFINED) { 3.19 /* setup the policy with the boot policy */ 3.20 - if (acm_init_binary_policy((ntohl(pol->secondary_policy_code) << 4) | 3.21 - ntohl(pol->primary_policy_code))) { 3.22 + if (acm_init_binary_policy((be32_to_cpu(pol->secondary_policy_code) << 4) | 3.23 + be32_to_cpu(pol->primary_policy_code))) { 3.24 goto error_free; 3.25 } 3.26 acm_active_security_policy = 3.27 @@ -82,8 +82,8 @@ do_acm_set_policy(void *buf, u32 buf_siz 3.28 } 3.29 3.30 /* once acm_active_security_policy is set, it cannot be changed */ 3.31 - if ((ntohl(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) || 3.32 - (ntohl(pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code)) 3.33 + if ((be32_to_cpu(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) || 3.34 + (be32_to_cpu(pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code)) 3.35 { 3.36 printkd("%s: Wrong policy type in boot policy!\n", __func__); 3.37 goto error_free; 3.38 @@ -93,21 +93,21 @@ do_acm_set_policy(void *buf, u32 buf_siz 3.39 write_lock(&acm_bin_pol_rwlock); 3.40 3.41 /* set label reference name */ 3.42 - if (acm_set_policy_reference(buf + ntohl(pol->policy_reference_offset), 3.43 - ntohl(pol->primary_buffer_offset) - 3.44 - ntohl(pol->policy_reference_offset))) 3.45 + if (acm_set_policy_reference(buf + be32_to_cpu(pol->policy_reference_offset), 3.46 + be32_to_cpu(pol->primary_buffer_offset) - 3.47 + be32_to_cpu(pol->policy_reference_offset))) 3.48 goto error_lock_free; 3.49 3.50 /* set primary policy data */ 3.51 - if (acm_primary_ops->set_binary_policy(buf + ntohl(pol->primary_buffer_offset), 3.52 - ntohl(pol->secondary_buffer_offset) - 3.53 - ntohl(pol->primary_buffer_offset))) 3.54 + if (acm_primary_ops->set_binary_policy(buf + be32_to_cpu(pol->primary_buffer_offset), 3.55 + be32_to_cpu(pol->secondary_buffer_offset) - 3.56 + be32_to_cpu(pol->primary_buffer_offset))) 3.57 goto error_lock_free; 3.58 3.59 /* set secondary policy data */ 3.60 - if (acm_secondary_ops->set_binary_policy(buf + ntohl(pol->secondary_buffer_offset), 3.61 - ntohl(pol->len) - 3.62 - ntohl(pol->secondary_buffer_offset))) 3.63 + if (acm_secondary_ops->set_binary_policy(buf + be32_to_cpu(pol->secondary_buffer_offset), 3.64 + be32_to_cpu(pol->len) - 3.65 + be32_to_cpu(pol->secondary_buffer_offset))) 3.66 goto error_lock_free; 3.67 3.68 write_unlock(&acm_bin_pol_rwlock); 3.69 @@ -136,38 +136,38 @@ acm_get_policy(XEN_GUEST_HANDLE(void) bu 3.70 read_lock(&acm_bin_pol_rwlock); 3.71 3.72 bin_pol = (struct acm_policy_buffer *)policy_buffer; 3.73 - bin_pol->magic = htonl(ACM_MAGIC); 3.74 - bin_pol->primary_policy_code = htonl(acm_bin_pol.primary_policy_code); 3.75 - bin_pol->secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code); 3.76 + bin_pol->magic = cpu_to_be32(ACM_MAGIC); 3.77 + bin_pol->primary_policy_code = cpu_to_be32(acm_bin_pol.primary_policy_code); 3.78 + bin_pol->secondary_policy_code = cpu_to_be32(acm_bin_pol.secondary_policy_code); 3.79 3.80 - bin_pol->len = htonl(sizeof(struct acm_policy_buffer)); 3.81 - bin_pol->policy_reference_offset = htonl(ntohl(bin_pol->len)); 3.82 - bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len)); 3.83 - bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len)); 3.84 + bin_pol->len = cpu_to_be32(sizeof(struct acm_policy_buffer)); 3.85 + bin_pol->policy_reference_offset = cpu_to_be32(be32_to_cpu(bin_pol->len)); 3.86 + bin_pol->primary_buffer_offset = cpu_to_be32(be32_to_cpu(bin_pol->len)); 3.87 + bin_pol->secondary_buffer_offset = cpu_to_be32(be32_to_cpu(bin_pol->len)); 3.88 3.89 - ret = acm_dump_policy_reference(policy_buffer + ntohl(bin_pol->policy_reference_offset), 3.90 - buf_size - ntohl(bin_pol->policy_reference_offset)); 3.91 + ret = acm_dump_policy_reference(policy_buffer + be32_to_cpu(bin_pol->policy_reference_offset), 3.92 + buf_size - be32_to_cpu(bin_pol->policy_reference_offset)); 3.93 if (ret < 0) 3.94 goto error_free_unlock; 3.95 3.96 - bin_pol->len = htonl(ntohl(bin_pol->len) + ret); 3.97 - bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len)); 3.98 + bin_pol->len = cpu_to_be32(be32_to_cpu(bin_pol->len) + ret); 3.99 + bin_pol->primary_buffer_offset = cpu_to_be32(be32_to_cpu(bin_pol->len)); 3.100 3.101 - ret = acm_primary_ops->dump_binary_policy (policy_buffer + ntohl(bin_pol->primary_buffer_offset), 3.102 - buf_size - ntohl(bin_pol->primary_buffer_offset)); 3.103 + ret = acm_primary_ops->dump_binary_policy (policy_buffer + be32_to_cpu(bin_pol->primary_buffer_offset), 3.104 + buf_size - be32_to_cpu(bin_pol->primary_buffer_offset)); 3.105 if (ret < 0) 3.106 goto error_free_unlock; 3.107 3.108 - bin_pol->len = htonl(ntohl(bin_pol->len) + ret); 3.109 - bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len)); 3.110 + bin_pol->len = cpu_to_be32(be32_to_cpu(bin_pol->len) + ret); 3.111 + bin_pol->secondary_buffer_offset = cpu_to_be32(be32_to_cpu(bin_pol->len)); 3.112 3.113 - ret = acm_secondary_ops->dump_binary_policy(policy_buffer + ntohl(bin_pol->secondary_buffer_offset), 3.114 - buf_size - ntohl(bin_pol->secondary_buffer_offset)); 3.115 + ret = acm_secondary_ops->dump_binary_policy(policy_buffer + be32_to_cpu(bin_pol->secondary_buffer_offset), 3.116 + buf_size - be32_to_cpu(bin_pol->secondary_buffer_offset)); 3.117 if (ret < 0) 3.118 goto error_free_unlock; 3.119 3.120 - bin_pol->len = htonl(ntohl(bin_pol->len) + ret); 3.121 - if (copy_to_guest(buf, policy_buffer, ntohl(bin_pol->len))) 3.122 + bin_pol->len = cpu_to_be32(be32_to_cpu(bin_pol->len) + ret); 3.123 + if (copy_to_guest(buf, policy_buffer, be32_to_cpu(bin_pol->len))) 3.124 goto error_free_unlock; 3.125 3.126 read_unlock(&acm_bin_pol_rwlock); 3.127 @@ -204,12 +204,12 @@ acm_dump_statistics(XEN_GUEST_HANDLE(voi 3.128 if (len2 < 0) 3.129 goto error_lock_free; 3.130 3.131 - acm_stats.magic = htonl(ACM_MAGIC); 3.132 - acm_stats.primary_policy_code = htonl(acm_bin_pol.primary_policy_code); 3.133 - acm_stats.secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code); 3.134 - acm_stats.primary_stats_offset = htonl(sizeof(struct acm_stats_buffer)); 3.135 - acm_stats.secondary_stats_offset = htonl(sizeof(struct acm_stats_buffer) + len1); 3.136 - acm_stats.len = htonl(sizeof(struct acm_stats_buffer) + len1 + len2); 3.137 + acm_stats.magic = cpu_to_be32(ACM_MAGIC); 3.138 + acm_stats.primary_policy_code = cpu_to_be32(acm_bin_pol.primary_policy_code); 3.139 + acm_stats.secondary_policy_code = cpu_to_be32(acm_bin_pol.secondary_policy_code); 3.140 + acm_stats.primary_stats_offset = cpu_to_be32(sizeof(struct acm_stats_buffer)); 3.141 + acm_stats.secondary_stats_offset = cpu_to_be32(sizeof(struct acm_stats_buffer) + len1); 3.142 + acm_stats.len = cpu_to_be32(sizeof(struct acm_stats_buffer) + len1 + len2); 3.143 3.144 memcpy(stats_buffer, &acm_stats, sizeof(struct acm_stats_buffer)); 3.145
4.1 --- a/xen/acm/acm_simple_type_enforcement_hooks.c Mon Jan 29 16:49:29 2007 +0000 4.2 +++ b/xen/acm/acm_simple_type_enforcement_hooks.c Mon Jan 29 16:50:22 2007 +0000 4.3 @@ -143,11 +143,11 @@ ste_dump_policy(u8 *buf, u32 buf_size) { 4.4 if (buf_size < sizeof(struct acm_ste_policy_buffer)) 4.5 return -EINVAL; 4.6 4.7 - ste_buf->ste_max_types = htonl(ste_bin_pol.max_types); 4.8 - ste_buf->ste_max_ssidrefs = htonl(ste_bin_pol.max_ssidrefs); 4.9 - ste_buf->policy_code = htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY); 4.10 - ste_buf->ste_ssid_offset = htonl(sizeof(struct acm_ste_policy_buffer)); 4.11 - ret = ntohl(ste_buf->ste_ssid_offset) + 4.12 + ste_buf->ste_max_types = cpu_to_be32(ste_bin_pol.max_types); 4.13 + ste_buf->ste_max_ssidrefs = cpu_to_be32(ste_bin_pol.max_ssidrefs); 4.14 + ste_buf->policy_code = cpu_to_be32(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY); 4.15 + ste_buf->ste_ssid_offset = cpu_to_be32(sizeof(struct acm_ste_policy_buffer)); 4.16 + ret = be32_to_cpu(ste_buf->ste_ssid_offset) + 4.17 sizeof(domaintype_t)*ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types; 4.18 4.19 ret = (ret + 7) & ~7; 4.20 @@ -156,7 +156,7 @@ ste_dump_policy(u8 *buf, u32 buf_size) { 4.21 return -EINVAL; 4.22 4.23 /* now copy buffer over */ 4.24 - arrcpy(buf + ntohl(ste_buf->ste_ssid_offset), 4.25 + arrcpy(buf + be32_to_cpu(ste_buf->ste_ssid_offset), 4.26 ste_bin_pol.ssidrefs, 4.27 sizeof(domaintype_t), 4.28 ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types); 4.29 @@ -287,11 +287,11 @@ ste_set_policy(u8 *buf, u32 buf_size) 4.30 return -EINVAL; 4.31 4.32 /* Convert endianess of policy */ 4.33 - ste_buf->policy_code = ntohl(ste_buf->policy_code); 4.34 - ste_buf->policy_version = ntohl(ste_buf->policy_version); 4.35 - ste_buf->ste_max_types = ntohl(ste_buf->ste_max_types); 4.36 - ste_buf->ste_max_ssidrefs = ntohl(ste_buf->ste_max_ssidrefs); 4.37 - ste_buf->ste_ssid_offset = ntohl(ste_buf->ste_ssid_offset); 4.38 + ste_buf->policy_code = be32_to_cpu(ste_buf->policy_code); 4.39 + ste_buf->policy_version = be32_to_cpu(ste_buf->policy_version); 4.40 + ste_buf->ste_max_types = be32_to_cpu(ste_buf->ste_max_types); 4.41 + ste_buf->ste_max_ssidrefs = be32_to_cpu(ste_buf->ste_max_ssidrefs); 4.42 + ste_buf->ste_ssid_offset = be32_to_cpu(ste_buf->ste_ssid_offset); 4.43 4.44 /* policy type and version checks */ 4.45 if ((ste_buf->policy_code != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) || 4.46 @@ -348,12 +348,12 @@ ste_dump_stats(u8 *buf, u16 buf_len) 4.47 struct acm_ste_stats_buffer stats; 4.48 4.49 /* now send the hook counts to user space */ 4.50 - stats.ec_eval_count = htonl(atomic_read(&ste_bin_pol.ec_eval_count)); 4.51 - stats.gt_eval_count = htonl(atomic_read(&ste_bin_pol.gt_eval_count)); 4.52 - stats.ec_denied_count = htonl(atomic_read(&ste_bin_pol.ec_denied_count)); 4.53 - stats.gt_denied_count = htonl(atomic_read(&ste_bin_pol.gt_denied_count)); 4.54 - stats.ec_cachehit_count = htonl(atomic_read(&ste_bin_pol.ec_cachehit_count)); 4.55 - stats.gt_cachehit_count = htonl(atomic_read(&ste_bin_pol.gt_cachehit_count)); 4.56 + stats.ec_eval_count = cpu_to_be32(atomic_read(&ste_bin_pol.ec_eval_count)); 4.57 + stats.gt_eval_count = cpu_to_be32(atomic_read(&ste_bin_pol.gt_eval_count)); 4.58 + stats.ec_denied_count = cpu_to_be32(atomic_read(&ste_bin_pol.ec_denied_count)); 4.59 + stats.gt_denied_count = cpu_to_be32(atomic_read(&ste_bin_pol.gt_denied_count)); 4.60 + stats.ec_cachehit_count = cpu_to_be32(atomic_read(&ste_bin_pol.ec_cachehit_count)); 4.61 + stats.gt_cachehit_count = cpu_to_be32(atomic_read(&ste_bin_pol.gt_cachehit_count)); 4.62 4.63 if (buf_len < sizeof(struct acm_ste_stats_buffer)) 4.64 return -ENOMEM;
5.1 --- a/xen/arch/ia64/linux-xen/setup.c Mon Jan 29 16:49:29 2007 +0000 5.2 +++ b/xen/arch/ia64/linux-xen/setup.c Mon Jan 29 16:50:22 2007 +0000 5.3 @@ -424,8 +424,7 @@ setup_arch (char **cmdline_p) 5.4 else 5.5 len = strlen (mvec_name); 5.6 len = min(len, sizeof (str) - 1); 5.7 - strncpy (str, mvec_name, len); 5.8 - str[len] = '\0'; 5.9 + strlcpy (str, mvec_name, len); 5.10 mvec_name = str; 5.11 } else 5.12 mvec_name = acpi_get_sysname(); 5.13 @@ -564,7 +563,7 @@ show_cpuinfo (struct seq_file *m, void * 5.14 *cp++ = sep; 5.15 sep = ','; 5.16 *cp++ = ' '; 5.17 - strcpy(cp, feature_bits[i].feature_name); 5.18 + strlcpy(cp, feature_bits[i].feature_name, sizeof(features)); 5.19 cp += strlen(feature_bits[i].feature_name); 5.20 mask &= ~feature_bits[i].mask; 5.21 }
6.1 --- a/xen/arch/ia64/xen/dom_fw.c Mon Jan 29 16:49:29 2007 +0000 6.2 +++ b/xen/arch/ia64/xen/dom_fw.c Mon Jan 29 16:50:22 2007 +0000 6.3 @@ -333,13 +333,13 @@ dom_fw_fake_acpi(struct domain *d, struc 6.4 memset(tables, 0, sizeof(struct fake_acpi_tables)); 6.5 6.6 /* setup XSDT (64bit version of RSDT) */ 6.7 - strncpy(xsdt->signature, XSDT_SIG, 4); 6.8 + strlcpy(xsdt->signature, XSDT_SIG, sizeof(xsdt->signature)); 6.9 /* XSDT points to both the FADT and the MADT, so add one entry */ 6.10 xsdt->length = sizeof(struct xsdt_descriptor_rev2) + sizeof(u64); 6.11 xsdt->revision = 1; 6.12 - strcpy(xsdt->oem_id, "XEN"); 6.13 - strcpy(xsdt->oem_table_id, "Xen/ia64"); 6.14 - strcpy(xsdt->asl_compiler_id, "XEN"); 6.15 + strlcpy(xsdt->oem_id, "XEN", sizeof(xsdt->oem_id)); 6.16 + strlcpy(xsdt->oem_table_id, "Xen/ia64", sizeof(xsdt->oem_table_id)); 6.17 + strlcpy(xsdt->asl_compiler_id, "XEN", sizeof(xsdt->asl_compiler_id)); 6.18 xsdt->asl_compiler_revision = (xen_major_version() << 16) | 6.19 xen_minor_version(); 6.20 6.21 @@ -349,16 +349,16 @@ dom_fw_fake_acpi(struct domain *d, struc 6.22 xsdt->checksum = generate_acpi_checksum(xsdt, xsdt->length); 6.23 6.24 /* setup FADT */ 6.25 - strncpy(fadt->signature, FADT_SIG, 4); 6.26 + strlcpy(fadt->signature, FADT_SIG, sizeof(fadt->signature)); 6.27 fadt->length = sizeof(struct fadt_descriptor_rev2); 6.28 fadt->revision = FADT2_REVISION_ID; 6.29 - strcpy(fadt->oem_id, "XEN"); 6.30 - strcpy(fadt->oem_table_id, "Xen/ia64"); 6.31 - strcpy(fadt->asl_compiler_id, "XEN"); 6.32 + strlcpy(fadt->oem_id, "XEN", sizeof(fadt->oem_id)); 6.33 + strlcpy(fadt->oem_table_id, "Xen/ia64", sizeof(fadt->oem_table_id)); 6.34 + strlcpy(fadt->asl_compiler_id, "XEN", sizeof(fadt->asl_compiler_id)); 6.35 fadt->asl_compiler_revision = (xen_major_version() << 16) | 6.36 xen_minor_version(); 6.37 6.38 - strncpy(facs->signature, FACS_SIG, 4); 6.39 + strlcpy(facs->signature, FACS_SIG, sizeof(facs->signature)); 6.40 facs->version = 1; 6.41 facs->length = sizeof(struct facs_descriptor_rev2); 6.42 6.43 @@ -386,8 +386,8 @@ dom_fw_fake_acpi(struct domain *d, struc 6.44 fadt->checksum = generate_acpi_checksum(fadt, fadt->length); 6.45 6.46 /* setup RSDP */ 6.47 - strncpy(rsdp->signature, RSDP_SIG, 8); 6.48 - strcpy(rsdp->oem_id, "XEN"); 6.49 + strlcpy(rsdp->signature, RSDP_SIG, sizeof(rsdp->signature)); 6.50 + strlcpy(rsdp->oem_id, "XEN", sizeof(rsdp->oem_id)); 6.51 rsdp->revision = 2; /* ACPI 2.0 includes XSDT */ 6.52 rsdp->length = sizeof(struct acpi20_table_rsdp); 6.53 rsdp->xsdt_address = ACPI_TABLE_MPA(xsdt); 6.54 @@ -397,11 +397,11 @@ dom_fw_fake_acpi(struct domain *d, struc 6.55 rsdp->ext_checksum = generate_acpi_checksum(rsdp, rsdp->length); 6.56 6.57 /* setup DSDT with trivial namespace. */ 6.58 - strncpy(dsdt->signature, DSDT_SIG, 4); 6.59 + strlcpy(dsdt->signature, DSDT_SIG, sizeof(dsdt->signature)); 6.60 dsdt->revision = 1; 6.61 - strcpy(dsdt->oem_id, "XEN"); 6.62 - strcpy(dsdt->oem_table_id, "Xen/ia64"); 6.63 - strcpy(dsdt->asl_compiler_id, "XEN"); 6.64 + strlcpy(dsdt->oem_id, "XEN", sizeof(dsdt->oem_id)); 6.65 + strlcpy(dsdt->oem_table_id, "Xen/ia64", sizeof(dsdt->oem_table_id)); 6.66 + strlcpy(dsdt->asl_compiler_id, "XEN", sizeof(dsdt->asl_compiler_id)); 6.67 dsdt->asl_compiler_revision = (xen_major_version() << 16) | 6.68 xen_minor_version(); 6.69 6.70 @@ -409,7 +409,7 @@ dom_fw_fake_acpi(struct domain *d, struc 6.71 tables->aml[0] = 0x10; /* Scope */ 6.72 tables->aml[1] = 0x40; /* length/offset to next object (patched) */ 6.73 tables->aml[2] = 0x00; 6.74 - strncpy((char *)&tables->aml[3], "_SB_", 4); 6.75 + strlcpy((char *)&tables->aml[3], "_SB_", 5); 6.76 6.77 /* The processor object isn't absolutely necessary, revist for SMP */ 6.78 aml_len = 7; 6.79 @@ -437,11 +437,14 @@ dom_fw_fake_acpi(struct domain *d, struc 6.80 dsdt->checksum = generate_acpi_checksum(dsdt, dsdt->length); 6.81 6.82 /* setup MADT */ 6.83 - strncpy(madt->header.signature, APIC_SIG, 4); 6.84 + strlcpy(madt->header.signature, APIC_SIG, sizeof(madt->header.signature)); 6.85 madt->header.revision = 2; 6.86 - strcpy(madt->header.oem_id, "XEN"); 6.87 - strcpy(madt->header.oem_table_id, "Xen/ia64"); 6.88 - strcpy(madt->header.asl_compiler_id, "XEN"); 6.89 + strlcpy(madt->header.oem_id, "XEN", 6.90 + sizeof(madt->header.oem_id)); 6.91 + strlcpy(madt->header.oem_table_id, "Xen/ia64", 6.92 + sizeof(madt->header.oem_table_id)); 6.93 + strlcpy(madt->header.asl_compiler_id, "XEN", 6.94 + sizeof(madt->header.asl_compiler_id)); 6.95 madt->header.asl_compiler_revision = (xen_major_version() << 16) | 6.96 xen_minor_version(); 6.97 6.98 @@ -760,8 +763,10 @@ dom_fw_init(struct domain *d, 6.99 tables->sal_systab.sal_rev_major = 0; 6.100 tables->sal_systab.entry_count = 2; 6.101 6.102 - strcpy((char *)tables->sal_systab.oem_id, "Xen/ia64"); 6.103 - strcpy((char *)tables->sal_systab.product_id, "Xen/ia64"); 6.104 + strlcpy((char *)tables->sal_systab.oem_id, "Xen/ia64", 6.105 + sizeof(tables->sal_systab.oem_id)); 6.106 + strlcpy((char *)tables->sal_systab.product_id, "Xen/ia64", 6.107 + sizeof(tables->sal_systab.product_id)); 6.108 6.109 /* PAL entry point: */ 6.110 tables->sal_ed.type = SAL_DESC_ENTRY_POINT;
7.1 --- a/xen/arch/ia64/xen/domain.c Mon Jan 29 16:49:29 2007 +0000 7.2 +++ b/xen/arch/ia64/xen/domain.c Mon Jan 29 16:50:22 2007 +0000 7.3 @@ -1148,8 +1148,7 @@ int construct_dom0(struct domain *d, 7.4 dom_fw_setup(d, bp_mpa, max_pages * PAGE_SIZE); 7.5 7.6 /* Fill boot param. */ 7.7 - strncpy((char *)si->cmd_line, dom0_command_line, sizeof(si->cmd_line)); 7.8 - si->cmd_line[sizeof(si->cmd_line)-1] = 0; 7.9 + strlcpy((char *)si->cmd_line, dom0_command_line, sizeof(si->cmd_line)); 7.10 7.11 bp = (struct ia64_boot_param *)((unsigned char *)si + 7.12 sizeof(start_info_t));
8.1 --- a/xen/arch/ia64/xen/gdbstub.c Mon Jan 29 16:49:29 2007 +0000 8.2 +++ b/xen/arch/ia64/xen/gdbstub.c Mon Jan 29 16:50:22 2007 +0000 8.3 @@ -639,7 +639,7 @@ kgdb_get_reg(int regnum, struct unw_fram 8.4 outbuffer[size*2] = 0; 8.5 } 8.6 else 8.7 - strcpy(outbuffer, "E0"); 8.8 + strlcpy(outbuffer, "E0", sizeof("E0")); 8.9 8.10 return; 8.11 #else
9.1 --- a/xen/arch/ia64/xen/oprofile/perfmon.c Mon Jan 29 16:49:29 2007 +0000 9.2 +++ b/xen/arch/ia64/xen/oprofile/perfmon.c Mon Jan 29 16:50:22 2007 +0000 9.3 @@ -119,7 +119,7 @@ int 9.4 xenoprof_arch_init(int *num_events, int *is_primary, char *cpu_type) 9.5 { 9.6 *num_events = 0; 9.7 - strncpy(cpu_type, get_cpu_type(), XENOPROF_CPU_TYPE_SIZE - 1); 9.8 + strlcpy(cpu_type, get_cpu_type(), XENOPROF_CPU_TYPE_SIZE); 9.9 cpu_type[XENOPROF_CPU_TYPE_SIZE - 1] = '\0'; 9.10 9.11 *is_primary = 0;
10.1 --- a/xen/arch/powerpc/domain_build.c Mon Jan 29 16:49:29 2007 +0000 10.2 +++ b/xen/arch/powerpc/domain_build.c Mon Jan 29 16:50:22 2007 +0000 10.3 @@ -290,7 +290,7 @@ int construct_dom0(struct domain *d, 10.4 10.5 memset(si->cmd_line, 0, sizeof(si->cmd_line)); 10.6 if ( cmdline != NULL ) 10.7 - strncpy((char *)si->cmd_line, cmdline, sizeof(si->cmd_line)-1); 10.8 + strlcpy((char *)si->cmd_line, cmdline, sizeof(si->cmd_line)); 10.9 10.10 v->arch.ctxt.msr = msr; 10.11 v->arch.ctxt.pc = pc;
11.1 --- a/xen/arch/powerpc/of-devtree.c Mon Jan 29 16:49:29 2007 +0000 11.2 +++ b/xen/arch/powerpc/of-devtree.c Mon Jan 29 16:50:22 2007 +0000 11.3 @@ -358,8 +358,7 @@ static ofdn_t ofd_node_create( 11.4 n->on_io = 0; 11.5 n->on_pathlen = pathlen; 11.6 n->on_last = ofd_pathsplit_left(path, '/', pathlen); 11.7 - strncpy(n->on_path, path, pathlen); 11.8 - n->on_path[n->on_pathlen] = 0; 11.9 + strlcpy(n->on_path, path, pathlen); 11.10 11.11 return pos; 11.12 }
12.1 --- a/xen/arch/powerpc/ofd_fixup.c Mon Jan 29 16:49:29 2007 +0000 12.2 +++ b/xen/arch/powerpc/ofd_fixup.c Mon Jan 29 16:50:22 2007 +0000 12.3 @@ -267,7 +267,7 @@ static ofdn_t ofd_chosen_props(void *m, 12.4 &path[1], sizeof (path) - 1); 12.5 } 12.6 12.7 - strcpy(bootargs, cmdline); 12.8 + strlcpy(bootargs, cmdline, sizeof(bootargs)); 12.9 bsz = strlen(bootargs) + 1; 12.10 rm = sizeof (bootargs) - bsz; 12.11
13.1 --- a/xen/arch/x86/cpu/common.c Mon Jan 29 16:49:29 2007 +0000 13.2 +++ b/xen/arch/x86/cpu/common.c Mon Jan 29 16:50:22 2007 +0000 13.3 @@ -30,9 +30,9 @@ static void default_init(struct cpuinfo_ 13.4 if (c->cpuid_level == -1) { 13.5 /* No cpuid. It must be an ancient CPU */ 13.6 if (c->x86 == 4) 13.7 - strcpy(c->x86_model_id, "486"); 13.8 + safe_strcpy(c->x86_model_id, "486"); 13.9 else if (c->x86 == 3) 13.10 - strcpy(c->x86_model_id, "386"); 13.11 + safe_strcpy(c->x86_model_id, "386"); 13.12 } 13.13 } 13.14 13.15 @@ -383,7 +383,7 @@ void __devinit identify_cpu(struct cpuin 13.16 char *p; 13.17 p = table_lookup_model(c); 13.18 if ( p ) 13.19 - strcpy(c->x86_model_id, p); 13.20 + safe_strcpy(c->x86_model_id, p); 13.21 else 13.22 /* Last resort... */ 13.23 snprintf(c->x86_model_id, sizeof(c->x86_model_id),
14.1 --- a/xen/arch/x86/cpu/cyrix.c Mon Jan 29 16:49:29 2007 +0000 14.2 +++ b/xen/arch/x86/cpu/cyrix.c Mon Jan 29 16:50:22 2007 +0000 14.3 @@ -181,7 +181,6 @@ static void __init geode_configure(void) 14.4 static void __init init_cyrix(struct cpuinfo_x86 *c) 14.5 { 14.6 unsigned char dir0, dir0_msn, dir0_lsn, dir1 = 0; 14.7 - char *buf = c->x86_model_id; 14.8 const char *p = NULL; 14.9 14.10 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID; 14.11 @@ -302,8 +301,8 @@ static void __init init_cyrix(struct cpu 14.12 dir0_msn = 7; 14.13 break; 14.14 } 14.15 - strcpy(buf, Cx86_model[dir0_msn & 7]); 14.16 - if (p) strcat(buf, p); 14.17 + safe_strcpy(c->x86_model_id, Cx86_model[dir0_msn & 7]); 14.18 + if (p) safe_strcat(c->x86_model_id, p); 14.19 return; 14.20 } 14.21 14.22 @@ -339,7 +338,7 @@ static void cyrix_identify(struct cpuinf 14.23 if ( c->x86 == 4 && test_cyrix_52div() ) { 14.24 unsigned char dir0, dir1; 14.25 14.26 - strcpy(c->x86_vendor_id, "CyrixInstead"); 14.27 + safe_strcpy(c->x86_vendor_id, "CyrixInstead"); 14.28 c->x86_vendor = X86_VENDOR_CYRIX; 14.29 14.30 /* Actually enable cpuid on the older cyrix */
15.1 --- a/xen/arch/x86/cpu/intel.c Mon Jan 29 16:49:29 2007 +0000 15.2 +++ b/xen/arch/x86/cpu/intel.c Mon Jan 29 16:50:22 2007 +0000 15.3 @@ -152,7 +152,7 @@ static void __devinit init_intel(struct 15.4 } 15.5 15.6 if ( p ) 15.7 - strcpy(c->x86_model_id, p); 15.8 + safe_strcpy(c->x86_model_id, p); 15.9 15.10 c->x86_max_cores = num_cpu_cores(c); 15.11
16.1 --- a/xen/arch/x86/dmi_scan.c Mon Jan 29 16:49:29 2007 +0000 16.2 +++ b/xen/arch/x86/dmi_scan.c Mon Jan 29 16:50:22 2007 +0000 16.3 @@ -159,7 +159,7 @@ static void __init dmi_save_ident(struct 16.4 return; 16.5 dmi_ident[slot] = alloc_bootmem(strlen(p)+1); 16.6 if(dmi_ident[slot]) 16.7 - strcpy(dmi_ident[slot], p); 16.8 + safe_strcpy(dmi_ident[slot], p); 16.9 else 16.10 printk(KERN_ERR "dmi_save_ident: out of memory.\n"); 16.11 }
17.1 --- a/xen/arch/x86/domain_build.c Mon Jan 29 16:49:29 2007 +0000 17.2 +++ b/xen/arch/x86/domain_build.c Mon Jan 29 16:50:22 2007 +0000 17.3 @@ -871,7 +871,7 @@ int construct_dom0(struct domain *d, 17.4 17.5 memset(si->cmd_line, 0, sizeof(si->cmd_line)); 17.6 if ( cmdline != NULL ) 17.7 - strlcpy((char *)si->cmd_line, cmdline, sizeof(si->cmd_line)); 17.8 + safe_strcpy(si->cmd_line, cmdline); 17.9 17.10 if ( fill_console_start_info((void *)(si + 1)) ) 17.11 {
18.1 --- a/xen/arch/x86/hvm/intercept.c Mon Jan 29 16:49:29 2007 +0000 18.2 +++ b/xen/arch/x86/hvm/intercept.c Mon Jan 29 16:50:22 2007 +0000 18.3 @@ -173,7 +173,7 @@ int hvm_register_savevm(struct domain *d 18.4 return -1; 18.5 } 18.6 18.7 - strlcpy(se->idstr, idstr, HVM_SE_IDSTR_LEN); 18.8 + safe_strcpy(se->idstr, idstr); 18.9 18.10 se->instance_id = instance_id; 18.11 se->version_id = version_id; 18.12 @@ -217,7 +217,7 @@ int hvm_save(struct domain *d, hvm_domai 18.13 18.14 for(se = d->arch.hvm_domain.first_se; se != NULL; se = se->next) { 18.15 /* ID string */ 18.16 - len = strnlen(se->idstr, HVM_SE_IDSTR_LEN); 18.17 + len = strnlen(se->idstr, sizeof(se->idstr)); 18.18 hvm_put_8u(h, len); 18.19 hvm_put_buffer(h, se->idstr, len); 18.20 18.21 @@ -255,7 +255,7 @@ static HVMStateEntry *find_se(struct dom 18.22 HVMStateEntry *se; 18.23 18.24 for(se = d->arch.hvm_domain.first_se; se != NULL; se = se->next) { 18.25 - if (!strncmp(se->idstr, idstr, HVM_SE_IDSTR_LEN) && 18.26 + if (!strncmp(se->idstr, idstr, sizeof(se->idstr)) && 18.27 instance_id == se->instance_id){ 18.28 return se; 18.29 }
19.1 --- a/xen/arch/x86/setup.c Mon Jan 29 16:49:29 2007 +0000 19.2 +++ b/xen/arch/x86/setup.c Mon Jan 29 16:50:22 2007 +0000 19.3 @@ -111,7 +111,7 @@ char acpi_param[10] = ""; 19.4 static void parse_acpi_param(char *s) 19.5 { 19.6 /* Save the parameter so it can be propagated to domain0. */ 19.7 - strlcpy(acpi_param, s, sizeof(acpi_param)); 19.8 + safe_strcpy(acpi_param, s); 19.9 19.10 /* Interpret the parameter for use within Xen. */ 19.11 if ( !strcmp(s, "off") ) 19.12 @@ -748,22 +748,22 @@ void __init __start_xen(multiboot_info_t 19.13 if ( (cmdline = strchr(cmdline, ' ')) != NULL ) 19.14 { 19.15 while ( *cmdline == ' ' ) cmdline++; 19.16 - strcpy(dom0_cmdline, cmdline); 19.17 + safe_strcpy(dom0_cmdline, cmdline); 19.18 + } 19.19 + 19.20 + /* Append any extra parameters. */ 19.21 + if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") ) 19.22 + safe_strcat(dom0_cmdline, " noapic"); 19.23 + if ( acpi_skip_timer_override && 19.24 + !strstr(dom0_cmdline, "acpi_skip_timer_override") ) 19.25 + safe_strcat(dom0_cmdline, " acpi_skip_timer_override"); 19.26 + if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") ) 19.27 + { 19.28 + safe_strcat(dom0_cmdline, " acpi="); 19.29 + safe_strcat(dom0_cmdline, acpi_param); 19.30 } 19.31 19.32 cmdline = dom0_cmdline; 19.33 - 19.34 - /* Append any extra parameters. */ 19.35 - if ( skip_ioapic_setup && !strstr(cmdline, "noapic") ) 19.36 - strcat(cmdline, " noapic"); 19.37 - if ( acpi_skip_timer_override && 19.38 - !strstr(cmdline, "acpi_skip_timer_override") ) 19.39 - strcat(cmdline, " acpi_skip_timer_override"); 19.40 - if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") ) 19.41 - { 19.42 - strcat(cmdline, " acpi="); 19.43 - strcat(cmdline, acpi_param); 19.44 - } 19.45 } 19.46 19.47 if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) )
20.1 --- a/xen/common/kexec.c Mon Jan 29 16:49:29 2007 +0000 20.2 +++ b/xen/common/kexec.c Mon Jan 29 16:50:22 2007 +0000 20.3 @@ -131,7 +131,7 @@ static __init int register_crashdump_tri 20.4 20.5 static void setup_note(Elf_Note *n, const char *name, int type, int descsz) 20.6 { 20.7 - strcpy(ELFNOTE_NAME(n), name); 20.8 + safe_strcpy(ELFNOTE_NAME(n), name); 20.9 n->namesz = strlen(name); 20.10 n->descsz = descsz; 20.11 n->type = type;
21.1 --- a/xen/common/keyhandler.c Mon Jan 29 16:49:29 2007 +0000 21.2 +++ b/xen/common/keyhandler.c Mon Jan 29 16:50:22 2007 +0000 21.3 @@ -67,8 +67,7 @@ void register_keyhandler( 21.4 ASSERT(key_table[key].u.handler == NULL); 21.5 key_table[key].u.handler = handler; 21.6 key_table[key].flags = 0; 21.7 - strlcpy(key_table[key].desc, desc, STR_MAX); 21.8 - key_table[key].desc[STR_MAX-1] = '\0'; 21.9 + safe_strcpy(key_table[key].desc, desc); 21.10 } 21.11 21.12 void register_irq_keyhandler( 21.13 @@ -77,7 +76,7 @@ void register_irq_keyhandler( 21.14 ASSERT(key_table[key].u.irq_handler == NULL); 21.15 key_table[key].u.irq_handler = handler; 21.16 key_table[key].flags = KEYHANDLER_IRQ_CALLBACK; 21.17 - strlcpy(key_table[key].desc, desc, STR_MAX); 21.18 + safe_strcpy(key_table[key].desc, desc); 21.19 } 21.20 21.21 static void show_handlers(unsigned char key)
22.1 --- a/xen/common/libelf/libelf-dominfo.c Mon Jan 29 16:49:29 2007 +0000 22.2 +++ b/xen/common/libelf/libelf-dominfo.c Mon Jan 29 16:50:22 2007 +0000 22.3 @@ -128,16 +128,16 @@ int elf_xen_parse_note(struct elf_binary 22.4 switch (type) 22.5 { 22.6 case XEN_ELFNOTE_LOADER: 22.7 - elf_strlcpy(parms->loader, str, sizeof(parms->loader)); 22.8 + safe_strcpy(parms->loader, str); 22.9 break; 22.10 case XEN_ELFNOTE_GUEST_OS: 22.11 - elf_strlcpy(parms->guest_os, str, sizeof(parms->guest_os)); 22.12 + safe_strcpy(parms->guest_os, str); 22.13 break; 22.14 case XEN_ELFNOTE_GUEST_VERSION: 22.15 - elf_strlcpy(parms->guest_ver, str, sizeof(parms->guest_ver)); 22.16 + safe_strcpy(parms->guest_ver, str); 22.17 break; 22.18 case XEN_ELFNOTE_XEN_VERSION: 22.19 - elf_strlcpy(parms->xen_ver, str, sizeof(parms->xen_ver)); 22.20 + safe_strcpy(parms->xen_ver, str); 22.21 break; 22.22 case XEN_ELFNOTE_PAE_MODE: 22.23 if (0 == strcmp(str, "yes")) 22.24 @@ -224,13 +224,13 @@ int elf_xen_parse_guest_info(struct elf_ 22.25 22.26 /* strings */ 22.27 if (0 == strcmp(name, "LOADER")) 22.28 - elf_strlcpy(parms->loader, value, sizeof(parms->loader)); 22.29 + safe_strcpy(parms->loader, value); 22.30 if (0 == strcmp(name, "GUEST_OS")) 22.31 - elf_strlcpy(parms->guest_os, value, sizeof(parms->guest_os)); 22.32 + safe_strcpy(parms->guest_os, value); 22.33 if (0 == strcmp(name, "GUEST_VER")) 22.34 - elf_strlcpy(parms->guest_ver, value, sizeof(parms->guest_ver)); 22.35 + safe_strcpy(parms->guest_ver, value); 22.36 if (0 == strcmp(name, "XEN_VER")) 22.37 - elf_strlcpy(parms->xen_ver, value, sizeof(parms->xen_ver)); 22.38 + safe_strcpy(parms->xen_ver, value); 22.39 if (0 == strcmp(name, "PAE")) 22.40 { 22.41 if (0 == strcmp(value, "yes[extended-cr3]"))
23.1 --- a/xen/common/libelf/libelf-private.h Mon Jan 29 16:49:29 2007 +0000 23.2 +++ b/xen/common/libelf/libelf-private.h Mon Jan 29 16:50:22 2007 +0000 23.3 @@ -21,8 +21,6 @@ 23.4 #define bswap_32(x) swab32(x) 23.5 #define bswap_64(x) swab64(x) 23.6 23.7 -#define elf_strlcpy(d,s,c) strlcpy(d,s,c) 23.8 - 23.9 #else /* !__XEN__ */ 23.10 23.11 #include <stdio.h> 23.12 @@ -52,13 +50,10 @@ 23.13 xc_set_error(XC_INVALID_KERNEL, fmt , ## args ); \ 23.14 } while (0) 23.15 23.16 -/* SysV unices have no strlcpy/strlcat. */ 23.17 -static inline size_t elf_strlcpy(char *dest, const char *src, size_t size) 23.18 -{ 23.19 - strncpy(dest, src, size-1); 23.20 - dest[size-1] = '\0'; 23.21 - return strlen(src); 23.22 -} 23.23 +#define safe_strcpy(d,s) \ 23.24 +do { strncpy((d),(s),sizeof((d))-1); \ 23.25 + (d)[sizeof((d))-1] = '\0'; \ 23.26 +} while (0) 23.27 23.28 #endif 23.29
24.1 --- a/xen/common/perfc.c Mon Jan 29 16:49:29 2007 +0000 24.2 +++ b/xen/common/perfc.c Mon Jan 29 16:50:22 2007 +0000 24.3 @@ -148,8 +148,7 @@ static int perfc_copy_info(XEN_GUEST_HAN 24.4 { 24.5 for ( i = 0; i < NR_PERFCTRS; i++ ) 24.6 { 24.7 - strlcpy(perfc_d[i].name, perfc_info[i].name, 24.8 - sizeof(perfc_d[i].name)); 24.9 + safe_strcpy(perfc_d[i].name, perfc_info[i].name); 24.10 24.11 switch ( perfc_info[i].type ) 24.12 {
25.1 --- a/xen/common/rangeset.c Mon Jan 29 16:49:29 2007 +0000 25.2 +++ b/xen/common/rangeset.c Mon Jan 29 16:50:22 2007 +0000 25.3 @@ -283,7 +283,7 @@ struct rangeset *rangeset_new( 25.4 25.5 if ( name != NULL ) 25.6 { 25.7 - strlcpy(r->name, name, sizeof(r->name)); 25.8 + safe_strcpy(r->name, name); 25.9 } 25.10 else 25.11 {
26.1 --- a/xen/common/string.c Mon Jan 29 16:49:29 2007 +0000 26.2 +++ b/xen/common/string.c Mon Jan 29 16:50:22 2007 +0000 26.3 @@ -41,44 +41,6 @@ int strnicmp(const char *s1, const char 26.4 } 26.5 #endif 26.6 26.7 -#ifndef __HAVE_ARCH_STRCPY 26.8 -/** 26.9 - * strcpy - Copy a %NUL terminated string 26.10 - * @dest: Where to copy the string to 26.11 - * @src: Where to copy the string from 26.12 - */ 26.13 -char * strcpy(char * dest,const char *src) 26.14 -{ 26.15 - char *tmp = dest; 26.16 - 26.17 - while ((*dest++ = *src++) != '\0') 26.18 - /* nothing */; 26.19 - return tmp; 26.20 -} 26.21 -#endif 26.22 - 26.23 -#ifndef __HAVE_ARCH_STRNCPY 26.24 -/** 26.25 - * strncpy - Copy a length-limited, %NUL-terminated string 26.26 - * @dest: Where to copy the string to 26.27 - * @src: Where to copy the string from 26.28 - * @count: The maximum number of bytes to copy 26.29 - * 26.30 - * Note that unlike userspace strncpy, this does not %NUL-pad the buffer. 26.31 - * However, the result is not %NUL-terminated if the source exceeds 26.32 - * @count bytes. 26.33 - */ 26.34 -char * strncpy(char * dest,const char *src,size_t count) 26.35 -{ 26.36 - char *tmp = dest; 26.37 - 26.38 - while (count-- && (*dest++ = *src++) != '\0') 26.39 - /* nothing */; 26.40 - 26.41 - return tmp; 26.42 -} 26.43 -#endif 26.44 - 26.45 #ifndef __HAVE_ARCH_STRLCPY 26.46 /** 26.47 * strlcpy - Copy a %NUL terminated string into a sized buffer 26.48 @@ -105,52 +67,33 @@ size_t strlcpy(char *dest, const char *s 26.49 EXPORT_SYMBOL(strlcpy); 26.50 #endif 26.51 26.52 -#ifndef __HAVE_ARCH_STRCAT 26.53 -/** 26.54 - * strcat - Append one %NUL-terminated string to another 26.55 - * @dest: The string to be appended to 26.56 - * @src: The string to append to it 26.57 - */ 26.58 -char * strcat(char * dest, const char * src) 26.59 -{ 26.60 - char *tmp = dest; 26.61 - 26.62 - while (*dest) 26.63 - dest++; 26.64 - while ((*dest++ = *src++) != '\0') 26.65 - ; 26.66 - 26.67 - return tmp; 26.68 -} 26.69 -#endif 26.70 - 26.71 -#ifndef __HAVE_ARCH_STRNCAT 26.72 +#ifndef __HAVE_ARCH_STRLCAT 26.73 /** 26.74 - * strncat - Append a length-limited, %NUL-terminated string to another 26.75 - * @dest: The string to be appended to 26.76 - * @src: The string to append to it 26.77 - * @count: The maximum numbers of bytes to copy 26.78 + * strlcat - Append a %NUL terminated string into a sized buffer 26.79 + * @dest: Where to copy the string to 26.80 + * @src: Where to copy the string from 26.81 + * @size: size of destination buffer 26.82 * 26.83 - * Note that in contrast to strncpy, strncat ensures the result is 26.84 - * terminated. 26.85 + * Compatible with *BSD: the result is always a valid 26.86 + * NUL-terminated string that fits in the buffer (unless, 26.87 + * of course, the buffer size is zero). 26.88 */ 26.89 -char * strncat(char *dest, const char *src, size_t count) 26.90 +size_t strlcat(char *dest, const char *src, size_t size) 26.91 { 26.92 - char *tmp = dest; 26.93 + size_t slen = strlen(src); 26.94 + size_t dlen = strnlen(dest, size); 26.95 + char *p = dest + dlen; 26.96 26.97 - if (count) { 26.98 - while (*dest) 26.99 - dest++; 26.100 - while ((*dest++ = *src++)) { 26.101 - if (--count == 0) { 26.102 - *dest = '\0'; 26.103 - break; 26.104 - } 26.105 - } 26.106 - } 26.107 + while ((p - dest) < size) 26.108 + if ((*p++ = *src++) == '\0') 26.109 + break; 26.110 26.111 - return tmp; 26.112 + if (dlen < size) 26.113 + *(p-1) = '\0'; 26.114 + 26.115 + return slen + dlen; 26.116 } 26.117 +EXPORT_SYMBOL(strlcat); 26.118 #endif 26.119 26.120 #ifndef __HAVE_ARCH_STRCMP
27.1 --- a/xen/drivers/char/console.c Mon Jan 29 16:49:29 2007 +0000 27.2 +++ b/xen/drivers/char/console.c Mon Jan 29 16:50:22 2007 +0000 27.3 @@ -481,7 +481,7 @@ void printk(const char *fmt, ...) 27.4 27.5 void set_printk_prefix(const char *prefix) 27.6 { 27.7 - strcpy(printk_prefix, prefix); 27.8 + safe_strcpy(printk_prefix, prefix); 27.9 } 27.10 27.11 void init_console(void) 27.12 @@ -771,7 +771,7 @@ void debugtrace_printk(const char *fmt, 27.13 27.14 ASSERT(debugtrace_buf[debugtrace_bytes - 1] == 0); 27.15 27.16 - sprintf(buf, "%u ", ++count); 27.17 + snprintf(buf, sizeof(buf), "%u ", ++count); 27.18 27.19 va_start(args, fmt); 27.20 (void)vsnprintf(buf + strlen(buf), sizeof(buf), fmt, args);
28.1 --- a/xen/include/acm/acm_endian.h Mon Jan 29 16:49:29 2007 +0000 28.2 +++ b/xen/include/acm/acm_endian.h Mon Jan 29 16:50:22 2007 +0000 28.3 @@ -22,57 +22,27 @@ 28.4 #ifndef _ACM_ENDIAN_H 28.5 #define _ACM_ENDIAN_H 28.6 28.7 -/* don't use these functions in performance critical sections! */ 28.8 - 28.9 -/* set during initialization by testing */ 28.10 -extern u8 little_endian; 28.11 - 28.12 -static inline u32 ntohl(u32 x) 28.13 -{ 28.14 - if (little_endian) 28.15 - return 28.16 - ( (((x) >> 24) & 0xff )| 28.17 - (((x) >> 8) & 0xff00 )| 28.18 - (((x) << 8) & 0xff0000 )| 28.19 - (((x) << 24) & 0xff000000) ); 28.20 - else 28.21 - return x; 28.22 -} 28.23 - 28.24 -static inline u16 ntohs(u16 x) 28.25 -{ 28.26 - if (little_endian) 28.27 - return 28.28 - ( (((x) >> 8) & 0xff )| 28.29 - (((x) << 8) & 0xff00 ) ); 28.30 - else 28.31 - return x; 28.32 -} 28.33 - 28.34 -#define htonl(x) ntohl(x) 28.35 -#define htons(x) ntohs(x) 28.36 +#include <asm/byteorder.h> 28.37 28.38 static inline void arrcpy16(u16 *dest, const u16 *src, size_t n) 28.39 { 28.40 - unsigned int i = 0; 28.41 - while (i < n) { 28.42 - dest[i] = htons(src[i]); 28.43 - i++; 28.44 - } 28.45 + unsigned int i; 28.46 + for ( i = 0; i < n; i++ ) 28.47 + dest[i] = cpu_to_be16(src[i]); 28.48 } 28.49 28.50 static inline void arrcpy32(u32 *dest, const u32 *src, size_t n) 28.51 { 28.52 - unsigned int i = 0; 28.53 - while (i < n) { 28.54 - dest[i] = htonl(src[i]); 28.55 - i++; 28.56 - } 28.57 + unsigned int i; 28.58 + for ( i = 0; i < n; i++ ) 28.59 + dest[i] = cpu_to_be32(src[i]); 28.60 } 28.61 28.62 -static inline void arrcpy(void *dest, const void *src, unsigned int elsize, size_t n) 28.63 +static inline void arrcpy( 28.64 + void *dest, const void *src, unsigned int elsize, size_t n) 28.65 { 28.66 - switch (elsize) { 28.67 + switch ( elsize ) 28.68 + { 28.69 case sizeof(u16): 28.70 arrcpy16((u16 *)dest, (u16 *)src, n); 28.71 break;
29.1 --- a/xen/include/xen/byteorder/big_endian.h Mon Jan 29 16:49:29 2007 +0000 29.2 +++ b/xen/include/xen/byteorder/big_endian.h Mon Jan 29 16:50:22 2007 +0000 29.3 @@ -11,10 +11,6 @@ 29.4 #include <xen/types.h> 29.5 #include <xen/byteorder/swab.h> 29.6 29.7 -#define __constant_htonl(x) ((__force __be32)(__u32)(x)) 29.8 -#define __constant_ntohl(x) ((__force __u32)(__be32)(x)) 29.9 -#define __constant_htons(x) ((__force __be16)(__u16)(x)) 29.10 -#define __constant_ntohs(x) ((__force __u16)(__be16)(x)) 29.11 #define __constant_cpu_to_le64(x) ((__force __le64)___constant_swab64((x))) 29.12 #define __constant_le64_to_cpu(x) ___constant_swab64((__force __u64)(__le64)(x)) 29.13 #define __constant_cpu_to_le32(x) ((__force __le32)___constant_swab32((x)))
30.1 --- a/xen/include/xen/byteorder/little_endian.h Mon Jan 29 16:49:29 2007 +0000 30.2 +++ b/xen/include/xen/byteorder/little_endian.h Mon Jan 29 16:50:22 2007 +0000 30.3 @@ -11,10 +11,6 @@ 30.4 #include <xen/types.h> 30.5 #include <xen/byteorder/swab.h> 30.6 30.7 -#define __constant_htonl(x) ((__force __be32)___constant_swab32((x))) 30.8 -#define __constant_ntohl(x) ___constant_swab32((__force __be32)(x)) 30.9 -#define __constant_htons(x) ((__force __be16)___constant_swab16((x))) 30.10 -#define __constant_ntohs(x) ___constant_swab16((__force __be16)(x)) 30.11 #define __constant_cpu_to_le64(x) ((__force __le64)(__u64)(x)) 30.12 #define __constant_le64_to_cpu(x) ((__force __u64)(__le64)(x)) 30.13 #define __constant_cpu_to_le32(x) ((__force __le32)(__u32)(x))
31.1 --- a/xen/include/xen/string.h Mon Jan 29 16:49:29 2007 +0000 31.2 +++ b/xen/include/xen/string.h Mon Jan 29 16:50:22 2007 +0000 31.3 @@ -19,20 +19,20 @@ extern __kernel_size_t strspn(const char 31.4 */ 31.5 #include <asm/string.h> 31.6 31.7 -#ifndef __HAVE_ARCH_STRCPY 31.8 -extern char * strcpy(char *,const char *); 31.9 -#endif 31.10 -#ifndef __HAVE_ARCH_STRNCPY 31.11 -extern char * strncpy(char *,const char *, __kernel_size_t); 31.12 -#endif 31.13 +/* 31.14 + * These string functions are considered too dangerous for normal use. 31.15 + * Use safe_strcpy(), safe_strcat(), strlcpy(), strlcat() as appropriate. 31.16 + */ 31.17 +#define strcpy __xen_has_no_strcpy__ 31.18 +#define strcat __xen_has_no_strcat__ 31.19 +#define strncpy __xen_has_no_strncpy__ 31.20 +#define strncat __xen_has_no_strncat__ 31.21 + 31.22 #ifndef __HAVE_ARCH_STRLCPY 31.23 extern size_t strlcpy(char *,const char *, __kernel_size_t); 31.24 #endif 31.25 -#ifndef __HAVE_ARCH_STRCAT 31.26 -extern char * strcat(char *, const char *); 31.27 -#endif 31.28 -#ifndef __HAVE_ARCH_STRNCAT 31.29 -extern char * strncat(char *, const char *, __kernel_size_t); 31.30 +#ifndef __HAVE_ARCH_STRLCAT 31.31 +extern size_t strlcat(char *,const char *, __kernel_size_t); 31.32 #endif 31.33 #ifndef __HAVE_ARCH_STRCMP 31.34 extern int strcmp(const char *,const char *); 31.35 @@ -82,9 +82,8 @@ extern void * memchr(const void *,int,__ 31.36 } 31.37 #endif 31.38 31.39 -#define safe_strcpy(d,s) \ 31.40 -do { strncpy((d),(s),sizeof((d))); \ 31.41 - (d)[sizeof((d))-1] = '\0'; \ 31.42 -} while (0) 31.43 +/* safe_xxx always NUL-terminates and returns !=0 if result is truncated. */ 31.44 +#define safe_strcpy(d, s) (strlcpy(d, s, sizeof(d)) >= sizeof(d)) 31.45 +#define safe_strcat(d, s) (strlcat(d, s, sizeof(d)) >= sizeof(d)) 31.46 31.47 #endif /* _LINUX_STRING_H_ */