netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Pablo Neira Ayuso <pablo@netfilter.org>,
	Sasha Levin <sashal@kernel.org>,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.4 035/187] netfilter: nf_tables: validate NFT_DATA_VALUE after nft_data_init()
Date: Fri, 27 Dec 2019 12:38:23 -0500	[thread overview]
Message-ID: <20191227174055.4923-35-sashal@kernel.org> (raw)
In-Reply-To: <20191227174055.4923-1-sashal@kernel.org>

From: Pablo Neira Ayuso <pablo@netfilter.org>

[ Upstream commit 0d2c96af797ba149e559c5875c0151384ab6dd14 ]

Userspace might bogusly sent NFT_DATA_VERDICT in several netlink
attributes that assume NFT_DATA_VALUE. Moreover, make sure that error
path invokes nft_data_release() to decrement the reference count on the
chain object.

Fixes: 96518518cc41 ("netfilter: add nftables")
Fixes: 0f3cd9b36977 ("netfilter: nf_tables: add range expression")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/netfilter/nf_tables_api.c |  4 +++-
 net/netfilter/nft_bitwise.c   |  4 ++--
 net/netfilter/nft_cmp.c       |  6 ++++++
 net/netfilter/nft_range.c     | 10 ++++++++++
 4 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 7120eba71ac5..4c03c14e46bc 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -4252,8 +4252,10 @@ static int nft_get_set_elem(struct nft_ctx *ctx, struct nft_set *set,
 		return err;
 
 	err = -EINVAL;
-	if (desc.type != NFT_DATA_VALUE || desc.len != set->klen)
+	if (desc.type != NFT_DATA_VALUE || desc.len != set->klen) {
+		nft_data_release(&elem.key.val, desc.type);
 		return err;
+	}
 
 	priv = set->ops->get(ctx->net, set, &elem, flags);
 	if (IS_ERR(priv))
diff --git a/net/netfilter/nft_bitwise.c b/net/netfilter/nft_bitwise.c
index 02afa752dd2e..10e9d50e4e19 100644
--- a/net/netfilter/nft_bitwise.c
+++ b/net/netfilter/nft_bitwise.c
@@ -80,7 +80,7 @@ static int nft_bitwise_init(const struct nft_ctx *ctx,
 			    tb[NFTA_BITWISE_MASK]);
 	if (err < 0)
 		return err;
-	if (d1.len != priv->len) {
+	if (d1.type != NFT_DATA_VALUE || d1.len != priv->len) {
 		err = -EINVAL;
 		goto err1;
 	}
@@ -89,7 +89,7 @@ static int nft_bitwise_init(const struct nft_ctx *ctx,
 			    tb[NFTA_BITWISE_XOR]);
 	if (err < 0)
 		goto err1;
-	if (d2.len != priv->len) {
+	if (d2.type != NFT_DATA_VALUE || d2.len != priv->len) {
 		err = -EINVAL;
 		goto err2;
 	}
diff --git a/net/netfilter/nft_cmp.c b/net/netfilter/nft_cmp.c
index 0744b2bb46da..ae730dba60c8 100644
--- a/net/netfilter/nft_cmp.c
+++ b/net/netfilter/nft_cmp.c
@@ -80,6 +80,12 @@ static int nft_cmp_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
 	if (err < 0)
 		return err;
 
+	if (desc.type != NFT_DATA_VALUE) {
+		err = -EINVAL;
+		nft_data_release(&priv->data, desc.type);
+		return err;
+	}
+
 	priv->sreg = nft_parse_register(tb[NFTA_CMP_SREG]);
 	err = nft_validate_register_load(priv->sreg, desc.len);
 	if (err < 0)
diff --git a/net/netfilter/nft_range.c b/net/netfilter/nft_range.c
index 4701fa8a45e7..89efcc5a533d 100644
--- a/net/netfilter/nft_range.c
+++ b/net/netfilter/nft_range.c
@@ -66,11 +66,21 @@ static int nft_range_init(const struct nft_ctx *ctx, const struct nft_expr *expr
 	if (err < 0)
 		return err;
 
+	if (desc_from.type != NFT_DATA_VALUE) {
+		err = -EINVAL;
+		goto err1;
+	}
+
 	err = nft_data_init(NULL, &priv->data_to, sizeof(priv->data_to),
 			    &desc_to, tb[NFTA_RANGE_TO_DATA]);
 	if (err < 0)
 		goto err1;
 
+	if (desc_to.type != NFT_DATA_VALUE) {
+		err = -EINVAL;
+		goto err2;
+	}
+
 	if (desc_from.len != desc_to.len) {
 		err = -EINVAL;
 		goto err2;
-- 
2.20.1


  parent reply	other threads:[~2019-12-27 17:57 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20191227174055.4923-1-sashal@kernel.org>
2019-12-27 17:37 ` [PATCH AUTOSEL 5.4 008/187] mwifiex: fix possible heap overflow in mwifiex_process_country_ie() Sasha Levin
2020-01-06 22:51   ` Brian Norris
2020-01-09 15:29     ` Sasha Levin
2020-01-09 17:33       ` Brian Norris
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 014/187] netfilter: ctnetlink: netns exit must wait for callbacks Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 017/187] netfilter: nf_tables_offload: Check for the NETDEV_UNREGISTER event Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 018/187] mwifiex: Fix heap overflow in mmwifiex_process_tdls_action_frame() Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 025/187] netfilter: nf_queue: enqueue skbs with NULL dst Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 033/187] netfilter: nft_set_rbtree: bogus lookup/get on consecutive elements in named sets Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 034/187] netfilter: nf_tables: validate NFT_SET_ELEM_INTERVAL_END Sasha Levin
2019-12-27 17:38 ` Sasha Levin [this message]
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 036/187] netfilter: nf_tables: skip module reference count bump on object updates Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 037/187] netfilter: nf_tables_offload: return EOPNOTSUPP if rule specifies no actions Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 038/187] netfilter: bridge: make sure to pull arp header in br_nf_forward_arp() Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 049/187] mlxsw: spectrum_router: Remove unlikely user-triggerable warning Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 050/187] selftests: forwarding: Delete IPv6 address at the end Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 052/187] net: ethernet: ti: davinci_cpdma: fix warning "device driver frees DMA memory with different size" Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 053/187] af_packet: set defaule value for tmo Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 054/187] fjes: fix missed check in fjes_acpi_add Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 055/187] NFC: nxp-nci: Fix probing without ACPI Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 056/187] Revert "iwlwifi: assign directly to iwl_trans->cfg in QuZ detection" Sasha Levin
2019-12-30  5:48   ` Anders Kaseorg
2020-01-05 15:42     ` Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 057/187] iwlwifi: pcie: move power gating workaround earlier in the flow Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 067/187] bnxt_en: Fix MSIX request logic for RDMA driver Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 068/187] bnxt_en: Return error if FW returns more data than dump length Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 069/187] net: ena: fix napi handler misbehavior when the napi budget is zero Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 071/187] bpf, riscv: Limit to 33 tail calls Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 072/187] bpf, mips: " Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 073/187] bpftool: Don't crash on missing jited insns or ksyms Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 080/187] samples: bpf: Replace symbol compare of trace_event Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 081/187] samples: bpf: fix syscall_tp due to unused syscall Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 087/187] net: usb: lan78xx: Fix suspend/resume PHY register access error Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 088/187] qede: Fix multicast mac configuration Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 090/187] mac80211: fix TID field in monitor mode transmit Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 091/187] cfg80211: fix double-free after changing network namespace Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 100/187] bpf: Clear skb->tstamp in bpf_redirect when necessary Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 101/187] bnxt: apply computed clamp value for coalece parameter Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 102/187] ipv6/addrconf: only check invalid header values when NETLINK_F_STRICT_CHK is set Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 103/187] tcp/dccp: fix possible race __inet_lookup_established() Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 104/187] 6pack,mkiss: fix possible deadlock Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 107/187] net: marvell: mvpp2: phylink requires the link interrupt Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 108/187] hv_netvsc: Fix tx_table init in rndis_set_subchannel() Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 109/187] bnx2x: Do not handle requests from VFs after parity Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 110/187] bnx2x: Fix logic to get total no. of PFs per engine Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 111/187] bonding: fix active-backup transition after link failure Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 112/187] gtp: do not allow adding duplicate tid and ms_addr pdp context Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 113/187] gtp: fix wrong condition in gtp_genl_dump_pdp() Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 114/187] gtp: fix an use-after-free in ipv4_pdp_find() Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 115/187] gtp: avoid zero size hashtable Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 116/187] net: phylink: fix interface passed to mac_link_up Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 117/187] net/smc: add fallback check to connect() Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 118/187] cxgb4: Fix kernel panic while accessing sge_info Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 119/187] net: usb: lan78xx: Fix error message format specifier Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 122/187] rfkill: Fix incorrect check to avoid NULL pointer dereference Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 128/187] net: dsa: b53: Fix egress flooding settings Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 129/187] net: gemini: Fix memory leak in gmac_setup_txqs Sasha Levin

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=20191227174055.4923-35-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=coreteam@netfilter.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=stable@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).