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, Eric Dumazet <edumazet@google.com>,
	Baozeng Ding <sploving1@gmail.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: [PATCH 4.8 09/35] ipv6: tcp: restore IP6CB for pktoptions skbs
Date: Sun, 13 Nov 2016 12:27:23 +0100	[thread overview]
Message-ID: <20161113112421.226878243@linuxfoundation.org> (raw)
In-Reply-To: <20161113112420.863033770@linuxfoundation.org>

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

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

From: Eric Dumazet <edumazet@google.com>


[ Upstream commit 8ce48623f0cf3d632e32448411feddccb693d351 ]

Baozeng Ding reported following KASAN splat :

BUG: KASAN: use-after-free in ip6_datagram_recv_specific_ctl+0x13f1/0x15c0 at addr ffff880029c84ec8
Read of size 1 by task poc/25548
Call Trace:
 [<ffffffff82cf43c9>] dump_stack+0x12e/0x185 /lib/dump_stack.c:15
 [<     inline     >] print_address_description /mm/kasan/report.c:204
 [<ffffffff817ced3b>] kasan_report_error+0x48b/0x4b0 /mm/kasan/report.c:283
 [<     inline     >] kasan_report /mm/kasan/report.c:303
 [<ffffffff817ced9e>] __asan_report_load1_noabort+0x3e/0x40 /mm/kasan/report.c:321
 [<ffffffff85c71da1>] ip6_datagram_recv_specific_ctl+0x13f1/0x15c0 /net/ipv6/datagram.c:687
 [<ffffffff85c734c3>] ip6_datagram_recv_ctl+0x33/0x40
 [<ffffffff85c0b07c>] do_ipv6_getsockopt.isra.4+0xaec/0x2150
 [<ffffffff85c0c7f6>] ipv6_getsockopt+0x116/0x230
 [<ffffffff859b5a12>] tcp_getsockopt+0x82/0xd0 /net/ipv4/tcp.c:3035
 [<ffffffff855fb385>] sock_common_getsockopt+0x95/0xd0 /net/core/sock.c:2647
 [<     inline     >] SYSC_getsockopt /net/socket.c:1776
 [<ffffffff855f8ba2>] SyS_getsockopt+0x142/0x230 /net/socket.c:1758
 [<ffffffff8685cdc5>] entry_SYSCALL_64_fastpath+0x23/0xc6
Memory state around the buggy address:
 ffff880029c84d80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff880029c84e00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ffff880029c84e80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                                              ^
 ffff880029c84f00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff880029c84f80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff

He also provided a syzkaller reproducer.

Issue is that ip6_datagram_recv_specific_ctl() expects to find IP6CB
data that was moved at a different place in tcp_v6_rcv()

This patch moves tcp_v6_restore_cb() up and calls it from
tcp_v6_do_rcv() when np->pktoptions is set.

Fixes: 971f10eca186 ("tcp: better TCP_SKB_CB layout to reduce cache line misses")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Baozeng Ding <sploving1@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 net/ipv6/tcp_ipv6.c |   20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1193,6 +1193,16 @@ out:
 	return NULL;
 }
 
