All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Florian Westphal <fw@strlen.de>,
	syzbot+91bdd8eece0f6629ec8b@syzkaller.appspotmail.com,
	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 4.14 15/32] netfilter: arp_tables: init netns pointer in xt_tgdtor_param struct
Date: Fri, 24 Jan 2020 09:21:02 -0500	[thread overview]
Message-ID: <20200124142119.30484-15-sashal@kernel.org> (raw)
In-Reply-To: <20200124142119.30484-1-sashal@kernel.org>

From: Florian Westphal <fw@strlen.de>

[ Upstream commit 212e7f56605ef9688d0846db60c6c6ec06544095 ]

An earlier commit (1b789577f655060d98d20e,
"netfilter: arp_tables: init netns pointer in xt_tgchk_param struct")
fixed missing net initialization for arptables, but turns out it was
incomplete.  We can get a very similar struct net NULL deref during
error unwinding:

general protection fault: 0000 [#1] PREEMPT SMP KASAN
RIP: 0010:xt_rateest_put+0xa1/0x440 net/netfilter/xt_RATEEST.c:77
 xt_rateest_tg_destroy+0x72/0xa0 net/netfilter/xt_RATEEST.c:175
 cleanup_entry net/ipv4/netfilter/arp_tables.c:509 [inline]
 translate_table+0x11f4/0x1d80 net/ipv4/netfilter/arp_tables.c:587
 do_replace net/ipv4/netfilter/arp_tables.c:981 [inline]
 do_arpt_set_ctl+0x317/0x650 net/ipv4/netfilter/arp_tables.c:1461

Also init the netns pointer in xt_tgdtor_param struct.

Fixes: add67461240c1d ("netfilter: add struct net * to target parameters")
Reported-by: syzbot+91bdd8eece0f6629ec8b@syzkaller.appspotmail.com
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/ipv4/netfilter/arp_tables.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index e288489ae3d56..6dd727e0a72f6 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -506,12 +506,13 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e,
 	return 0;
 }
 
