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 14/14] netfilter: nf_tables: fix oops when inserting an element into a verdict map
Date: Thu, 10 Nov 2016 01:23:47 +0100	[thread overview]
Message-ID: <1478737427-1574-15-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1478737427-1574-1-git-send-email-pablo@netfilter.org>

From: Liping Zhang <zlpnobody@gmail.com>

Dalegaard says:
 The following ruleset, when loaded with 'nft -f bad.txt'
 ----snip----
 flush ruleset
 table ip inlinenat {
   map sourcemap {
     type ipv4_addr : verdict;
   }

   chain postrouting {
     ip saddr vmap @sourcemap accept
   }
 }
 add chain inlinenat test
 add element inlinenat sourcemap { 100.123.10.2 : jump test }
 ----snip----

 results in a kernel oops:
 BUG: unable to handle kernel paging request at 0000000000001344
 IP: [<ffffffffa07bf704>] nf_tables_check_loops+0x114/0x1f0 [nf_tables]
 [...]
 Call Trace:
  [<ffffffffa07c2aae>] ? nft_data_init+0x13e/0x1a0 [nf_tables]
  [<ffffffffa07c1950>] nft_validate_register_store+0x60/0xb0 [nf_tables]
  [<ffffffffa07c74b5>] nft_add_set_elem+0x545/0x5e0 [nf_tables]
  [<ffffffffa07bfdd0>] ? nft_table_lookup+0x30/0x60 [nf_tables]
  [<ffffffff8132c630>] ? nla_strcmp+0x40/0x50
  [<ffffffffa07c766e>] nf_tables_newsetelem+0x11e/0x210 [nf_tables]
  [<ffffffff8132c400>] ? nla_validate+0x60/0x80
  [<ffffffffa030d9b4>] nfnetlink_rcv+0x354/0x5a7 [nfnetlink]

Because we forget to fill the net pointer in bind_ctx, so dereferencing
it may cause kernel crash.

Reported-by: Dalegaard <dalegaard@gmail.com>
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_tables_api.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 7d6a626b08f1..026581b04ea8 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -3568,6 +3568,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
 		dreg = nft_type_to_reg(set->dtype);
 		list_for_each_entry(binding, &set->bindings, list) {
 			struct nft_ctx bind_ctx = {
+				.net	= ctx->net,
 				.afi	= ctx->afi,
 				.table	= ctx->table,
 				.chain	= (struct nft_chain *)binding->chain,
-- 
2.1.4

  parent reply	other threads:[~2016-11-10  0:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-10  0:23 [PATCH 00/14] Netfilter fixes for net Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 01/14] netfilter: nft_dynset: fix panic if NFT_SET_HASH is not enabled Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 02/14] netfilter: nf_tables: fix *leak* when expr clone fail Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 03/14] netfilter: nf_tables: fix race when create new element in dynset Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 04/14] netfilter: nf_conntrack_sip: extend request line validation Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 05/14] netfilter: nf_tables: fix type mismatch with error return from nft_parse_u32_check Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 06/14] netfilter: conntrack: avoid excess memory allocation Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 07/14] netfilter: ip_vs_sync: fix bogus maybe-uninitialized warning Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 08/14] netfilter: nf_tables: destroy the set if fail to add transaction Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 09/14] netfilter: nft_dup: do not use sreg_dev if the user doesn't specify it Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 10/14] ipvs: use IPVS_CMD_ATTR_MAX for family.maxattr Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 11/14] netfilter: connmark: ignore skbs with magic untracked conntrack objects Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 12/14] netfilter: conntrack: fix CT target for UNSPEC helpers Pablo Neira Ayuso
2016-11-10  0:23 ` [PATCH 13/14] netfilter: conntrack: refine gc worker heuristics Pablo Neira Ayuso
2016-11-10  0:23 ` Pablo Neira Ayuso [this message]
2016-11-10  1:38 ` [PATCH 00/14] 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=1478737427-1574-15-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).