Skip to content

Commit 0fab6d3

Browse files
Florian Westphalgregkh
authored andcommitted
netfilter: ip6_tables: simplify translate_compat_table args
commit 329a0807124f12fe1c8032f95d8a8eb47047fb0e upstream. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 77521be commit 0fab6d3

1 file changed

Lines changed: 24 additions & 35 deletions

File tree

net/ipv6/netfilter/ip6_tables.c

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,6 @@ compat_copy_entry_to_user(struct ip6t_entry *e, void __user **dstptr,
14601460

14611461
static int
14621462
compat_find_calc_match(struct xt_entry_match *m,
1463-
const char *name,
14641463
const struct ip6t_ip6 *ipv6,
14651464
int *size)
14661465
{
@@ -1497,8 +1496,7 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
14971496
const unsigned char *base,
14981497
const unsigned char *limit,
14991498
const unsigned int *hook_entries,
1500-
const unsigned int *underflows,
1501-
const char *name)
1499+
const unsigned int *underflows)
15021500
{
15031501
struct xt_entry_match *ematch;
15041502
struct xt_entry_target *t;
@@ -1534,7 +1532,7 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
15341532
entry_offset = (void *)e - (void *)base;
15351533
j = 0;
15361534
xt_ematch_foreach(ematch, e) {
1537-
ret = compat_find_calc_match(ematch, name, &e->ipv6, &off);
1535+
ret = compat_find_calc_match(ematch, &e->ipv6, &off);
15381536
if (ret != 0)
15391537
goto release_matches;
15401538
++j;
@@ -1583,7 +1581,7 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
15831581

15841582
static int
15851583
compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr,
1586-
unsigned int *size, const char *name,
1584+
unsigned int *size,
15871585
struct xt_table_info *newinfo, unsigned char *base)
15881586
{
15891587
struct xt_entry_target *t;
@@ -1663,14 +1661,9 @@ static int compat_check_entry(struct ip6t_entry *e, struct net *net,
16631661

16641662
static int
16651663
translate_compat_table(struct net *net,
1666-
const char *name,
1667-
unsigned int valid_hooks,
16681664
struct xt_table_info **pinfo,
16691665
void **pentry0,
1670-
unsigned int total_size,
1671-
unsigned int number,
1672-
unsigned int *hook_entries,
1673-
unsigned int *underflows)
1666+
const struct compat_ip6t_replace *compatr)
16741667
{
16751668
unsigned int i, j;
16761669
struct xt_table_info *newinfo, *info;
@@ -1682,8 +1675,8 @@ translate_compat_table(struct net *net,
16821675

16831676
info = *pinfo;
16841677
entry0 = *pentry0;
1685-
size = total_size;
1686-
info->number = number;
1678+
size = compatr->size;
1679+
info->number = compatr->num_entries;
16871680

16881681
/* Init all hooks to impossible value. */
16891682
for (i = 0; i < NF_INET_NUMHOOKS; i++) {
@@ -1694,40 +1687,39 @@ translate_compat_table(struct net *net,
16941687
duprintf("translate_compat_table: size %u\n", info->size);
16951688
j = 0;
16961689
xt_compat_lock(AF_INET6);
1697-
xt_compat_init_offsets(AF_INET6, number);
1690+
xt_compat_init_offsets(AF_INET6, compatr->num_entries);
16981691
/* Walk through entries, checking offsets. */
1699-
xt_entry_foreach(iter0, entry0, total_size) {
1692+
xt_entry_foreach(iter0, entry0, compatr->size) {
17001693
ret = check_compat_entry_size_and_hooks(iter0, info, &size,
17011694
entry0,
1702-
entry0 + total_size,
1703-
hook_entries,
1704-
underflows,
1705-
name);
1695+
entry0 + compatr->size,
1696+
compatr->hook_entry,
1697+
compatr->underflow);
17061698
if (ret != 0)
17071699
goto out_unlock;
17081700
++j;
17091701
}
17101702

17111703
ret = -EINVAL;
1712-
if (j != number) {
1704+
if (j != compatr->num_entries) {
17131705
duprintf("translate_compat_table: %u not %u entries\n",
1714-
j, number);
1706+
j, compatr->num_entries);
17151707
goto out_unlock;
17161708
}
17171709

17181710
/* Check hooks all assigned */
17191711
for (i = 0; i < NF_INET_NUMHOOKS; i++) {
17201712
/* Only hooks which are valid */
1721-
if (!(valid_hooks & (1 << i)))
1713+
if (!(compatr->valid_hooks & (1 << i)))
17221714
continue;
17231715
if (info->hook_entry[i] == 0xFFFFFFFF) {
17241716
duprintf("Invalid hook entry %u %u\n",
1725-
i, hook_entries[i]);
1717+
i, info->hook_entry[i]);
17261718
goto out_unlock;
17271719
}
17281720
if (info->underflow[i] == 0xFFFFFFFF) {
17291721
duprintf("Invalid underflow %u %u\n",
1730-
i, underflows[i]);
1722+
i, info->underflow[i]);
17311723
goto out_unlock;
17321724
}
17331725
}
@@ -1737,17 +1729,17 @@ translate_compat_table(struct net *net,
17371729
if (!newinfo)
17381730
goto out_unlock;
17391731

1740-
newinfo->number = number;
1732+
newinfo->number = compatr->num_entries;
17411733
for (i = 0; i < NF_INET_NUMHOOKS; i++) {
17421734
newinfo->hook_entry[i] = info->hook_entry[i];
17431735
newinfo->underflow[i] = info->underflow[i];
17441736
}
17451737
entry1 = newinfo->entries;
17461738
pos = entry1;
1747-
size = total_size;
1748-
xt_entry_foreach(iter0, entry0, total_size) {
1739+
size = compatr->size;
1740+
xt_entry_foreach(iter0, entry0, compatr->size) {
17491741
ret = compat_copy_entry_from_user(iter0, &pos, &size,
1750-
name, newinfo, entry1);
1742+
newinfo, entry1);
17511743
if (ret != 0)
17521744
break;
17531745
}
@@ -1757,12 +1749,12 @@ translate_compat_table(struct net *net,
17571749
goto free_newinfo;
17581750

17591751
ret = -ELOOP;
1760-
if (!mark_source_chains(newinfo, valid_hooks, entry1))
1752+
if (!mark_source_chains(newinfo, compatr->valid_hooks, entry1))
17611753
goto free_newinfo;
17621754

17631755
i = 0;
17641756
xt_entry_foreach(iter1, entry1, newinfo->size) {
1765-
ret = compat_check_entry(iter1, net, name);
1757+
ret = compat_check_entry(iter1, net, compatr->name);
17661758
if (ret != 0)
17671759
break;
17681760
++i;
@@ -1802,7 +1794,7 @@ translate_compat_table(struct net *net,
18021794
free_newinfo:
18031795
xt_free_table_info(newinfo);
18041796
out:
1805-
xt_entry_foreach(iter0, entry0, total_size) {
1797+
xt_entry_foreach(iter0, entry0, compatr->size) {
18061798
if (j-- == 0)
18071799
break;
18081800
compat_release_entry(iter0);
@@ -1847,10 +1839,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
18471839
goto free_newinfo;
18481840
}
18491841

1850-
ret = translate_compat_table(net, tmp.name, tmp.valid_hooks,
1851-
&newinfo, &loc_cpu_entry, tmp.size,
1852-
tmp.num_entries, tmp.hook_entry,
1853-
tmp.underflow);
1842+
ret = translate_compat_table(net, &newinfo, &loc_cpu_entry, &tmp);
18541843
if (ret != 0)
18551844
goto free_newinfo;
18561845

0 commit comments

Comments
 (0)