linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Dongseok Yi <dseok.yi@samsung.com>,
	Willem de Bruijn <willemb@google.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH 5.10 12/43] net: fix use-after-free when UDP GRO with shared fraglist
Date: Fri, 22 Jan 2021 15:12:28 +0100	[thread overview]
Message-ID: <20210122135736.141811031@linuxfoundation.org> (raw)
In-Reply-To: <20210122135735.652681690@linuxfoundation.org>

From: Dongseok Yi <dseok.yi@samsung.com>

[ Upstream commit 53475c5dd856212e91538a9501162e821cc1f791 ]

skbs in fraglist could be shared by a BPF filter loaded at TC. If TC
writes, it will call skb_ensure_writable -> pskb_expand_head to create
a private linear section for the head_skb. And then call
skb_clone_fraglist -> skb_get on each skb in the fraglist.

skb_segment_list overwrites part of the skb linear section of each
fragment itself. Even after skb_clone, the frag_skbs share their
linear section with their clone in PF_PACKET.

Both sk_receive_queue of PF_PACKET and PF_INET (or PF_INET6) can have
a link for the same frag_skbs chain. If a new skb (not frags) is
queued to one of the sk_receive_queue, multiple ptypes can see and
release this. It causes use-after-free.

[ 4443.426215] ------------[ cut here ]------------
[ 4443.426222] refcount_t: underflow; use-after-free.
[ 4443.426291] WARNING: CPU: 7 PID: 28161 at lib/refcount.c:190
refcount_dec_and_test_checked+0xa4/0xc8
[ 4443.426726] pstate: 60400005 (nZCv daif +PAN -UAO)
[ 4443.426732] pc : refcount_dec_and_test_checked+0xa4/0xc8
[ 4443.426737] lr : refcount_dec_and_test_checked+0xa0/0xc8
[ 4443.426808] Call trace:
[ 4443.426813]  refcount_dec_and_test_checked+0xa4/0xc8
[ 4443.426823]  skb_release_data+0x144/0x264
[ 4443.426828]  kfree_skb+0x58/0xc4
[ 4443.426832]  skb_queue_purge+0x64/0x9c
[ 4443.426844]  packet_set_ring+0x5f0/0x820
[ 4443.426849]  packet_setsockopt+0x5a4/0xcd0
[ 4443.426853]  __sys_setsockopt+0x188/0x278
[ 4443.426858]  __arm64_sys_setsockopt+0x28/0x38
[ 4443.426869]  el0_svc_common+0xf0/0x1d0
[ 4443.426873]  el0_svc_handler+0x74/0x98
[ 4443.426880]  el0_svc+0x8/0xc

Fixes: 3a1296a38d0c (net: Support GRO/GSO fraglist chaining.)
Signed-off-by: Dongseok Yi <dseok.yi@samsung.com>
Acked-by: Willem de Bruijn <willemb@google.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/1610072918-174177-1-git-send-email-dseok.yi@samsung.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 net/core/skbuff.c |   20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3648,7 +3648,8 @@ struct sk_buff *skb_segment_list(struct
 	unsigned int delta_truesize = 0;
 	unsigned int delta_len = 0;
 	struct sk_buff *tail = NULL;
-	struct sk_buff *nskb;
+	struct sk_buff *nskb, *tmp;
+	int err;
 
 	skb_push(skb, -skb_network_offset(skb) + offset);
 
@@ -3658,11 +3659,28 @@ struct sk_buff *skb_segment_list(struct
 		nskb = list_skb;
 		list_skb = list_skb->next;
 
+		err = 0;
+		if (skb_shared(nskb)) {
+			tmp = skb_clone(nskb, GFP_ATOMIC);
+			if (tmp) {
+				consume_skb(nskb);
+				nskb = tmp;
+				err = skb_unclone(nskb, GFP_ATOMIC);
+			} else {
+				err = -ENOMEM;
+			}
+		}
+
 		if (!tail)
 			skb->next = nskb;
 		else
 			tail->next = nskb;
 
+		if (unlikely(err)) {
+			nskb->next = list_skb;
+			goto err_linearize;
+		}
+
 		tail = nskb;
 
 		delta_len += nskb->len;



  parent reply	other threads:[~2021-01-22 14:55 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22 14:12 [PATCH 5.10 00/43] 5.10.10-rc1 review Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 01/43] Revert "kconfig: remove kvmconfig and xenconfig shorthands" Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 02/43] bpf: Fix selftest compilation on clang 11 Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 03/43] x86/hyperv: Initialize clockevents after LAPIC is initialized Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 04/43] drm/amdgpu/display: drop DCN support for aarch64 Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 05/43] bpf: Fix signed_{sub,add32}_overflows type handling Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 06/43] X.509: Fix crash caused by NULL pointer Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 07/43] nfsd4: readdirplus shouldnt return parent of export Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 08/43] bpf: Dont leak memory in bpf getsockopt when optlen == 0 Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 09/43] bpf: Support PTR_TO_MEM{,_OR_NULL} register spilling Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 10/43] bpf: Fix helper bpf_map_peek_elem_proto pointing to wrong callback Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 11/43] net: ipa: modem: add missing SET_NETDEV_DEV() for proper sysfs links Greg Kroah-Hartman
