linux-kernel.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: Taehee Yoo <ap420073@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	Sasha Levin <sashal@kernel.org>,
	osmocom-net-gprs@lists.osmocom.org, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 4.14 103/105] gtp: fix use-after-free in gtp_encap_destroy()
Date: Mon, 15 Jul 2019 10:28:37 -0400	[thread overview]
Message-ID: <20190715142839.9896-103-sashal@kernel.org> (raw)
In-Reply-To: <20190715142839.9896-1-sashal@kernel.org>

From: Taehee Yoo <ap420073@gmail.com>

[ Upstream commit 1788b8569f5de27da09087fa3f6580d2aa04cc75 ]

gtp_encap_destroy() is called twice.
1. When interface is deleted.
2. When udp socket is destroyed.
either gtp->sk0 or gtp->sk1u could be freed by sock_put() in
gtp_encap_destroy(). so, when gtp_encap_destroy() is called again,
it would uses freed sk pointer.

patch makes gtp_encap_destroy() to set either gtp->sk0 or gtp->sk1u to
null. in addition, both gtp->sk0 and gtp->sk1u pointer are protected
by rtnl_lock. so, rtnl_lock() is added.

Test command:
   gtp-link add gtp1 &
   killall gtp-link
   ip link del gtp1

Splat looks like:
[   83.182767] BUG: KASAN: use-after-free in __lock_acquire+0x3a20/0x46a0
[   83.184128] Read of size 8 at addr ffff8880cc7d5360 by task ip/1008
[   83.185567] CPU: 1 PID: 1008 Comm: ip Not tainted 5.2.0-rc6+ #50
[   83.188469] Call Trace:
[ ... ]
[   83.200126]  lock_acquire+0x141/0x380
[   83.200575]  ? lock_sock_nested+0x3a/0xf0
[   83.201069]  _raw_spin_lock_bh+0x38/0x70
[   83.201551]  ? lock_sock_nested+0x3a/0xf0
[   83.202044]  lock_sock_nested+0x3a/0xf0
[   83.202520]  gtp_encap_destroy+0x18/0xe0 [gtp]
[   83.203065]  gtp_encap_disable.isra.14+0x13/0x50 [gtp]
[   83.203687]  gtp_dellink+0x56/0x170 [gtp]
[   83.204190]  rtnl_delete_link+0xb4/0x100
[ ... ]
[   83.236513] Allocated by task 976:
[   83.236925]  save_stack+0x19/0x80
[   83.237332]  __kasan_kmalloc.constprop.3+0xa0/0xd0
[   83.237894]  kmem_cache_alloc+0xd8/0x280
[   83.238360]  sk_prot_alloc.isra.42+0x50/0x200
[   83.238874]  sk_alloc+0x32/0x940
[   83.239264]  inet_create+0x283/0xc20
[   83.239684]  __sock_create+0x2dd/0x540
[   83.240136]  __sys_socket+0xca/0x1a0
[   83.240550]  __x64_sys_socket+0x6f/0xb0
[   83.240998]  do_syscall_64+0x9c/0x450
[   83.241466]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
[   83.242061]
[   83.242249] Freed by task 0:
[   83.242616]  save_stack+0x19/0x80
[   83.243013]  __kasan_slab_free+0x111/0x150
[   83.243498]  kmem_cache_free+0x89/0x250
[   83.244444]  __sk_destruct+0x38f/0x5a0
[   83.245366]  rcu_core+0x7e9/0x1c20
[   83.245766]  __do_softirq+0x213/0x8fa

Fixes: 1e3a3abd8b28 ("gtp: make GTP sockets in gtp_newlink optional")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/gtp.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
index c751f87c935e..53fd66534e3a 100644
--- a/drivers/net/gtp.c
+++ b/drivers/net/gtp.c
@@ -289,13 +289,17 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
 	return gtp_rx(pctx, skb, hdrlen, gtp->role);
 }
 
-static void gtp_encap_destroy(struct sock *sk)
+static void __gtp_encap_destroy(struct sock *sk)
 {
 	struct gtp_dev *gtp;
 
 	lock_sock(sk);
 	gtp = sk->sk_user_data;
 	if (gtp) {
+		if (gtp->sk0 == sk)
+			gtp->sk0 = NULL;
+		else
+			gtp->sk1u = NULL;
 		udp_sk(sk)->encap_type = 0;
 		rcu_assign_sk_user_data(sk, NULL);
 		sock_put(sk);
@@ -303,12 +307,19 @@ static void gtp_encap_destroy(struct sock *sk)
 	release_sock(sk);
 }
 
+static void gtp_encap_destroy(struct sock *sk)
+{
+	rtnl_lock();
+	__gtp_encap_destroy(sk);
+	rtnl_unlock();
+}
+
 static void gtp_encap_disable_sock(struct sock *sk)
 {
 	if (!sk)
 		return;
 
-	gtp_encap_destroy(sk);
+	__gtp_encap_destroy(sk);
 }
 
 static void gtp_encap_disable(struct gtp_dev *gtp)
@@ -1045,6 +1056,7 @@ static int gtp_genl_new_pdp(struct sk_buff *skb, struct genl_info *info)
 		return -EINVAL;
 	}
 