-static inline void cleanup_entry(struct arpt_entry *e)
+static void cleanup_entry(struct arpt_entry *e, struct net *net)
 {
 	struct xt_tgdtor_param par;
 	struct xt_entry_target *t;
 
 	t = arpt_get_target(e);
+	par.net      = net;
 	par.target   = t->u.kernel.target;
 	par.targinfo = t->data;
 	par.family   = NFPROTO_ARP;
@@ -601,7 +602,7 @@ static int translate_table(struct net *net,
 		xt_entry_foreach(iter, entry0, newinfo->size) {
 			if (i-- == 0)
 				break;
-			cleanup_entry(iter);
+			cleanup_entry(iter, net);
 		}
 		return ret;
 	}
@@ -926,7 +927,7 @@ static int __do_replace(struct net *net, const char *name,
 	/* Decrease module usage counts and free resource */
 	loc_cpu_old_entry = oldinfo->entries;
 	xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size)
-		cleanup_entry(iter);
+		cleanup_entry(iter, net);
 
 	xt_free_table_info(oldinfo);
 	if (copy_to_user(counters_ptr, counters,
@@ -990,7 +991,7 @@ static int do_replace(struct net *net, const void __user *user,
 
  free_newinfo_untrans:
 	xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
-		cleanup_entry(iter);
+		cleanup_entry(iter, net);
  free_newinfo:
 	xt_free_table_info(newinfo);
 	return ret;
@@ -1287,7 +1288,7 @@ static int compat_do_replace(struct net *net, void __user *user,
 
  free_newinfo_untrans:
 	xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
-		cleanup_entry(iter);
+		cleanup_entry(iter, net);
  free_newinfo:
 	xt_free_table_info(newinfo);
 	return ret;
@@ -1514,7 +1515,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
 	return ret;
 }
 
-static void __arpt_unregister_table(struct xt_table *table)
+static void __arpt_unregister_table(struct net *net, struct xt_table *table)
 {
 	struct xt_table_info *private;
 	void *loc_cpu_entry;
@@ -1526,7 +1527,7 @@ static void __arpt_unregister_table(struct xt_table *table)
 	/* Decrease module usage counts and free resources */
 	loc_cpu_entry = private->entries;
 	xt_entry_foreach(iter, loc_cpu_entry, private->size)
-		cleanup_entry(iter);
+		cleanup_entry(iter, net);
 	if (private->number > private->initial_entries)
 		module_put(table_owner);
 	xt_free_table_info(private);
@@ -1566,7 +1567,7 @@ int arpt_register_table(struct net *net,
 
 	ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
 	if (ret != 0) {
-		__arpt_unregister_table(new_table);
+		__arpt_unregister_table(net, new_table);
 		*res = NULL;
 	}
 
@@ -1581,7 +1582,7 @@ void arpt_unregister_table(struct net *net, struct xt_table *table,
 			   const struct nf_hook_ops *ops)
 {
 	nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
-	__arpt_unregister_table(table);
+	__arpt_unregister_table(net, table);
 }
 
 /* The built-in targets: standard (NULL) and error. */
-- 
2.20.1


  parent reply	other threads:[~2020-01-24 14:21 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-24 14:20 [PATCH AUTOSEL 4.14 01/32] batman-adv: Fix DAT candidate selection on little endian systems Sasha Levin
2020-01-24 14:20 ` [PATCH AUTOSEL 4.14 02/32] dt-bindings: reset: meson8b: fix duplicate reset IDs Sasha Levin
2020-01-24 14:20   ` Sasha Levin
2020-01-24 14:20 ` [PATCH AUTOSEL 4.14 03/32] ARM: dts: sun8i: a83t: Correct USB3503 GPIOs polarity Sasha Levin
2020-01-24 14:20   ` Sasha Levin
2020-01-24 14:20 ` [PATCH AUTOSEL 4.14 04/32] ARM: dts: beagle-x15-common: Model 5V0 regulator Sasha Levin
2020-01-24 14:20   ` Sasha Levin
2020-01-24 14:20   ` Sasha Levin
2020-01-24 14:20 ` [PATCH AUTOSEL 4.14 05/32] soc: ti: wkup_m3_ipc: Fix race condition with rproc_boot Sasha Levin
2020-01-24 14:20   ` Sasha Levin
2020-01-24 14:20 ` [PATCH AUTOSEL 4.14 06/32] clk: Don't try to enable critical clocks if prepare failed Sasha Levin
2020-01-24 14:20 ` [PATCH AUTOSEL 4.14 07/32] mac80211: mesh: restrict airtime metric to peered established plinks Sasha Levin
2020-01-24 14:20 ` [PATCH AUTOSEL 4.14 08/32] clk: mmp2: Fix the order of timer mux parents Sasha Levin
2020-01-24 14:20 ` [PATCH AUTOSEL 4.14 09/32] ixgbevf: Remove limit of 10 entries for unicast filter list Sasha Levin
2020-01-24 14:20   ` [Intel-wired-lan] " Sasha Levin
2020-01-24 14:20 ` [PATCH AUTOSEL 4.14 10/32] ixgbe: Fix calculation of queue with VFs and flow director on interface flap Sasha Levin
2020-01-24 14:20   ` [Intel-wired-lan] " Sasha Levin
2020-01-24 14:20 ` [PATCH AUTOSEL 4.14 11/32] igb: Fix SGMII SFP module discovery for 100FX/LX Sasha Levin
2020-01-24 14:20   ` [Intel-wired-lan] " Sasha Levin
2020-01-24 14:20 ` [PATCH AUTOSEL 4.14 12/32] ASoC: msm8916-wcd-analog: Fix selected events for MIC BIAS External1 Sasha Levin
2020-01-24 14:20   ` [alsa-devel] " Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 13/32] ASoC: sti: fix possible sleep-in-atomic Sasha Levin
2020-01-24 14:21   ` [alsa-devel] " Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 14/32] netfilter: fix a use-after-free in mtype_destroy() Sasha Levin
2020-01-24 14:21 ` Sasha Levin [this message]
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 16/32] qmi_wwan: Add support for Quectel RM500Q Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 17/32] NFC: pn533: fix bulk-message timeout Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 18/32] ptp: free ptp device pin descriptors properly Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 19/32] net: usb: lan78xx: limit size of local TSO packets Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 20/32] r8152: add missing endpoint sanity check Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 21/32] wireless: fix enabling channel 12 for custom regulatory domain Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 22/32] cfg80211: Fix radar event during another phy CAC Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 23/32] mac80211: Fix TKIP replay protection immediately after key setup Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 24/32] wireless: wext: avoid gcc -O3 warning Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 25/32] cfg80211: check for set_wiphy_params Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 26/32] tick/sched: Annotate lockless access to last_jiffies_update Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 27/32] hv_netvsc: Fix memory leak when removing rndis device Sasha Levin
2020-01-24 14:21   ` Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 28/32] net/wan/fsl_ucc_hdlc: fix out of bounds write on array utdm_info Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 29/32] scsi: mptfusion: Fix double fetch bug in ioctl Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 30/32] net: hns: fix soft lockup when there is not enough memory Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 31/32] net: dsa: bcm_sf2: Configure IMP port for 2Gb/sec Sasha Levin
2020-01-24 14:21 ` [PATCH AUTOSEL 4.14 32/32] bnxt_en: Fix ipv6 RFS filter matching logic 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=20200124142119.30484-15-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=coreteam@netfilter.org \
    --cc=fw@strlen.de \
    --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 \
    --cc=syzbot+91bdd8eece0f6629ec8b@syzkaller.appspotmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.