2021-01-22 14:12 ` Greg Kroah-Hartman [this message]
2021-01-22 14:12 ` [PATCH 5.10 13/43] udp: Prevent reuseport_select_sock from reading uninitialized socks Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 14/43] netxen_nic: fix MSI/MSI-x interrupts Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 15/43] net: ipv6: Validate GSO SKB before finish IPv6 processing Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 16/43] tipc: fix NULL deref in tipc_link_xmit() Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 17/43] mlxsw: core: Add validation of transceiver temperature thresholds Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 18/43] mlxsw: core: Increase critical threshold for ASIC thermal zone Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 19/43] net: mvpp2: Remove Pause and Asym_Pause support Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 20/43] rndis_host: set proper input size for OID_GEN_PHYSICAL_MEDIUM request Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 21/43] esp: avoid unneeded kmap_atomic call Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 22/43] net: dcb: Validate netlink message in DCB handler Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 23/43] net: dcb: Accept RTM_GETDCB messages carrying set-like DCB commands Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 24/43] rxrpc: Call state should be read with READ_ONCE() under some circumstances Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 25/43] i40e: fix potential NULL pointer dereferencing Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 26/43] net: stmmac: Fixed mtu channged by cache aligned Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 27/43] net: sit: unregister_netdevice on newlinks error path Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 28/43] net: stmmac: fix taprio schedule configuration Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 29/43] net: stmmac: fix taprio configuration when base_time is in the past Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 30/43] net: avoid 32 x truesize under-estimation for tiny skbs Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 31/43] dt-bindings: net: renesas,etheravb: RZ/G2H needs tx-internal-delay-ps Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 32/43] net: phy: smsc: fix clk error handling Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 33/43] net: dsa: clear devlink port type before unregistering slave netdevs Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 34/43] rxrpc: Fix handling of an unsupported token type in rxrpc_read() Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 35/43] net: stmmac: use __napi_schedule() for PREEMPT_RT Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 36/43] can: mcp251xfd: mcp251xfd_handle_rxif_one(): fix wrong NULL pointer check Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 37/43] drm/panel: otm8009a: allow using non-continuous dsi clock Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 38/43] mac80211: do not drop tx nulldata packets on encrypted links Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 39/43] mac80211: check if atf has been disabled in __ieee80211_schedule_txq Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 40/43] net: dsa: unbind all switches from tree when DSA master unbinds Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 41/43] cxgb4/chtls: Fix tid stuck due to wrong update of qid Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 42/43] spi: fsl: Fix driver breakage when SPI_CS_HIGH is not set in spi->mode Greg Kroah-Hartman
2021-01-22 14:12 ` [PATCH 5.10 43/43] spi: cadence: cache reference clock rate during probe Greg Kroah-Hartman
2021-01-23  0:24 ` [PATCH 5.10 00/43] 5.10.10-rc1 review Shuah Khan
2021-01-23 15:06   ` Greg Kroah-Hartman
2021-01-23  5:44 ` Naresh Kamboju
2021-01-23  7:20   ` Naresh Kamboju
2021-01-23 15:06     ` Greg Kroah-Hartman
2021-01-23  9:52 ` Pavel Machek
2021-01-23 15:06   ` Greg Kroah-Hartman
2021-01-23 14:36 ` Guenter Roeck
2021-01-23 15:07   ` Greg Kroah-Hartman

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=20210122135736.141811031@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=daniel@iogearbox.net \
    --cc=dseok.yi@samsung.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=willemb@google.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).