stable.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: Lorenz Bauer <lmb@cloudflare.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Sasha Levin <sashal@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.4 047/107] net: bpf: Don't leak time wait and request sockets
Date: Fri, 24 Jan 2020 09:17:17 -0500	[thread overview]
Message-ID: <20200124141817.28793-47-sashal@kernel.org> (raw)
In-Reply-To: <20200124141817.28793-1-sashal@kernel.org>

From: Lorenz Bauer <lmb@cloudflare.com>

[ Upstream commit 2e012c74823629d9db27963c79caa3f5b2010746 ]

It's possible to leak time wait and request sockets via the following
BPF pseudo code:
 
  sk = bpf_skc_lookup_tcp(...)
  if (sk)
    bpf_sk_release(sk)

If sk->sk_state is TCP_NEW_SYN_RECV or TCP_TIME_WAIT the refcount taken
by bpf_skc_lookup_tcp is not undone by bpf_sk_release. This is because
sk_flags is re-used for other data in both kinds of sockets. The check

  !sock_flag(sk, SOCK_RCU_FREE)

therefore returns a bogus result. Check that sk_flags is valid by calling
sk_fullsock. Skip checking SOCK_RCU_FREE if we already know that sk is
not a full socket.

Fixes: edbf8c01de5a ("bpf: add skc_lookup_tcp helper")
Fixes: f7355a6c0497 ("bpf: Check sk_fullsock() before returning from bpf_sk_lookup()")
Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200110132336.26099-1-lmb@cloudflare.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/core/filter.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/net/core/filter.c b/net/core/filter.c
index 2f76461c120d2..3cbf06a466f7d 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5305,8 +5305,7 @@ __bpf_sk_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len,
 	if (sk) {
 		sk = sk_to_full_sk(sk);
 		if (!sk_fullsock(sk)) {
-			if (!sock_flag(sk, SOCK_RCU_FREE))
-				sock_gen_put(sk);
+			sock_gen_put(sk);
 			return NULL;
 		}
 	}
@@ -5343,8 +5342,7 @@ bpf_sk_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len,
 	if (sk) {
 		sk = sk_to_full_sk(sk);
 		if (!sk_fullsock(sk)) {
-			if (!sock_flag(sk, SOCK_RCU_FREE))
-				sock_gen_put(sk);
+			sock_gen_put(sk);
 			return NULL;
 		}
 	}
