Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1572639

[PATCH 4.9 31/51] lwtunnel: Fix oops on state free after encap module unload

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 4.9 31/51] lwtunnel: Fix oops on state free after encap module unload
Date 2017-02-02 19:50 +0100
Message-ID <t6uCe-7FA-23@gated-at.bofh.it> (permalink)
References <t6usx-7Bs-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


4.9-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Robert Shearman <rshearma@brocade.com>


[ Upstream commit 85c814016ce3b371016c2c054a905fa2492f5a65 ]

When attempting to free lwtunnel state after the module for the encap
has been unloaded an oops occurs:

BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
IP: lwtstate_free+0x18/0x40
[..]
task: ffff88003e372380 task.stack: ffffc900001fc000
RIP: 0010:lwtstate_free+0x18/0x40
RSP: 0018:ffff88003fd83e88 EFLAGS: 00010246
RAX: 0000000000000000 RBX: ffff88002bbb3380 RCX: ffff88000c91a300
[..]
Call Trace:
 <IRQ>
 free_fib_info_rcu+0x195/0x1a0
 ? rt_fibinfo_free+0x50/0x50
 rcu_process_callbacks+0x2d3/0x850
 ? rcu_process_callbacks+0x296/0x850
 __do_softirq+0xe4/0x4cb
 irq_exit+0xb0/0xc0
 smp_apic_timer_interrupt+0x3d/0x50
 apic_timer_interrupt+0x93/0xa0
[..]
Code: e8 6e c6 fc ff 89 d8 5b 5d c3 bb de ff ff ff eb f4 66 90 66 66 66 66 90 55 48 89 e5 53 0f b7 07 48 89 fb 48 8b 04 c5 00 81 d5 81 <48> 8b 40 08 48 85 c0 74 13 ff d0 48 8d 7b 20 be 20 00 00 00 e8

The problem is after the module for the encap can be unloaded the
corresponding ops is removed and is thus NULL here.

Modules implementing lwtunnel ops should not be allowed to unload
while there is state alive using those ops, so grab the module
reference for the ops on creating lwtunnel state and of course release
the reference when freeing the state.

Fixes: 1104d9ba443a ("lwtunnel: Add destroy state operation")
Signed-off-by: Robert Shearman <rshearma@brocade.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 include/net/lwtunnel.h |    5 +----
 net/core/lwtunnel.c    |   14 +++++++++++++-
 2 files changed, 14 insertions(+), 5 deletions(-)

--- a/include/net/lwtunnel.h
+++ b/include/net/lwtunnel.h
@@ -48,10 +48,7 @@ struct lwtunnel_encap_ops {
 };
 
 #ifdef CONFIG_LWTUNNEL
-static inline void lwtstate_free(struct lwtunnel_state *lws)
-{
-	kfree(lws);
-}
+void lwtstate_free(struct lwtunnel_state *lws);
 
 static inline struct lwtunnel_state *
 lwtstate_get(struct lwtunnel_state *lws)
--- a/net/core/lwtunnel.c
+++ b/net/core/lwtunnel.c
@@ -66,6 +66,15 @@ EXPORT_SYMBOL(lwtunnel_state_alloc);
 static const struct lwtunnel_encap_ops __rcu *
 		lwtun_encaps[LWTUNNEL_ENCAP_MAX + 1] __read_mostly;
 