+static void tcp_v6_restore_cb(struct sk_buff *skb)
+{
+	/* We need to move header back to the beginning if xfrm6_policy_check()
+	 * and tcp_v6_fill_cb() are going to be called again.
+	 * ip6_datagram_recv_specific_ctl() also expects IP6CB to be there.
+	 */
+	memmove(IP6CB(skb), &TCP_SKB_CB(skb)->header.h6,
+		sizeof(struct inet6_skb_parm));
+}
+
 /* The socket must have it's spinlock held when we get
  * here, unless it is a TCP_LISTEN socket.
  *
@@ -1322,6 +1332,7 @@ ipv6_pktoptions:
 			np->flow_label = ip6_flowlabel(ipv6_hdr(opt_skb));
 		if (ipv6_opt_accepted(sk, opt_skb, &TCP_SKB_CB(opt_skb)->header.h6)) {
 			skb_set_owner_r(opt_skb, sk);
+			tcp_v6_restore_cb(opt_skb);
 			opt_skb = xchg(&np->pktoptions, opt_skb);
 		} else {
 			__kfree_skb(opt_skb);
@@ -1355,15 +1366,6 @@ static void tcp_v6_fill_cb(struct sk_buf
 	TCP_SKB_CB(skb)->sacked = 0;
 }
 
-static void tcp_v6_restore_cb(struct sk_buff *skb)
-{
-	/* We need to move header back to the beginning if xfrm6_policy_check()
-	 * and tcp_v6_fill_cb() are going to be called again.
-	 */
-	memmove(IP6CB(skb), &TCP_SKB_CB(skb)->header.h6,
-		sizeof(struct inet6_skb_parm));
-}
-
 static int tcp_v6_rcv(struct sk_buff *skb)
 {
 	const struct tcphdr *th;

  parent reply	other threads:[~2016-11-13 11:29 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161113112745epcas3p44b79602b71457dccccc98057db31f68c@epcas3p4.samsung.com>
2016-11-13 11:27 ` [PATCH 4.8 00/35] 4.8.8-stable review Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 02/35] net: pktgen: fix pkt_size Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 03/35] net/sched: act_vlan: Push skb->data to mac_header prior calling skb_vlan_*() functions Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 04/35] net: Add netdev all_adj_list refcnt propagation to fix panic Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 05/35] packet: call fanout_release, while UNREGISTERING a netdev Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 06/35] netlink: do not enter direct reclaim from netlink_dump() Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 07/35] drivers/ptp: Fix kernel memory disclosure Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 08/35] net_sched: reorder pernet ops and act ops registrations Greg Kroah-Hartman
2016-11-13 11:27   ` Greg Kroah-Hartman [this message]
2016-11-13 11:27   ` [PATCH 4.8 10/35] net: phy: Trigger state machine on state change and not polling Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 11/35] ip6_tunnel: fix ip6_tnl_lookup Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 12/35] ipv6: correctly add local routes when lo goes up Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 13/35] IB/ipoib: move back IB LL address into the hard header Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 14/35] net/mlx4_en: fixup xdp tx irq to match rx Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 15/35] net: pktgen: remove rcu locking in pktgen_change_name() Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 16/35] bridge: multicast: restore perm router ports on multicast enable Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 17/35] switchdev: Execute bridge ndos only for bridge ports Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 18/35] rtnetlink: Add rtnexthop offload flag to compare mask Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 19/35] net: core: Correctly iterate over lower adjacency list Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 21/35] ipv4: disable BH in set_ping_group_range() Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 22/35] ipv4: use the right lock for ping_group_range Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 23/35] net: fec: Call swap_buffer() prior to IP header alignment Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 24/35] net: sctp, forbid negative length Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 25/35] sctp: fix the panic caused by route update Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 26/35] udp: fix IP_CHECKSUM handling Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 27/35] netvsc: fix incorrect receive checksum offloading Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 28/35] macsec: Fix header length if SCI is added if explicitly disabled Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 29/35] net: ipv6: Do not consider link state for nexthop validation Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 30/35] net sched filters: fix notification of filter delete with proper handle Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 31/35] sctp: validate chunk len before actually using it Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 32/35] ip6_tunnel: Update skb->protocol to ETH_P_IPV6 in ip6_tnl_xmit() Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 33/35] packet: on direct_xmit, limit tso and csum to supported devices Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 34/35] arch/powerpc: Update parameters for csum_tcpudp_magic & csum_tcpudp_nofold Greg Kroah-Hartman
2016-11-13 11:27   ` [PATCH 4.8 35/35] usb: dwc3: gadget: properly account queued requests Greg Kroah-Hartman
2016-11-13 20:41   ` [PATCH 4.8 00/35] 4.8.8-stable review Guenter Roeck
2016-11-14  7:44     ` Greg Kroah-Hartman
     [not found]   ` <5828ae8b.46bb1c0a.31433.9533@mx.google.com>
2016-11-14  7:53     ` Greg Kroah-Hartman
2016-11-14 16:48   ` Shuah Khan
2016-11-14 17:18     ` 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=20161113112421.226878243@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sploving1@gmail.com \
    --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).