+	rtnl_lock();
 	rcu_read_lock();
 
 	gtp = gtp_find_dev(sock_net(skb->sk), info->attrs);
@@ -1069,6 +1081,7 @@ static int gtp_genl_new_pdp(struct sk_buff *skb, struct genl_info *info)
 
 out_unlock:
 	rcu_read_unlock();
+	rtnl_unlock();
 	return err;
 }
 
-- 
2.20.1


  parent reply	other threads:[~2019-07-15 14:35 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-15 14:26 [PATCH AUTOSEL 4.14 001/105] wil6210: fix potential out-of-bounds read Sasha Levin
2019-07-15 14:26 ` [PATCH AUTOSEL 4.14 002/105] ath10k: Do not send probe response template for mesh Sasha Levin
2019-07-15 14:26 ` [PATCH AUTOSEL 4.14 003/105] ath9k: Check for errors when reading SREV register Sasha Levin
2019-07-15 14:26 ` [PATCH AUTOSEL 4.14 004/105] ath6kl: add some bounds checking Sasha Levin
2019-07-15 14:26 ` [PATCH AUTOSEL 4.14 005/105] x86/tsc: Use CPUID.0x16 to calculate missing crystal frequency Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 006/105] ath: DFS JP domain W56 fixed pulse type 3 RADAR detection Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 007/105] batman-adv: fix for leaked TVLV handler Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 008/105] media: dvb: usb: fix use after free in dvb_usb_device_exit Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 009/105] media: spi: IR LED: add missing of table registration Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 010/105] crypto: talitos - fix skcipher failure due to wrong output IV Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 011/105] media: marvell-ccic: fix DMA s/g desc number calculation Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 012/105] media: vpss: fix a potential NULL pointer dereference Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 013/105] media: media_device_enum_links32: clean a reserved field Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 014/105] net: stmmac: dwmac1000: Clear unused address entries Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 015/105] net: stmmac: dwmac4/5: " Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 016/105] qed: Set the doorbell address correctly Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 017/105] signal/pid_namespace: Fix reboot_pid_ns to use send_sig not force_sig Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 018/105] signal/cifs: Fix cifs_put_tcp_session to call send_sig instead of force_sig Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 019/105] af_key: fix leaks in key_pol_get_resp and dump_sp Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 020/105] xfrm: Fix xfrm sel prefix length validation Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 021/105] fscrypt: clean up some BUG_ON()s in block encryption/decryption Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 022/105] Revert "e1000e: fix cyclic resets at link up with active tx" Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 023/105] e1000e: start network tx queue only when link is up Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 024/105] media: mc-device.c: don't memset __user pointer contents Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 025/105] media: staging: media: davinci_vpfe: - Fix for memory leak if decoder initialization fails Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 026/105] net: phy: Check against net_device being NULL Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 027/105] crypto: talitos - properly handle split ICV Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 028/105] crypto: talitos - Align SEC1 accesses to 32 bits boundaries Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 029/105] tua6100: Avoid build warnings Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 030/105] locking/lockdep: Fix merging of hlocks with non-zero references Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 031/105] media: wl128x: Fix some error handling in fm_v4l2_init_video_device() Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 032/105] cpupower : frequency-set -r option misses the last cpu in related cpu list Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 033/105] net: stmmac: dwmac4: fix flow control issue Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 034/105] net: fec: Do not use netdev messages too early Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 035/105] net: axienet: Fix race condition causing TX hang Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 036/105] s390/qdio: handle PENDING state for QEBSM devices Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 037/105] RAS/CEC: Fix pfn insertion Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 038/105] net: sfp: add mutex to prevent concurrent state checks Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 039/105] ipset: Fix memory accounting for hash types on resize Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 040/105] perf cs-etm: Properly set the value of 'old' and 'head' in snapshot mode Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 041/105] perf test 6: Fix missing kvm module load for s390 Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 042/105] media: fdp1: Support M3N and E3 platforms Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 043/105] iommu: Fix a leak in iommu_insert_resv_region Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 044/105] gpio: omap: fix lack of irqstatus_raw0 for OMAP4 Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 045/105] gpio: omap: ensure irq is enabled before wakeup Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 046/105] regmap: fix bulk writes on paged registers Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 047/105] bpf: silence warning messages in core Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 048/105] rcu: Force inlining of rcu_read_lock() Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 049/105] x86/cpufeatures: Add FDP_EXCPTN_ONLY and ZERO_FCS_FDS Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 050/105] blkcg, writeback: dead memcgs shouldn't contribute to writeback ownership arbitration Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 051/105] xfrm: fix sa selector validation Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 052/105] sched/core: Add __sched tag for io_schedule() Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 053/105] sched/fair: Fix "runnable_avg_yN_inv" not used warnings Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 054/105] x86/atomic: Fix smp_mb__{before,after}_atomic() Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 055/105] perf evsel: Make perf_evsel__name() accept a NULL argument Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 056/105] vhost_net: disable zerocopy by default Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 057/105] ipoib: correcly show a VF hardware address Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 058/105] EDAC/sysfs: Fix memory leak when creating a csrow object Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 059/105] ipsec: select crypto ciphers for xfrm_algo Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 060/105] ipvs: defer hook registration to avoid leaks Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 061/105] media: s5p-mfc: Make additional clocks optional Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 062/105] media: i2c: fix warning same module names Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 063/105] ntp: Limit TAI-UTC offset Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 064/105] timer_list: Guard procfs specific code Sasha Levin
2019-07-15 14:27 ` [PATCH AUTOSEL 4.14 065/105] acpi/arm64: ignore 5.1 FADTs that are reported as 5.0 Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 066/105] media: coda: fix mpeg2 sequence number handling Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 067/105] media: coda: fix last buffer handling in V4L2_ENC_CMD_STOP Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 068/105] media: coda: increment sequence offset for the last returned frame Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 069/105] media: vimc: cap: check v4l2_fill_pixfmt return value Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 070/105] media: hdpvr: fix locking and a missing msleep Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 071/105] rtlwifi: rtl8192cu: fix error handle when usb probe failed Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 072/105] mt7601u: do not schedule rx_tasklet when the device has been disconnected Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 073/105] x86/build: Add 'set -e' to mkcapflags.sh to delete broken capflags.c Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 074/105] mt7601u: fix possible memory leak when the device is disconnected Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 075/105] ipvs: fix tinfo memory leak in start_sync_thread Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 076/105] ath10k: add missing error handling Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 077/105] ath10k: fix PCIE device wake up failed Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 078/105] perf tools: Increase MAX_NR_CPUS and MAX_CACHES Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 079/105] libata: don't request sense data on !ZAC ATA devices Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 080/105] clocksource/drivers/exynos_mct: Increase priority over ARM arch timer Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 081/105] rslib: Fix decoding of shortened codes Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 082/105] rslib: Fix handling of of caller provided syndrome Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 083/105] ixgbe: Check DDM existence in transceiver before access Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 084/105] crypto: serpent - mark __serpent_setkey_sbox noinline Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 085/105] crypto: asymmetric_keys - select CRYPTO_HASH where needed Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 086/105] PCI / ACPI: Use cached ACPI device state to get PCI device power state Sasha Levin
2019-07-16  9:22   ` Rafael J. Wysocki
2019-07-22  0:40     ` Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 087/105] EDAC: Fix global-out-of-bounds write when setting edac_mc_poll_msec Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 088/105] bcache: check c->gc_thread by IS_ERR_OR_NULL in cache_set_flush() Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 089/105] net: hns3: fix a -Wformat-nonliteral compile warning Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 090/105] net: hns3: add some error checking in hclge_tm module Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 091/105] ath10k: destroy sdio workqueue while remove sdio module Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 092/105] iwlwifi: mvm: Drop large non sta frames Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 093/105] perf stat: Make metric event lookup more robust Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 094/105] net: usb: asix: init MAC address buffers Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 095/105] gpiolib: Fix references to gpiod_[gs]et_*value_cansleep() variants Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 096/105] Bluetooth: hci_bcsp: Fix memory leak in rx_skb Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 097/105] Bluetooth: 6lowpan: search for destination address in all peers Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 098/105] Bluetooth: Check state in l2cap_disconnect_rsp Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 099/105] gtp: add missing gtp_encap_disable_sock() in gtp_encap_enable() Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 100/105] Bluetooth: validate BLE connection interval updates Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 101/105] gtp: fix suspicious RCU usage Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 102/105] gtp: fix Illegal context switch in RCU read-side critical section Sasha Levin
2019-07-15 14:28 ` Sasha Levin [this message]
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 104/105] gtp: fix use-after-free in gtp_newlink() Sasha Levin
2019-07-15 14:28 ` [PATCH AUTOSEL 4.14 105/105] net: mvmdio: defer probe of orion-mdio if a clock is not ready 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=20190715142839.9896-103-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=ap420073@gmail.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=osmocom-net-gprs@lists.osmocom.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).