netdev.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 09/13] netfilter: nft_range: validate operation netlink attribute
Date: Fri, 21 Oct 2016 12:12:19 +0200	[thread overview]
Message-ID: <1477044743-18948-10-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1477044743-18948-1-git-send-email-pablo@netfilter.org>

Use nft_parse_u32_check() to make sure we don't get a value over the
unsigned 8-bit integer. Moreover, make sure this value doesn't go over
the two supported range comparison modes.

Fixes: 9286c2eb1fda ("netfilter: nft_range: validate operation netlink attribute")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_range.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nft_range.c b/net/netfilter/nft_range.c
index c6d5358482d1..9bc4586c3006 100644
--- a/net/netfilter/nft_range.c
+++ b/net/netfilter/nft_range.c
@@ -59,6 +59,7 @@ static int nft_range_init(const struct nft_ctx *ctx, const struct nft_expr *expr
 	struct nft_range_expr *priv = nft_expr_priv(expr);
 	struct nft_data_desc desc_from, desc_to;
 	int err;
+	u32 op;
 
 	err = nft_data_init(NULL, &priv->data_from, sizeof(priv->data_from),
 			    &desc_from, tb[NFTA_RANGE_FROM_DATA]);
@@ -80,7 +81,20 @@ static int nft_range_init(const struct nft_ctx *ctx, const struct nft_expr *expr
 	if (err < 0)
 		goto err2;
 
-	priv->op  = ntohl(nla_get_be32(tb[NFTA_RANGE_OP]));
+	err = nft_parse_u32_check(tb[NFTA_RANGE_OP], U8_MAX, &op);
+	if (err < 0)
+		goto err2;
+
+	switch (op) {
+	case NFT_RANGE_EQ:
+	case NFT_RANGE_NEQ:
+		break;
+	default:
+		err = -EINVAL;
+		goto err2;
+	}
+
+	priv->op  = op;
 	priv->len = desc_from.len;
 	return 0;
 err2:
-- 
2.1.4


  parent reply	other threads:[~2016-10-21 10:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-21 10:12 [PATCH 00/13] Netfilter fixes for net Pablo Neira Ayuso
2016-10-21 10:12 ` [PATCH 01/13] netfilter: xt_hashlimit: Add missing ULL suffixes for 64-bit constants Pablo Neira Ayuso
2016-10-21 10:12 ` [PATCH 02/13] netfilter: nft_dynset: fix element timeout for HZ != 1000 Pablo Neira Ayuso
2016-10-21 10:12 ` [PATCH 03/13] netfilter: conntrack: remove obsolete sysctl (nf_conntrack_events_retry_timeout) Pablo Neira Ayuso
2016-10-21 10:12 ` [PATCH 04/13] netfilter: xt_NFLOG: fix unexpected truncated packet Pablo Neira Ayuso
2016-10-21 10:12 ` [PATCH 05/13] netfilter: xt_ipcomp: add "ip[6]t_ipcomp" module alias name Pablo Neira Ayuso
2016-10-21 10:12 ` [PATCH 06/13] netfilter: nft_hash: add missing NFTA_HASH_OFFSET's nla_policy Pablo Neira Ayuso
2016-10-21 10:12 ` [PATCH 07/13] netfilter: nf_tables: underflow in nft_parse_u32_check() Pablo Neira Ayuso
2016-10-21 10:12 ` [PATCH 08/13] netfilter: nft_exthdr: fix error handling in nft_exthdr_init() Pablo Neira Ayuso
2016-10-21 10:12 ` Pablo Neira Ayuso [this message]
2016-10-21 10:12 ` [PATCH 10/13] netfilter: nf_tables: avoid uninitialized variable warning Pablo Neira Ayuso
2016-10-21 10:12 ` [PATCH 11/13] netfilter: x_tables: suppress kmemcheck warning Pablo Neira Ayuso
2016-10-21 10:12 ` [PATCH 12/13] netfilter: conntrack: restart gc immediately if GC_MAX_EVICTS is reached Pablo Neira Ayuso
2016-10-21 10:12 ` [PATCH 13/13] netfilter: fix nf_queue handling Pablo Neira Ayuso
2016-10-21 14:25 ` [PATCH 00/13] Netfilter fixes for net 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=1477044743-18948-10-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).