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: Martin Willi <martin@strongswan.org>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	Sasha Levin <sashal@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 4.14 03/33] esp: Skip TX bytes accounting when sending from a request socket
Date: Wed, 13 Mar 2019 15:14:36 -0400	[thread overview]
Message-ID: <20190313191506.159677-3-sashal@kernel.org> (raw)
In-Reply-To: <20190313191506.159677-1-sashal@kernel.org>

From: Martin Willi <martin@strongswan.org>

[ Upstream commit 09db51241118aeb06e1c8cd393b45879ce099b36 ]

On ESP output, sk_wmem_alloc is incremented for the added padding if a
socket is associated to the skb. When replying with TCP SYNACKs over
IPsec, the associated sk is a casted request socket, only. Increasing
sk_wmem_alloc on a request socket results in a write at an arbitrary
struct offset. In the best case, this produces the following WARNING:

WARNING: CPU: 1 PID: 0 at lib/refcount.c:102 esp_output_head+0x2e4/0x308 [esp4]
refcount_t: addition on 0; use-after-free.
CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.0.0-rc3 #2
Hardware name: Marvell Armada 380/385 (Device Tree)
[...]
[<bf0ff354>] (esp_output_head [esp4]) from [<bf1006a4>] (esp_output+0xb8/0x180 [esp4])
[<bf1006a4>] (esp_output [esp4]) from [<c05dee64>] (xfrm_output_resume+0x558/0x664)
[<c05dee64>] (xfrm_output_resume) from [<c05d07b0>] (xfrm4_output+0x44/0xc4)
[<c05d07b0>] (xfrm4_output) from [<c05956bc>] (tcp_v4_send_synack+0xa8/0xe8)
[<c05956bc>] (tcp_v4_send_synack) from [<c0586ad8>] (tcp_conn_request+0x7f4/0x948)
[<c0586ad8>] (tcp_conn_request) from [<c058c404>] (tcp_rcv_state_process+0x2a0/0xe64)
[<c058c404>] (tcp_rcv_state_process) from [<c05958ac>] (tcp_v4_do_rcv+0xf0/0x1f4)
[<c05958ac>] (tcp_v4_do_rcv) from [<c0598a4c>] (tcp_v4_rcv+0xdb8/0xe20)
[<c0598a4c>] (tcp_v4_rcv) from [<c056eb74>] (ip_protocol_deliver_rcu+0x2c/0x2dc)
[<c056eb74>] (ip_protocol_deliver_rcu) from [<c056ee6c>] (ip_local_deliver_finish+0x48/0x54)
[<c056ee6c>] (ip_local_deliver_finish) from [<c056eecc>] (ip_local_deliver+0x54/0xec)
[<c056eecc>] (ip_local_deliver) from [<c056efac>] (ip_rcv+0x48/0xb8)
[<c056efac>] (ip_rcv) from [<c0519c2c>] (__netif_receive_skb_one_core+0x50/0x6c)
[...]

The issue triggers only when not using TCP syncookies, as for syncookies
no socket is associated.

Fixes: cac2661c53f3 ("esp4: Avoid skb_cow_data whenever possible")
Fixes: 03e2a30f6a27 ("esp6: Avoid skb_cow_data whenever possible")
Signed-off-by: Martin Willi <martin@strongswan.org>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/ipv4/esp4.c | 2 +-
 net/ipv6/esp6.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index b00e4a43b4dc..d30285c5d52d 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -307,7 +307,7 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
 			skb->len += tailen;
 			skb->data_len += tailen;
 			skb->truesize += tailen;
-			if (sk)
+			if (sk && sk_fullsock(sk))
 				refcount_add(tailen, &sk->sk_wmem_alloc);
 
 			goto out;
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index f112fef79216..ef7822fad0fd 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -275,7 +275,7 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
 			skb->len += tailen;
 			skb->data_len += tailen;
 			skb->truesize += tailen;
-			if (sk)
+			if (sk && sk_fullsock(sk))
 				refcount_add(tailen, &sk->sk_wmem_alloc);
 
 			goto out;
-- 
2.19.1


  parent reply	other threads:[~2019-03-13 19:15 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-13 19:14 [PATCH AUTOSEL 4.14 01/33] clk: sunxi-ng: v3s: Fix TCON reset de-assert bit Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 02/33] clk: sunxi: A31: Fix wrong AHB gate number Sasha Levin
2019-03-13 19:14 ` Sasha Levin [this message]
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 04/33] ARM: 8824/1: fix a migrating irq bug when hotplug cpu Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 05/33] af_key: unconditionally clone on broadcast Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 06/33] assoc_array: Fix shortcut creation Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 07/33] keys: Fix dependency loop between construction record and auth key Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 08/33] scsi: libiscsi: Fix race between iscsi_xmit_task and iscsi_complete_task Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 09/33] scsi: core: reset host byte in DID_NEXUS_FAILURE case Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 10/33] net: systemport: Fix reception of BPDUs Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 11/33] pinctrl: meson: meson8b: fix the sdxc_a data 1..3 pins Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 12/33] qmi_wwan: apply SET_DTR quirk to Sierra WP7607 Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 13/33] net: mv643xx_eth: disable clk on error path in mv643xx_eth_shared_probe() Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 14/33] mailbox: bcm-flexrm-mailbox: Fix FlexRM ring flush timeout issue Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 15/33] ASoC: topology: free created components in tplg load error Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 16/33] qed: Fix iWARP syn packet mac address validation Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 17/33] arm64: Relax GIC version check during early boot Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 18/33] net: marvell: mvneta: fix DMA debug warning Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 19/33] kasan, slub: move kasan_poison_slab hook before page_address Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 20/33] tmpfs: fix link accounting when a tmpfile is linked in Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 21/33] kasan, slab: fix conflicts with CONFIG_HARDENED_USERCOPY Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 22/33] kasan, slab: make freelist stored without tags Sasha Levin
2019-03-13 19:18   ` Andrey Konovalov
2019-03-19 19:54     ` Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 23/33] ixgbe: fix older devices that do not support IXGBE_MRQC_L3L4TXSWEN Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 24/33] ARCv2: lib: memcpy: fix doing prefetchw outside of buffer Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 25/33] ARC: uacces: remove lp_start, lp_end from clobber list Sasha Levin
2019-03-13 19:14 ` [PATCH AUTOSEL 4.14 26/33] ARCv2: support manual regfile save on interrupts Sasha Levin
2019-03-13 19:15 ` [PATCH AUTOSEL 4.14 27/33] phonet: fix building with clang Sasha Levin
2019-03-13 19:15 ` [PATCH AUTOSEL 4.14 28/33] mac80211_hwsim: propagate genlmsg_reply return code Sasha Levin
2019-03-13 19:15 ` [PATCH AUTOSEL 4.14 29/33] net: thunderx: make CFG_DONE message to run through generic send-ack sequence Sasha Levin
2019-03-13 19:15 ` [PATCH AUTOSEL 4.14 30/33] nfp: bpf: fix code-gen bug on BPF_ALU | BPF_XOR | BPF_K Sasha Levin
2019-03-13 19:15 ` [PATCH AUTOSEL 4.14 31/33] nfp: bpf: fix ALU32 high bits clearance bug Sasha Levin
2019-03-13 19:15 ` [PATCH AUTOSEL 4.14 32/33] mdio_bus: Fix use-after-free on device_register fails Sasha Levin
2019-03-13 19:15 ` [PATCH AUTOSEL 4.14 33/33] net: set static variable an initial value in atl2_probe() 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=20190313191506.159677-3-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin@strongswan.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=steffen.klassert@secunet.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 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).