+void lwtstate_free(struct lwtunnel_state *lws)
+{
+	const struct lwtunnel_encap_ops *ops = lwtun_encaps[lws->type];
+
+	kfree(lws);
+	module_put(ops->owner);
+}
+EXPORT_SYMBOL(lwtstate_free);
+
 int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops *ops,
 			   unsigned int num)
 {
@@ -111,8 +120,11 @@ int lwtunnel_build_state(struct net_devi
 	ret = -EOPNOTSUPP;
 	rcu_read_lock();
 	ops = rcu_dereference(lwtun_encaps[encap_type]);
-	if (likely(ops && ops->build_state))
+	if (likely(ops && ops->build_state && try_module_get(ops->owner))) {
 		ret = ops->build_state(dev, encap, family, cfg, lws);
+		if (ret)
+			module_put(ops->owner);
+	}
 	rcu_read_unlock();
 
 	return ret;

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 4.9 00/51] 4.9.8-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:40 +0100
  [PATCH 4.9 35/51] xfs: adjust allocation length in xfs_alloc_space_available Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:40 +0100
  [PATCH 4.9 36/51] xfs: dont rely on ->total in xfs_alloc_space_available Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:40 +0100
  [PATCH 4.9 09/51] tcp: fix tcp_fastopen unaligned access complaints on sparc Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:40 +0100
  [PATCH 4.9 05/51] mlxsw: pci: Fix EQE structure definition Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:40 +0100
  [PATCH 4.9 04/51] mlxsw: switchx2: Fix memory leak at skb reallocation Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:40 +0100
  [PATCH 4.9 03/51] mlxsw: spectrum: Fix memory leak at skb reallocation Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:40 +0100
  [PATCH 4.9 26/51] net: mpls: Fix multipath selection for LSR use case Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:40 +0100
  [PATCH 4.9 11/51] mlx4: do not call napi_schedule() without care Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 14/51] ax25: Fix segfault after sock connection timeout Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 47/51] xfs: verify dirblocklog correctly Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 43/51] xfs: sanity check inode di_mode Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 39/51] xfs: sanity check directory inode di_size Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 15/51] net sched actions: fix refcnt when GETing of action after bind Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 50/51] xfs: clear _XBF_PAGES from buffers when readahead page Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 22/51] ipv6: addrconf: Avoid addrconf_disable_change() using RCU read-side lock Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 31/51] lwtunnel: Fix oops on state free after encap module unload Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 23/51] tcp: initialize max window for a new fastopen socket Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 49/51] xfs: extsize hints are not unlikely in xfs_bmap_btalloc Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 24/51] net/mlx5e: Do not recycle pages from emergency reserve Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 08/51] net: systemport: Decouple flow control from __bcm_sysport_tx_reclaim Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 30/51] net: Specify the owning module for lwtunnel ops Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 20/51] net: phy: bcm63xx: Utilize correct config_intr function Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 27/51] r8152: dont execute runtime suspend if the tx is not empty Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 46/51] xfs: fix COW writeback race Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 44/51] xfs: dont wrap ID in xfs_dq_get_next_id Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 06/51] net: lwtunnel: Handle lwtunnel_fill_encap failure Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 42/51] xfs: sanity check inode mode when creating new dentry Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 32/51] net: dsa: Bring back device detaching in dsa_slave_suspend() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 41/51] xfs: replace xfs_mode_to_ftype table with switch statement Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 10/51] openvswitch: maintain correct checksum state in conntrack actions Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 13/51] ip6_tunnel: Account for tunnel header in tunnel MTU Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 45/51] xfs: fix xfs_mode_to_ftype() prototype Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 28/51] af_unix: move unix_mknod() out of bindlock Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 25/51] bridge: netlink: call br_changelink() during br_dev_newlink() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 34/51] xfs: fix bogus minleft manipulations Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 37/51] xfs: dont print warnings when xfs_log_force fails Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 48/51] xfs: remove racy hasattr check from attr ops Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 12/51] ravb: do not use zero-length alignment DMA descriptor Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 51/51] xfs: fix bmv_count confusion w/ shared extents Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 33/51] xfs: bump up reserved blocks in xfs_alloc_set_aside Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 19:50 +0100
  [PATCH 4.9 02/51] netvsc: add rcu_read locking to netvsc callback Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 20:00 +0100
  [PATCH 4.9 17/51] virtio-net: restore VIRTIO_HDR_F_DATA_VALID on receiving Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 20:00 +0100
  [PATCH 4.9 07/51] net: ipv4: fix table id in getroute response Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 20:00 +0100
  [PATCH 4.9 01/51] r8152: fix the sw rx checksum is unavailable Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 20:00 +0100
  Re: [PATCH 4.9 00/51] 4.9.8-stable review Shuah Khan <shuahkh@osg.samsung.com> - 2017-02-02 21:40 +0100
    Re: [PATCH 4.9 00/51] 4.9.8-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-02 22:00 +0100
  Re: [PATCH 4.9 00/51] 4.9.8-stable review Guenter Roeck <linux@roeck-us.net> - 2017-02-03 06:20 +0100
    Re: [PATCH 4.9 00/51] 4.9.8-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-03 08:20 +0100

csiph-web