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 13/27] xtables: use match, target and data copy_to_user helpers in compat
Date: Fri,  3 Feb 2017 13:25:24 +0100	[thread overview]
Message-ID: <1486124738-3013-14-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1486124738-3013-1-git-send-email-pablo@netfilter.org>

From: Willem de Bruijn <willemb@google.com>

Convert compat to copying entries, matches and targets one by one,
using the xt_match_to_user and xt_target_to_user helper functions.

Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/x_tables.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index feccf527abdd..016db6be94b9 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -619,17 +619,14 @@ int xt_compat_match_to_user(const struct xt_entry_match *m,
 	int off = xt_compat_match_offset(match);
 	u_int16_t msize = m->u.user.match_size - off;
 
-	if (copy_to_user(cm, m, sizeof(*cm)) ||
-	    put_user(msize, &cm->u.user.match_size) ||
-	    copy_to_user(cm->u.user.name, m->u.kernel.match->name,
-			 strlen(m->u.kernel.match->name) + 1))
+	if (XT_OBJ_TO_USER(cm, m, match, msize))
 		return -EFAULT;
 
 	if (match->compat_to_user) {
 		if (match->compat_to_user((void __user *)cm->data, m->data))
 			return -EFAULT;
 	} else {
-		if (copy_to_user(cm->data, m->data, msize - sizeof(*cm)))
+		if (XT_DATA_TO_USER(cm, m, match, msize - sizeof(*cm)))
 			return -EFAULT;
 	}
 
@@ -977,17 +974,14 @@ int xt_compat_target_to_user(const struct xt_entry_target *t,
 	int off = xt_compat_target_offset(target);
 	u_int16_t tsize = t->u.user.target_size - off;
 
-	if (copy_to_user(ct, t, sizeof(*ct)) ||
-	    put_user(tsize, &ct->u.user.target_size) ||
-	    copy_to_user(ct->u.user.name, t->u.kernel.target->name,
-			 strlen(t->u.kernel.target->name) + 1))
+	if (XT_OBJ_TO_USER(ct, t, target, tsize))
 		return -EFAULT;
 
 	if (target->compat_to_user) {
 		if (target->compat_to_user((void __user *)ct->data, t->data))
 			return -EFAULT;
 	} else {
-		if (copy_to_user(ct->data, t->data, tsize - sizeof(*ct)))
+		if (XT_DATA_TO_USER(ct, t, target, tsize - sizeof(*ct)))
 			return -EFAULT;
 	}
 
-- 
2.1.4


  parent reply	other threads:[~2017-02-03 12:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-03 12:25 [PATCH 00/27] Netfilter updates for net-next Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 01/27] netfilter: merge udp and udplite conntrack helpers Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 02/27] netfilter: nat: merge udp and udplite helpers Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 03/27] netfilter: nf_tables: add missing descriptions in nft_ct_keys Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 04/27] netfilter: nft_ct: add average bytes per packet support Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 05/27] netfilter: select LIBCRC32C together with SCTP conntrack Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 06/27] netfilter: conntrack: validate SCTP crc32c in PREROUTING Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 07/27] netfilter: xt_connlimit: use rb_entry() Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 08/27] xtables: add xt_match, xt_target and data copy_to_user functions Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 09/27] iptables: use match, target and data copy_to_user helpers Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 10/27] ip6tables: " Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 11/27] arptables: " Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 12/27] ebtables: " Pablo Neira Ayuso
2017-02-03 12:25 ` Pablo Neira Ayuso [this message]
2017-02-03 12:25 ` [PATCH 14/27] xtables: extend matches and targets with .usersize Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 15/27] netfilter: pkttype: unnecessary to check ipv6 multicast address Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 16/27] netfilter: nft_meta: deal with PACKET_LOOPBACK in netdev family Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 17/27] netfilter: nf_tables: eliminate useless condition checks Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 18/27] netfilter: nf_tables: Eliminate duplicated code in nf_tables_table_enable() Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 19/27] netfilter: conntrack: no need to pass ctinfo to error handler Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 20/27] netfilter: reset netfilter state when duplicating packet Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 21/27] netfilter: reduce direct skb->nfct usage Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 22/27] skbuff: add and use skb_nfct helper Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 23/27] netfilter: add and use nf_ct_set helper Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 24/27] netfilter: guarantee 8 byte minalign for template addresses Pablo Neira Ayuso
2017-02-06 10:08   ` David Laight
2017-02-03 12:25 ` [PATCH 25/27] netfilter: merge ctinfo into nfct pointer storage area Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 26/27] ipvs: free ip_vs_dest structs when refcnt=0 Pablo Neira Ayuso
2017-02-03 12:25 ` [PATCH 27/27] netfilter: allow logging from non-init namespaces Pablo Neira Ayuso
2017-02-03 22:08 ` [PATCH 00/27] 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=1486124738-3013-14-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).