@@ -5411,7 +5409,8 @@ static const struct bpf_func_proto bpf_sk_lookup_udp_proto = {
 
 BPF_CALL_1(bpf_sk_release, struct sock *, sk)
 {
-	if (!sock_flag(sk, SOCK_RCU_FREE))
+	/* Only full sockets have sk->sk_flags. */
+	if (!sk_fullsock(sk) || !sock_flag(sk, SOCK_RCU_FREE))
 		sock_gen_put(sk);
 	return 0;
 }
-- 
2.20.1


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

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-24 14:16 [PATCH AUTOSEL 5.4 001/107] batman-adv: Fix DAT candidate selection on little endian systems Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 002/107] clk: sunxi-ng: v3s: Fix incorrect number of hw_clks Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 003/107] ARM: dts: meson8: fix the size of the PMU registers Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 004/107] dt-bindings: reset: meson8b: fix duplicate reset IDs Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 005/107] arm64: dts: meson-sm1-sei610: add gpio bluetooth interrupt Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 006/107] ARM: OMAP2+: Fix ti_sysc_find_one_clockdomain to check for to_clk_hw_omap Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 007/107] bus: ti-sysc: Fix iterating over clocks Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 008/107] ARM: dts: sun8i: a83t: Correct USB3503 GPIOs polarity Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 009/107] ARM: dts: am57xx-beagle-x15/am57xx-idk: Remove "gpios" for endpoint dt nodes Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 010/107] ARM: dts: beagle-x15-common: Model 5V0 regulator Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 011/107] soc: ti: wkup_m3_ipc: Fix race condition with rproc_boot Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 012/107] tools lib traceevent: Fix memory leakage in filter_event Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 013/107] ARM: dts: imx6q-dhcom: fix rtc compatible Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 014/107] arm64: dts: ls1028a: fix endian setting for dcfg Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 015/107] arm64: dts: imx8mm: Change SDMA1 ahb clock for imx8mm Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 016/107] ARM: dts: imx7ulp: fix reg of cpu node Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 017/107] ARM: dts: imx6q-dhcom: Fix SGTL5000 VDDIO regulator connection Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 018/107] arm64: dts: imx8mq-librem5-devkit: use correct interrupt for the magnetometer Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 019/107] rseq: Unregister rseq for clone CLONE_VM Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 020/107] locking/lockdep: Fix buffer overrun problem in stack_trace[] Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 021/107] efi/earlycon: Fix write-combine mapping on x86 Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 022/107] clk: Don't try to enable critical clocks if prepare failed Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 023/107] clk: sunxi-ng: sun8i-r: Fix divider on APB0 clock Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 024/107] clk: sunxi-ng: h6-r: Fix AR100/R_APB2 parent order Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 025/107] mac80211: mesh: restrict airtime metric to peered established plinks Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 026/107] x86/resctrl: Fix potential memory leak Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 027/107] clk: qcom: gcc-sdm845: Add missing flag to votable GDSCs Sasha Levin
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 028/107] clk: mmp2: Fix the order of timer mux parents Sasha Levin
2020-01-24 21:08   ` Lubomir Rintel
2020-01-24 14:16 ` [PATCH AUTOSEL 5.4 029/107] ASoC: rt5640: Fix NULL dereference on module unload Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 030/107] ARM: dts: imx6q-icore-mipi: Use 1.5 version of i.Core MX6DL Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 031/107] ARM: dts: imx6qdl-sabresd: Remove incorrect power supply assignment Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 032/107] ARM: dts: imx6sx-sdb: " Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 033/107] ARM: dts: imx6sl-evk: " Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 034/107] ARM: dts: imx6sll-evk: " Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 035/107] ARM: dts: imx7: Fix Toradex Colibri iMX7S 256MB NAND flash support Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 036/107] s390/zcrypt: move ap device reset from bus to driver code Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 037/107] s390/setup: Fix secure ipl message Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 038/107] i40e: Fix virtchnl_queue_select bitmap validation Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 039/107] ixgbevf: Remove limit of 10 entries for unicast filter list Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 040/107] ixgbe: Fix calculation of queue with VFs and flow director on interface flap Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 041/107] igb: Fix SGMII SFP module discovery for 100FX/LX Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 042/107] iavf: remove current MAC address filter on VF reset Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 043/107] ASoC: stm32: sai: fix possible circular locking Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 044/107] bpf/sockmap: Read psock ingress_msg before sk_receive_queue Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 045/107] sh_eth: check sh_eth_cpu_data::dual_port when dumping registers Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 046/107] ASoC: stm32: dfsdm: fix 16 bits record Sasha Levin
2020-01-24 14:17 ` Sasha Levin [this message]
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 048/107] net: stmmac: selftests: Update status when disabling RSS Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 049/107] net: stmmac: tc: Do not setup flower filtering if RSS is enabled Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 050/107] bpftool: Fix printing incorrect pointer in btf_dump_ptr Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 051/107] platform/x86: GPD pocket fan: Allow somewhat lower/higher temperature limits Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 052/107] platform/x86: intel_pmc_core: update Comet Lake platform driver Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 053/107] ASoC: SOF: Intel: fix HDA codec driver probe with multiple controllers Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 054/107] ASoC: hdac_hda: Fix error in driver removal after failed probe Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 055/107] ASoC: msm8916-wcd-analog: Fix selected events for MIC BIAS External1 Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 056/107] ASoC: sti: fix possible sleep-in-atomic Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 057/107] ASoC: msm8916-wcd-analog: Fix MIC BIAS Internal1 Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 058/107] ASoC: msm8916-wcd-digital: Reset RX interpolation path after use Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 059/107] netfilter: fix a use-after-free in mtype_destroy() Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 060/107] netfilter: arp_tables: init netns pointer in xt_tgdtor_param struct Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 061/107] qmi_wwan: Add support for Quectel RM500Q Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 062/107] NFC: pn533: fix bulk-message timeout Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 063/107] parisc: Use proper printk format for resource_size_t Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 064/107] lkdtm/bugs: fix build error in lkdtm_UNSET_SMEP Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 065/107] ptp: free ptp device pin descriptors properly Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 066/107] net: usb: lan78xx: limit size of local TSO packets Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 067/107] r8152: add missing endpoint sanity check Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 068/107] wireless: fix enabling channel 12 for custom regulatory domain Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 069/107] cfg80211: Fix radar event during another phy CAC Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 070/107] mac80211: Fix TKIP replay protection immediately after key setup Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 071/107] wireless: wext: avoid gcc -O3 warning Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 072/107] cfg80211: check for set_wiphy_params Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 073/107] tick/sched: Annotate lockless access to last_jiffies_update Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 074/107] Revert "gpio: thunderx: Switch to GPIOLIB_IRQCHIP" Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 075/107] mlxsw: spectrum: Do not modify cloned SKBs during xmit Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 076/107] mlxsw: switchx2: " Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 077/107] selftests: mlxsw: qos_mc_aware: Fix mausezahn invocation Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 078/107] mlxsw: spectrum: Wipe xstats.backlog of down ports Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 079/107] i2c: iop3xx: Fix memory leak in probe error path Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 080/107] Fix built-in early-load Intel microcode alignment Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 081/107] hv_netvsc: Fix memory leak when removing rndis device Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 082/107] bpf: Fix incorrect verifier simulation of ARSH under ALU32 Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 083/107] net/wan/fsl_ucc_hdlc: fix out of bounds write on array utdm_info Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 084/107] net: stmmac: selftests: Make it work in Synopsys AXS101 boards Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 085/107] net: stmmac: selftests: Mark as fail when received VLAN ID != expected Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 086/107] scsi: storvsc: Correctly set number of hardware queues for IDE disk Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 087/107] scsi: mptfusion: Fix double fetch bug in ioctl Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 088/107] net: hns3: pad the short frame before sending to the hardware Sasha Levin
2020-01-24 14:17 ` [PATCH AUTOSEL 5.4 089/107] net: ethernet: ave: Avoid lockdep warning Sasha Levin
2020-01-24 14:18 ` [PATCH AUTOSEL 5.4 090/107] netfilter: nf_tables: store transaction list locally while requesting module Sasha Levin
2020-01-24 14:18 ` [PATCH AUTOSEL 5.4 091/107] netfilter: nft_tunnel: fix null-attribute check Sasha Levin
2020-01-24 14:18 ` [PATCH AUTOSEL 5.4 092/107] netfilter: nft_tunnel: ERSPAN_VERSION must not be null Sasha Levin
2020-01-24 14:18 ` [PATCH AUTOSEL 5.4 093/107] netfilter: nf_tables: remove WARN and add NLA_STRING upper limits Sasha Levin
2020-01-24 14:18 ` [PATCH AUTOSEL 5.4 094/107] netfilter: nf_tables: fix flowtable list del corruption Sasha Levin
2020-01-24 14:18 ` [PATCH AUTOSEL 5.4 095/107] netfilter: nat: fix ICMP header corruption on ICMP errors Sasha Levin
2020-01-24 14:18 ` [PATCH AUTOSEL 5.4 096/107] net: hns: fix soft lockup when there is not enough memory 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=20200124141817.28793-47-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=ast@kernel.org \
    --cc=kafai@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lmb@cloudflare.com \
    --cc=netdev@vger.kernel.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).