Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3053579ybi; Tue, 2 Jul 2019 01:13:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxuhCJwKGrR4x84SjcQjWU7D7jhBF+jwTx/IKnupekjIAnu2Zk/Br4zeoiI1LlRBE+xJMpj X-Received: by 2002:a17:90a:3724:: with SMTP id u33mr4090531pjb.19.1562055188036; Tue, 02 Jul 2019 01:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562055188; cv=none; d=google.com; s=arc-20160816; b=wbHbpg86HYgyBRVzIvBc+VzxKg7HLzMqPoKlX1ZvZ4ORH7kJLA88Y33S0ONl8Ym2aS CKipekBxn3yy5V1Jr4iKi/0JZYCbcPBglbsG+9ljzTqtBcxToO8D7hBibNLBoset+sXK FN0krRHZE1UdKFoYqcjE+ju3ZpxSb2AeYiVRYPLuY6ho5lKVVc6OiJv8kEiqb2OfHItV Egq2J46q/5e5ePy4Ye3Tmgmq6vJJITkO75Vb39epSP8GJUKBPWQTBXuWHMbTD4AHLtXi noJUAvi16zxso0sZWK07xDriS0VMmQO6Wr1mCzNGA5RgKTBFcnxySmp/wanJGM1FGo6z 0jOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bnS2zAua/iH9GF9qIGwuH41JEynH/tcTSd6kG05jpSQ=; b=w31YWUpfeONBDZC8JfPGUQLpdpCfhhArz2WhN7dIjSA6B3yZ5jffMq9XhcqsCVp/V1 YDm+a2j5ELwDEhbWW4xk5AWXyY7ErJzH+scJX8X1SjzZToce4crYhH2E3FhKGPXBl3Qe dSiMpl5Cyo0AApjDh1KfKN9bRkYYaW9ve7yoH2PjnDh8UH4ecnaET85iZO47mTyzGnPe HDH24mnGqfqsvcJgQIYs8e0tS8wtH7koG/j2f11AGhL5StNGLaijP7hAm8E8cxtlw9Tr RFbwmhIsdOLfBYIpODqWpBqbYAOZvo5YtWHh3zpbT2THMHx59XtZ021pkryKfgXAKhDr LhfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZVbZdF9G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e65si11812068pgc.454.2019.07.02.01.12.53; Tue, 02 Jul 2019 01:13:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZVbZdF9G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728838AbfGBIKf (ORCPT + 99 others); Tue, 2 Jul 2019 04:10:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:58952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728073AbfGBIKb (ORCPT ); Tue, 2 Jul 2019 04:10:31 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 269F321852; Tue, 2 Jul 2019 08:10:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562055030; bh=nifUm/JXR3cyL28TKqQxvKrN3mKnp2p+nSmRs25XYtQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZVbZdF9GvfGkSqOfOcO5t7lI5dlRk8JZ1ztj6qQODi9ZBLSIFG/VGieM+TEmwg7SS YYa27MEXD9FP5tKY6Zi0J6aQh8eHUH/Jlde3wBHE7iTb4vxepQ2DciwhmlG1pthxjB XyEL8gd8AqLTBHWdsJqmyHwGEJl83wfL3uemHAXY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+9d4c12bfd45a58738d0a@syzkaller.appspotmail.com, syzbot+a9e23ea2aa21044c2798@syzkaller.appspotmail.com, syzbot+c4c4b2bb358bb936ad7e@syzkaller.appspotmail.com, syzbot+0290d2290a607e035ba1@syzkaller.appspotmail.com, syzbot+a43d8d4e7e8a7a9e149e@syzkaller.appspotmail.com, syzbot+a47c5f4c6c00fc1ed16e@syzkaller.appspotmail.com, Xin Long , "David S. Miller" Subject: [PATCH 4.14 43/43] tipc: pass tunnel dev as NULL to udp_tunnel(6)_xmit_skb Date: Tue, 2 Jul 2019 10:02:23 +0200 Message-Id: <20190702080126.138655706@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190702080123.904399496@linuxfoundation.org> References: <20190702080123.904399496@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long commit c3bcde026684c62d7a2b6f626dc7cf763833875c upstream. udp_tunnel(6)_xmit_skb() called by tipc_udp_xmit() expects a tunnel device to count packets on dev->tstats, a perpcu variable. However, TIPC is using udp tunnel with no tunnel device, and pass the lower dev, like veth device that only initializes dev->lstats(a perpcu variable) when creating it. Later iptunnel_xmit_stats() called by ip(6)tunnel_xmit() thinks the dev as a tunnel device, and uses dev->tstats instead of dev->lstats. tstats' each pointer points to a bigger struct than lstats, so when tstats->tx_bytes is increased, other percpu variable's members could be overwritten. syzbot has reported quite a few crashes due to fib_nh_common percpu member 'nhc_pcpu_rth_output' overwritten, call traces are like: BUG: KASAN: slab-out-of-bounds in rt_cache_valid+0x158/0x190 net/ipv4/route.c:1556 rt_cache_valid+0x158/0x190 net/ipv4/route.c:1556 __mkroute_output net/ipv4/route.c:2332 [inline] ip_route_output_key_hash_rcu+0x819/0x2d50 net/ipv4/route.c:2564 ip_route_output_key_hash+0x1ef/0x360 net/ipv4/route.c:2393 __ip_route_output_key include/net/route.h:125 [inline] ip_route_output_flow+0x28/0xc0 net/ipv4/route.c:2651 ip_route_output_key include/net/route.h:135 [inline] ... or: kasan: GPF could be caused by NULL-ptr deref or user memory access RIP: 0010:dst_dev_put+0x24/0x290 net/core/dst.c:168 rt_fibinfo_free_cpus net/ipv4/fib_semantics.c:200 [inline] free_fib_info_rcu+0x2e1/0x490 net/ipv4/fib_semantics.c:217 __rcu_reclaim kernel/rcu/rcu.h:240 [inline] rcu_do_batch kernel/rcu/tree.c:2437 [inline] invoke_rcu_callbacks kernel/rcu/tree.c:2716 [inline] rcu_process_callbacks+0x100a/0x1ac0 kernel/rcu/tree.c:2697 ... The issue exists since tunnel stats update is moved to iptunnel_xmit by Commit 039f50629b7f ("ip_tunnel: Move stats update to iptunnel_xmit()"), and here to fix it by passing a NULL tunnel dev to udp_tunnel(6)_xmit_skb so that the packets counting won't happen on dev->tstats. Reported-by: syzbot+9d4c12bfd45a58738d0a@syzkaller.appspotmail.com Reported-by: syzbot+a9e23ea2aa21044c2798@syzkaller.appspotmail.com Reported-by: syzbot+c4c4b2bb358bb936ad7e@syzkaller.appspotmail.com Reported-by: syzbot+0290d2290a607e035ba1@syzkaller.appspotmail.com Reported-by: syzbot+a43d8d4e7e8a7a9e149e@syzkaller.appspotmail.com Reported-by: syzbot+a47c5f4c6c00fc1ed16e@syzkaller.appspotmail.com Fixes: 039f50629b7f ("ip_tunnel: Move stats update to iptunnel_xmit()") Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tipc/udp_media.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) --- a/net/tipc/udp_media.c +++ b/net/tipc/udp_media.c @@ -174,7 +174,6 @@ static int tipc_udp_xmit(struct net *net goto tx_error; } - skb->dev = rt->dst.dev; ttl = ip4_dst_hoplimit(&rt->dst); udp_tunnel_xmit_skb(rt, ub->ubsock->sk, skb, src->ipv4.s_addr, dst->ipv4.s_addr, 0, ttl, 0, src->port, @@ -193,10 +192,9 @@ static int tipc_udp_xmit(struct net *net if (err) goto tx_error; ttl = ip6_dst_hoplimit(ndst); - err = udp_tunnel6_xmit_skb(ndst, ub->ubsock->sk, skb, - ndst->dev, &src->ipv6, - &dst->ipv6, 0, ttl, 0, src->port, - dst->port, false); + err = udp_tunnel6_xmit_skb(ndst, ub->ubsock->sk, skb, NULL, + &src->ipv6, &dst->ipv6, 0, ttl, 0, + src->port, dst->port, false); #endif } return err;