Skip to content

Commit 77521be

Browse files
Florian Westphalgregkh
authored andcommitted
netfilter: ip_tables: simplify translate_compat_table args
commit 7d3f843eed29222254c9feab481f55175a1afcc9 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 946e814 commit 77521be

1 file changed

Lines changed: 24 additions & 35 deletions

File tree

net/ipv4/netfilter/ip_tables.c

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

14491449
static int
14501450
compat_find_calc_match(struct xt_entry_match *m,
1451-
const char *name,
14521451
const struct ipt_ip *ip,
14531452
int *size)
14541453
{
@@ -1485,8 +1484,7 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
14851484
const unsigned char *base,
14861485
const unsigned char *limit,
14871486
const unsigned int *hook_entries,
1488-
const unsigned int *underflows,
1489-
const char *name)
1487+
const unsigned int *underflows)
14901488
{
14911489
struct xt_entry_match *ematch;
14921490
struct xt_entry_target *t;
@@ -1522,7 +1520,7 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
15221520
entry_offset = (void *)e - (void *)base;
15231521
j = 0;
15241522
xt_ematch_foreach(ematch, e) {
1525-
ret = compat_find_calc_match(ematch, name, &e->ip, &off);
1523+
ret = compat_find_calc_match(ematch, &e->ip, &off);
15261524
if (ret != 0)
15271525
goto release_matches;
15281526
++j;
@@ -1571,7 +1569,7 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
15711569

15721570
static int
15731571
compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr,
1574-
unsigned int *size, const char *name,
1572+
unsigned int *size,
15751573
struct xt_table_info *newinfo, unsigned char *base)
15761574
{
15771575
struct xt_entry_target *t;
@@ -1654,14 +1652,9 @@ compat_check_entry(struct ipt_entry *e, struct net *net, const char *name)
16541652

16551653
static int
16561654
translate_compat_table(struct net *net,
1657-
const char *name,
1658-
unsigned int valid_hooks,
16591655
struct xt_table_info **pinfo,
16601656
void **pentry0,
1661-
unsigned int total_size,
1662-
unsigned int number,
1663-
unsigned int *hook_entries,
1664-
unsigned int *underflows)
1657+
const struct compat_ipt_replace *compatr)
16651658
{
16661659
unsigned int i, j;
16671660
struct xt_table_info *newinfo, *info;
@@ -1673,8 +1666,8 @@ translate_compat_table(struct net *net,
16731666

16741667
info = *pinfo;
16751668
entry0 = *pentry0;
1676-
size = total_size;
1677-
info->number = number;
1669+
size = compatr->size;
1670+
info->number = compatr->num_entries;
16781671

16791672
/* Init all hooks to impossible value. */
16801673
for (i = 0; i < NF_INET_NUMHOOKS; i++) {
@@ -1685,40 +1678,39 @@ translate_compat_table(struct net *net,
16851678
duprintf("translate_compat_table: size %u\n", info->size);
16861679
j = 0;
16871680
xt_compat_lock(AF_INET);
1688-
xt_compat_init_offsets(AF_INET, number);
1681+
xt_compat_init_offsets(AF_INET, compatr->num_entries);
16891682
/* Walk through entries, checking offsets. */
1690-
xt_entry_foreach(iter0, entry0, total_size) {
1683+
xt_entry_foreach(iter0, entry0, compatr->size) {
16911684
ret = check_compat_entry_size_and_hooks(iter0, info, &size,
16921685
entry0,
1693-
entry0 + total_size,
1694-
hook_entries,
1695-
underflows,
1696-
name);
1686+
entry0 + compatr->size,
1687+
compatr->hook_entry,
1688+
compatr->underflow);
16971689
if (ret != 0)
16981690
goto out_unlock;
16991691
++j;
17001692
}
17011693

17021694
ret = -EINVAL;
1703-
if (j != number) {
1695+
if (j != compatr->num_entries) {
17041696
duprintf("translate_compat_table: %u not %u entries\n",
1705-
j, number);
1697+
j, compatr->num_entries);
17061698
goto out_unlock;
17071699
}
17081700

17091701
/* Check hooks all assigned */
17101702
for (i = 0; i < NF_INET_NUMHOOKS; i++) {
17111703
/* Only hooks which are valid */
1712-
if (!(valid_hooks & (1 << i)))
1704+
if (!(compatr->valid_hooks & (1 << i)))
17131705
continue;
17141706
if (info->hook_entry[i] == 0xFFFFFFFF) {
17151707
duprintf("Invalid hook entry %u %u\n",
1716-
i, hook_entries[i]);
1708+
i, info->hook_entry[i]);
17171709
goto out_unlock;
17181710
}
17191711
if (info->underflow[i] == 0xFFFFFFFF) {
17201712
duprintf("Invalid underflow %u %u\n",
1721-
i, underflows[i]);
1713+
i, info->underflow[i]);
17221714
goto out_unlock;
17231715
}
17241716
}
@@ -1728,17 +1720,17 @@ translate_compat_table(struct net *net,
17281720
if (!newinfo)
17291721
goto out_unlock;
17301722

1731-
newinfo->number = number;
1723+
newinfo->number = compatr->num_entries;
17321724
for (i = 0; i < NF_INET_NUMHOOKS; i++) {
17331725
newinfo->hook_entry[i] = info->hook_entry[i];
17341726
newinfo->underflow[i] = info->underflow[i];
17351727
}
17361728
entry1 = newinfo->entries;
17371729
pos = entry1;
1738-
size = total_size;
1739-
xt_entry_foreach(iter0, entry0, total_size) {
1730+
size = compatr->size;
1731+
xt_entry_foreach(iter0, entry0, compatr->size) {
17401732
ret = compat_copy_entry_from_user(iter0, &pos, &size,
1741-
name, newinfo, entry1);
1733+
newinfo, entry1);
17421734
if (ret != 0)
17431735
break;
17441736
}
@@ -1748,12 +1740,12 @@ translate_compat_table(struct net *net,
17481740
goto free_newinfo;
17491741

17501742
ret = -ELOOP;
1751-
if (!mark_source_chains(newinfo, valid_hooks, entry1))
1743+
if (!mark_source_chains(newinfo, compatr->valid_hooks, entry1))
17521744
goto free_newinfo;
17531745

17541746
i = 0;
17551747
xt_entry_foreach(iter1, entry1, newinfo->size) {
1756-
ret = compat_check_entry(iter1, net, name);
1748+
ret = compat_check_entry(iter1, net, compatr->name);
17571749
if (ret != 0)
17581750
break;
17591751
++i;
@@ -1793,7 +1785,7 @@ translate_compat_table(struct net *net,
17931785
free_newinfo:
17941786
xt_free_table_info(newinfo);
17951787
out:
1796-
xt_entry_foreach(iter0, entry0, total_size) {
1788+
xt_entry_foreach(iter0, entry0, compatr->size) {
17971789
if (j-- == 0)
17981790
break;
17991791
compat_release_entry(iter0);
@@ -1838,10 +1830,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
18381830
goto free_newinfo;
18391831
}
18401832

1841-
ret = translate_compat_table(net, tmp.name, tmp.valid_hooks,
1842-
&newinfo, &loc_cpu_entry, tmp.size,
1843-
tmp.num_entries, tmp.hook_entry,
1844-
tmp.underflow);
1833+
ret = translate_compat_table(net, &newinfo, &loc_cpu_entry, &tmp);
18451834
if (ret != 0)
18461835
goto free_newinfo;
18471836

0 commit comments

Comments
 (0)