netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 10/23] netfilter: ip_tables: simplify translate_compat_table args
Date: Fri, 22 Apr 2016 15:39:41 +0200	[thread overview]
Message-ID: <1461332394-3994-11-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1461332394-3994-1-git-send-email-pablo@netfilter.org>

From: Florian Westphal <fw@strlen.de>

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/ipv4/netfilter/ip_tables.c | 59 +++++++++++++++++-------------------------
 1 file changed, 24 insertions(+), 35 deletions(-)

diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index baab033d..d7041860 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -1449,7 +1449,6 @@ compat_copy_entry_to_user(struct ipt_entry *e, void __user **dstptr,
 
 static int
 compat_find_calc_match(struct xt_entry_match *m,
-		       const char *name,
 		       const struct ipt_ip *ip,
 		       int *size)
 {
@@ -1486,8 +1485,7 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
 				  const unsigned char *base,
 				  const unsigned char *limit,
 				  const unsigned int *hook_entries,
-				  const unsigned int *underflows,
-				  const char *name)
+				  const unsigned int *underflows)
 {
 	struct xt_entry_match *ematch;
 	struct xt_entry_target *t;
@@ -1523,7 +1521,7 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
 	entry_offset = (void *)e - (void *)base;
 	j = 0;
 	xt_ematch_foreach(ematch, e) {
-		ret = compat_find_calc_match(ematch, name, &e->ip, &off);
+		ret = compat_find_calc_match(ematch, &e->ip, &off);
 		if (ret != 0)
 			goto release_matches;
 		++j;
@@ -1572,7 +1570,7 @@ release_matches:
 
 static int
 compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr,
-			    unsigned int *size, const char *name,
+			    unsigned int *size,
 			    struct xt_table_info *newinfo, unsigned char *base)
 {
 	struct xt_entry_target *t;
@@ -1655,14 +1653,9 @@ compat_check_entry(struct ipt_entry *e, struct net *net, const char *name)
 
 static int
 translate_compat_table(struct net *net,
-		       const char *name,
-		       unsigned int valid_hooks,
 		       struct xt_table_info **pinfo,
 		       void **pentry0,
-		       unsigned int total_size,
-		       unsigned int number,
-		       unsigned int *hook_entries,
-		       unsigned int *underflows)
+		       const struct compat_ipt_replace *compatr)
 {
 	unsigned int i, j;
 	struct xt_table_info *newinfo, *info;
@@ -1674,8 +1667,8 @@ translate_compat_table(struct net *net,
 
 	info = *pinfo;
 	entry0 = *pentry0;
-	size = total_size;
-	info->number = number;
+	size = compatr->size;
+	info->number = compatr->num_entries;
 
 	/* Init all hooks to impossible value. */
 	for (i = 0; i < NF_INET_NUMHOOKS; i++) {
@@ -1686,40 +1679,39 @@ translate_compat_table(struct net *net,
 	duprintf("translate_compat_table: size %u\n", info->size);
 	j = 0;
 	xt_compat_lock(AF_INET);
-	xt_compat_init_offsets(AF_INET, number);
+	xt_compat_init_offsets(AF_INET, compatr->num_entries);
 	/* 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,
 							entry0,
-							entry0 + total_size,
-							hook_entries,
-							underflows,
-							name);
+							entry0 + compatr->size,
+							compatr->hook_entry,
+							compatr->underflow);
 		if (ret != 0)
 			goto out_unlock;
 		++j;
 	}
 
 	ret = -EINVAL;
-	if (j != number) {
+	if (j != compatr->num_entries) {
 		duprintf("translate_compat_table: %u not %u entries\n",
-			 j, number);
+			 j, compatr->num_entries);
 		goto out_unlock;
 	}
 
 	/* Check hooks all assigned */
 	for (i = 0; i < NF_INET_NUMHOOKS; i++) {
 		/* Only hooks which are valid */
-		if (!(valid_hooks & (1 << i)))
+		if (!(compatr->valid_hooks & (1 << i)))
 			continue;
 		if (info->hook_entry[i] == 0xFFFFFFFF) {
 			duprintf("Invalid hook entry %u %u\n",
-				 i, hook_entries[i]);
+				 i, info->hook_entry[i]);
 			goto out_unlock;
 		}
 		if (info->underflow[i] == 0xFFFFFFFF) {
 			duprintf("Invalid underflow %u %u\n",
-				 i, underflows[i]);
+				 i, info->underflow[i]);
 			goto out_unlock;
 		}
 	}
@@ -1729,17 +1721,17 @@ translate_compat_table(struct net *net,
 	if (!newinfo)
 		goto out_unlock;
 
-	newinfo->number = number;
+	newinfo->number = compatr->num_entries;
 	for (i = 0; i < NF_INET_NUMHOOKS; i++) {
 		newinfo->hook_entry[i] = info->hook_entry[i];
 		newinfo->underflow[i] = info->underflow[i];
 	}
 	entry1 = newinfo->entries;
 	pos = entry1;
-	size = total_size;
-	xt_entry_foreach(iter0, entry0, total_size) {
+	size = compatr->size;
+	xt_entry_foreach(iter0, entry0, compatr->size) {
 		ret = compat_copy_entry_from_user(iter0, &pos, &size,
-						  name, newinfo, entry1);
+						  newinfo, entry1);
 		if (ret != 0)
 			break;
 	}
@@ -1749,12 +1741,12 @@ translate_compat_table(struct net *net,
 		goto free_newinfo;
 
 	ret = -ELOOP;
-	if (!mark_source_chains(newinfo, valid_hooks, entry1))
+	if (!mark_source_chains(newinfo, compatr->valid_hooks, entry1))
 		goto free_newinfo;
 
 	i = 0;
 	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)
 			break;
 		++i;
@@ -1794,7 +1786,7 @@ translate_compat_table(struct net *net,
 free_newinfo:
 	xt_free_table_info(newinfo);
 out:
-	xt_entry_foreach(iter0, entry0, total_size) {
+	xt_entry_foreach(iter0, entry0, compatr->size) {
 		if (j-- == 0)
 			break;
 		compat_release_entry(iter0);
@@ -1839,10 +1831,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
 		goto free_newinfo;
 	}
 
-	ret = translate_compat_table(net, tmp.name, tmp.valid_hooks,
-				     &newinfo, &loc_cpu_entry, tmp.size,
-				     tmp.num_entries, tmp.hook_entry,
-				     tmp.underflow);
+	ret = translate_compat_table(net, &newinfo, &loc_cpu_entry, &tmp);
 	if (ret != 0)
 		goto free_newinfo;
 
-- 
2.1.4

  parent reply	other threads:[~2016-04-22 13:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-22 13:39 [PATCH 00/23] Netfilter updates for net-next Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 01/23] netfilter: x_tables: don't move to non-existent next rule Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 02/23] netfilter: x_tables: validate targets of jumps Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 03/23] netfilter: x_tables: add and use xt_check_entry_offsets Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 04/23] netfilter: x_tables: kill check_entry helper Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 05/23] netfilter: x_tables: assert minimum target size Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 06/23] netfilter: x_tables: add compat version of xt_check_entry_offsets Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 07/23] netfilter: x_tables: check standard target size too Pablo Neira Ayuso
2016-06-05 21:11   ` Andreas Schwab
2016-06-05 22:02     ` Florian Westphal
2016-06-06 11:20       ` Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 08/23] netfilter: x_tables: check for bogus target offset Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 09/23] netfilter: x_tables: validate all offsets and sizes in a rule Pablo Neira Ayuso
2016-04-22 13:39 ` Pablo Neira Ayuso [this message]
2016-04-22 13:39 ` [PATCH 11/23] netfilter: ip6_tables: simplify translate_compat_table args Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 12/23] netfilter: arp_tables: " Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 13/23] netfilter: x_tables: xt_compat_match_from_user doesn't need a retval Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 14/23] netfilter: x_tables: do compat validation via translate_table Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 15/23] netfilter: x_tables: remove obsolete overflow check for compat case too Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 16/23] netfilter: x_tables: remove obsolete check Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 17/23] netfilter: x_tables: introduce and use xt_copy_counters_from_user Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 18/23] netfilter: ctnetlink: remove unnecessary inlining Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 19/23] netfilter: connlabels: move helpers to xt_connlabel Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 20/23] netfilter: labels: don't emit ct event if labels were not changed Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 21/23] netfilter: connlabels: change nf_connlabels_get bit arg to 'highest used' Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 22/23] netfilter: ctnetlink: restore inlining for netlink message size calculation Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 23/23] netfilter: conntrack: don't acquire lock during seq_printf Pablo Neira Ayuso
2016-04-24  4:26 ` [PATCH 00/23] Netfilter updates for net-next David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1461332394-3994-11-git-send-email-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).