netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 03/14] netfilter: nft_lookup: use nft_validate_register_store() to validate types
Date: Sat, 11 Apr 2015 02:27:28 +0100	[thread overview]
Message-ID: <1428715659-31358-4-git-send-email-kaber@trash.net> (raw)
In-Reply-To: <1428715659-31358-1-git-send-email-kaber@trash.net>

In preparation of validating the length of a register store, use
nft_validate_register_store() in nft_lookup instead of open coding the
validation.

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/netfilter/nf_tables_api.c | 7 ++++---
 net/netfilter/nft_lookup.c    | 9 ++++-----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index a1e4a92..c96070e 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -4169,7 +4169,7 @@ EXPORT_SYMBOL_GPL(nft_validate_output_register);
  * 	Validate that a data load uses the appropriate data type for
  * 	the destination register and the length is within the bounds.
  * 	A value of NULL for the data means that its runtime gathered
- * 	data, which is always of type NFT_DATA_VALUE.
+ * 	data.
  */
 int nft_validate_register_store(const struct nft_ctx *ctx,
 				enum nft_registers reg,
@@ -4180,10 +4180,11 @@ int nft_validate_register_store(const struct nft_ctx *ctx,
 
 	switch (reg) {
 	case NFT_REG_VERDICT:
-		if (data == NULL || type != NFT_DATA_VERDICT)
+		if (type != NFT_DATA_VERDICT)
 			return -EINVAL;
 
-		if (data->verdict == NFT_GOTO || data->verdict == NFT_JUMP) {
+		if (data != NULL &&
+		    (data->verdict == NFT_GOTO || data->verdict == NFT_JUMP)) {
 			err = nf_tables_check_loops(ctx, data->chain);
 			if (err < 0)
 				return err;
diff --git a/net/netfilter/nft_lookup.c b/net/netfilter/nft_lookup.c
index d8cf86f..3e4d8ef 100644
--- a/net/netfilter/nft_lookup.c
+++ b/net/netfilter/nft_lookup.c
@@ -84,11 +84,10 @@ static int nft_lookup_init(const struct nft_ctx *ctx,
 		if (err < 0)
 			return err;
 
-		if (priv->dreg == NFT_REG_VERDICT) {
-			if (set->dtype != NFT_DATA_VERDICT)
-				return -EINVAL;
-		} else if (set->dtype == NFT_DATA_VERDICT)
-			return -EINVAL;
+		err = nft_validate_register_store(ctx, priv->dreg, NULL,
+						  set->dtype, set->dlen);
+		if (err < 0)
+			return err;
 	} else if (set->flags & NFT_SET_MAP)
 		return -EINVAL;
 
-- 
2.1.0


  parent reply	other threads:[~2015-04-11  1:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-11  1:27 [PATCH 00/14] netfilter: nf_tables: concatenation support Patrick McHardy
2015-04-11  1:27 ` [PATCH 01/14] netfilter: nf_tables: validate len in nft_validate_data_load() Patrick McHardy
2015-04-11  1:27 ` [PATCH 02/14] netfilter: nf_tables: rename nft_validate_data_load() Patrick McHardy
2015-04-11  1:27 ` Patrick McHardy [this message]
2015-04-11  1:27 ` [PATCH 04/14] netfilter: nf_tables: kill nft_validate_output_register() Patrick McHardy
2015-04-11  1:27 ` [PATCH 05/14] netfilter: nf_tables: introduce nft_validate_register_load() Patrick McHardy
2015-04-11  1:27 ` [PATCH 06/14] netfilter: nf_tables: get rid of NFT_REG_VERDICT usage Patrick McHardy
2015-04-11  1:27 ` [PATCH 07/14] netfilter: nf_tables: use struct nft_verdict within struct nft_data Patrick McHardy
2015-04-11  1:27 ` [PATCH 08/14] netfilter: nf_tables: convert expressions to u32 register pointers Patrick McHardy
2015-04-11  1:27 ` [PATCH 09/14] netfilter: nf_tables: kill nft_data_cmp() Patrick McHardy
2015-04-11  1:27 ` [PATCH 10/14] netfilter: nf_tables: convert sets to u32 data pointers Patrick McHardy
2015-04-11  1:27 ` [PATCH 11/14] netfilter: nf_tables: add register parsing/dumping helpers Patrick McHardy
2015-04-11  1:27 ` [PATCH 12/14] netfilter: nf_tables: switch registers to 32 bit addressing Patrick McHardy
2015-04-11  1:27 ` [PATCH 13/14] netfilter: nf_tables: support variable sized data in nft_data_init() Patrick McHardy
2015-04-11  1:27 ` [PATCH 14/14] netfilter: nf_tables: variable sized set element keys / data Patrick McHardy
2015-04-11 13:47 ` [PATCH 00/14] netfilter: nf_tables: concatenation support Pablo Neira Ayuso
2015-04-11 13:47   ` Patrick McHardy
2015-04-13 18:07 ` Pablo Neira Ayuso

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=1428715659-31358-4-git-send-email-kaber@trash.net \
    --to=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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).