Commit f56ef406 authored by Florian Westphal's avatar Florian Westphal Committed by Ben Hutchings

netfilter: ip6_tables: simplify translate_compat_table args

commit 329a0807 upstream.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent a33db92f
...@@ -1440,7 +1440,6 @@ compat_copy_entry_to_user(struct ip6t_entry *e, void __user **dstptr, ...@@ -1440,7 +1440,6 @@ compat_copy_entry_to_user(struct ip6t_entry *e, void __user **dstptr,
static int static int
compat_find_calc_match(struct xt_entry_match *m, compat_find_calc_match(struct xt_entry_match *m,
const char *name,
const struct ip6t_ip6 *ipv6, const struct ip6t_ip6 *ipv6,
unsigned int hookmask, unsigned int hookmask,
int *size) int *size)
...@@ -1478,8 +1477,7 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e, ...@@ -1478,8 +1477,7 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
const unsigned char *base, const unsigned char *base,
const unsigned char *limit, const unsigned char *limit,
const unsigned int *hook_entries, const unsigned int *hook_entries,
const unsigned int *underflows, const unsigned int *underflows)
const char *name)
{ {
struct xt_entry_match *ematch; struct xt_entry_match *ematch;
struct xt_entry_target *t; struct xt_entry_target *t;
...@@ -1515,8 +1513,8 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e, ...@@ -1515,8 +1513,8 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
entry_offset = (void *)e - (void *)base; entry_offset = (void *)e - (void *)base;
j = 0; j = 0;
xt_ematch_foreach(ematch, e) { xt_ematch_foreach(ematch, e) {
ret = compat_find_calc_match(ematch, name, ret = compat_find_calc_match(ematch, &e->ipv6, e->comefrom,
&e->ipv6, e->comefrom, &off); &off);
if (ret != 0) if (ret != 0)
goto release_matches; goto release_matches;
++j; ++j;
...@@ -1565,7 +1563,7 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e, ...@@ -1565,7 +1563,7 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
static int static int
compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr, compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr,
unsigned int *size, const char *name, unsigned int *size,
struct xt_table_info *newinfo, unsigned char *base) struct xt_table_info *newinfo, unsigned char *base)
{ {
struct xt_entry_target *t; struct xt_entry_target *t;
...@@ -1639,14 +1637,9 @@ static int compat_check_entry(struct ip6t_entry *e, struct net *net, ...@@ -1639,14 +1637,9 @@ static int compat_check_entry(struct ip6t_entry *e, struct net *net,
static int static int
translate_compat_table(struct net *net, translate_compat_table(struct net *net,
const char *name,
unsigned int valid_hooks,
struct xt_table_info **pinfo, struct xt_table_info **pinfo,
void **pentry0, void **pentry0,
unsigned int total_size, const struct compat_ip6t_replace *compatr)
unsigned int number,
unsigned int *hook_entries,
unsigned int *underflows)
{ {
unsigned int i, j; unsigned int i, j;
struct xt_table_info *newinfo, *info; struct xt_table_info *newinfo, *info;
...@@ -1658,8 +1651,8 @@ translate_compat_table(struct net *net, ...@@ -1658,8 +1651,8 @@ translate_compat_table(struct net *net,
info = *pinfo; info = *pinfo;
entry0 = *pentry0; entry0 = *pentry0;
size = total_size; size = compatr->size;
info->number = number; info->number = compatr->num_entries;
/* Init all hooks to impossible value. */ /* Init all hooks to impossible value. */
for (i = 0; i < NF_INET_NUMHOOKS; i++) { for (i = 0; i < NF_INET_NUMHOOKS; i++) {
...@@ -1670,40 +1663,39 @@ translate_compat_table(struct net *net, ...@@ -1670,40 +1663,39 @@ translate_compat_table(struct net *net,
duprintf("translate_compat_table: size %u\n", info->size); duprintf("translate_compat_table: size %u\n", info->size);
j = 0; j = 0;
xt_compat_lock(AF_INET6); xt_compat_lock(AF_INET6);
xt_compat_init_offsets(AF_INET6, number); xt_compat_init_offsets(AF_INET6, compatr->num_entries);
/* Walk through entries, checking offsets. */ /* Walk through entries, checking offsets. */
xt_entry_foreach(iter0, entry0, total_size) { xt_entry_foreach(iter0, entry0, compatr->size) {
ret = check_compat_entry_size_and_hooks(iter0, info, &size, ret = check_compat_entry_size_and_hooks(iter0, info, &size,
entry0, entry0,
entry0 + total_size, entry0 + compatr->size,
hook_entries, compatr->hook_entry,
underflows, compatr->underflow);
name);
if (ret != 0) if (ret != 0)
goto out_unlock; goto out_unlock;
++j; ++j;
} }
ret = -EINVAL; ret = -EINVAL;
if (j != number) { if (j != compatr->num_entries) {
duprintf("translate_compat_table: %u not %u entries\n", duprintf("translate_compat_table: %u not %u entries\n",
j, number); j, compatr->num_entries);
goto out_unlock; goto out_unlock;
} }
/* Check hooks all assigned */ /* Check hooks all assigned */
for (i = 0; i < NF_INET_NUMHOOKS; i++) { for (i = 0; i < NF_INET_NUMHOOKS; i++) {
/* Only hooks which are valid */ /* Only hooks which are valid */
if (!(valid_hooks & (1 << i))) if (!(compatr->valid_hooks & (1 << i)))
continue; continue;
if (info->hook_entry[i] == 0xFFFFFFFF) { if (info->hook_entry[i] == 0xFFFFFFFF) {
duprintf("Invalid hook entry %u %u\n", duprintf("Invalid hook entry %u %u\n",
i, hook_entries[i]); i, info->hook_entry[i]);
goto out_unlock; goto out_unlock;
} }
if (info->underflow[i] == 0xFFFFFFFF) { if (info->underflow[i] == 0xFFFFFFFF) {
duprintf("Invalid underflow %u %u\n", duprintf("Invalid underflow %u %u\n",
i, underflows[i]); i, info->underflow[i]);
goto out_unlock; goto out_unlock;
} }
} }
...@@ -1713,17 +1705,17 @@ translate_compat_table(struct net *net, ...@@ -1713,17 +1705,17 @@ translate_compat_table(struct net *net,
if (!newinfo) if (!newinfo)
goto out_unlock; goto out_unlock;
newinfo->number = number; newinfo->number = compatr->num_entries;
for (i = 0; i < NF_INET_NUMHOOKS; i++) { for (i = 0; i < NF_INET_NUMHOOKS; i++) {
newinfo->hook_entry[i] = info->hook_entry[i]; newinfo->hook_entry[i] = info->hook_entry[i];
newinfo->underflow[i] = info->underflow[i]; newinfo->underflow[i] = info->underflow[i];
} }
entry1 = newinfo->entries[raw_smp_processor_id()]; entry1 = newinfo->entries[raw_smp_processor_id()];
pos = entry1; pos = entry1;
size = total_size; size = compatr->size;
xt_entry_foreach(iter0, entry0, total_size) { xt_entry_foreach(iter0, entry0, compatr->size) {
ret = compat_copy_entry_from_user(iter0, &pos, &size, ret = compat_copy_entry_from_user(iter0, &pos, &size,
name, newinfo, entry1); newinfo, entry1);
if (ret != 0) if (ret != 0)
break; break;
} }
...@@ -1733,12 +1725,12 @@ translate_compat_table(struct net *net, ...@@ -1733,12 +1725,12 @@ translate_compat_table(struct net *net,
goto free_newinfo; goto free_newinfo;
ret = -ELOOP; ret = -ELOOP;
if (!mark_source_chains(newinfo, valid_hooks, entry1)) if (!mark_source_chains(newinfo, compatr->valid_hooks, entry1))
goto free_newinfo; goto free_newinfo;
i = 0; i = 0;
xt_entry_foreach(iter1, entry1, newinfo->size) { xt_entry_foreach(iter1, entry1, newinfo->size) {
ret = compat_check_entry(iter1, net, name); ret = compat_check_entry(iter1, net, compatr->name);
if (ret != 0) if (ret != 0)
break; break;
++i; ++i;
...@@ -1783,7 +1775,7 @@ translate_compat_table(struct net *net, ...@@ -1783,7 +1775,7 @@ translate_compat_table(struct net *net,
free_newinfo: free_newinfo:
xt_free_table_info(newinfo); xt_free_table_info(newinfo);
out: out:
xt_entry_foreach(iter0, entry0, total_size) { xt_entry_foreach(iter0, entry0, compatr->size) {
if (j-- == 0) if (j-- == 0)
break; break;
compat_release_entry(iter0); compat_release_entry(iter0);
...@@ -1826,10 +1818,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len) ...@@ -1826,10 +1818,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
goto free_newinfo; goto free_newinfo;
} }
ret = translate_compat_table(net, tmp.name, tmp.valid_hooks, ret = translate_compat_table(net, &newinfo, &loc_cpu_entry, &tmp);
&newinfo, &loc_cpu_entry, tmp.size,
tmp.num_entries, tmp.hook_entry,
tmp.underflow);
if (ret != 0) if (ret != 0)
goto free_newinfo; goto free_newinfo;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment