Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1019124ybe; Wed, 4 Sep 2019 11:13:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4XP6p+2IkVYU1YIyzKq7o5krDZxwOABVjxuaE0OZ43JE4rUK0AWbYVq30U07D66TdduU+ X-Received: by 2002:a63:2807:: with SMTP id o7mr36891739pgo.131.1567620830978; Wed, 04 Sep 2019 11:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620830; cv=none; d=google.com; s=arc-20160816; b=fwovuS7dyO85HXyq800euHJADviLqnMrdmKDWiDgWMJW1hYwmcLvCsoqGQADLXIDw2 +SqE72sOtlqLnK2KXl6U+HnN6BV1iDdvN9y2ktNSBFZFPRhoRwHxWTqUI4wq2fvgPIKG 8tv7h4qebSOuNzsR2AYx6aVB7AOWdhwI6HMLDiTULReYUYX2rO5QTLe1t4DNFswlMo51 JuIsRrFFVlhm4SPLZ9nvipZmxrTCA6PSI4AlsgsLpnLSLjeK6f5jTZcV0U5D0gs1nF68 TtCU4n7KauOsBtxeLLdseSqrlK94/ACeseLzQhhTzM0S/jBFha3Jyj7tj6VaUNu/y9nn 6Byg== 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=g8ywNun3WRF/Syx0DsFqljEbJumtF2by27FMnooCaRg=; b=gG3Pgkk+7KW6QLP/7/0CIRtuGQmSM9rrvgWm232Gc5qp0bnuQeLALNv4chfwIiKWkm UJ7cTbkV2daHqaCP5fShZzWzrjOql99BorYaaKWZnNXb5AR53h8HCNRe+qfH3B1YZZBz 82k2xbbNG1NCPnGPSAHP3bqx4l6sYTFTRcjYCX6nGNkbL68I3eSjsdmYImhaLgRWElrj TKehc6pguLVTYzy/Ja+SrSe1ABHuNvAsaAW3Dm/O42dt/wFEmYdVEEe2Hiq398U4ZuuV /99yCDwfr8XkD11i83c8Sunfh0SHuxAeznLFJ6wTWyAZ3QVzCSZ/c7fBeuE1nyzxfyPJ TG8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WVby9yfx; 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 125si15269092pgh.229.2019.09.04.11.13.34; Wed, 04 Sep 2019 11:13:50 -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=WVby9yfx; 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 S2390463AbfIDSMN (ORCPT + 99 others); Wed, 4 Sep 2019 14:12:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:56520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389430AbfIDSML (ORCPT ); Wed, 4 Sep 2019 14:12:11 -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 DF31B206BA; Wed, 4 Sep 2019 18:12:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620731; bh=YlhfXH73FxayUwhM+ST/fbMumodBzl9+Y/ZyvlbGsks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WVby9yfxRIFZajrGItZ6ANNI2Lwe8vWe7Zr50lzWBhijoFL6WTf6hEy/DGJW83r81 ChN/FLgoDujJA2FBeuLaTJCglZ+887OkVq61t4JdOcD7ayWaT77zLke18ak/NUXLm6 wbnKfjglp8MYa+4jj9aiAe6EAt3+wMM6nxKqHCco= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangbin Liu , Julian Anastasov , Jonathan Lemon , "David S. Miller" Subject: [PATCH 5.2 057/143] ipv4/icmp: fix rt dst dev null pointer dereference Date: Wed, 4 Sep 2019 19:53:20 +0200 Message-Id: <20190904175316.305229399@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@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: Hangbin Liu [ Upstream commit e2c693934194fd3b4e795635934883354c06ebc9 ] In __icmp_send() there is a possibility that the rt->dst.dev is NULL, e,g, with tunnel collect_md mode, which will cause kernel crash. Here is what the code path looks like, for GRE: - ip6gre_tunnel_xmit - ip6gre_xmit_ipv4 - __gre6_xmit - ip6_tnl_xmit - if skb->len - t->tun_hlen - eth_hlen > mtu; return -EMSGSIZE - icmp_send - net = dev_net(rt->dst.dev); <-- here The reason is __metadata_dst_init() init dst->dev to NULL by default. We could not fix it in __metadata_dst_init() as there is no dev supplied. On the other hand, the reason we need rt->dst.dev is to get the net. So we can just try get it from skb->dev when rt->dst.dev is NULL. v4: Julian Anastasov remind skb->dev also could be NULL. We'd better still use dst.dev and do a check to avoid crash. v3: No changes. v2: fix the issue in __icmp_send() instead of updating shared dst dev in {ip_md, ip6}_tunnel_xmit. Fixes: c8b34e680a09 ("ip_tunnel: Add tnl_update_pmtu in ip_md_tunnel_xmit") Signed-off-by: Hangbin Liu Reviewed-by: Julian Anastasov Acked-by: Jonathan Lemon Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/icmp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -582,7 +582,13 @@ void __icmp_send(struct sk_buff *skb_in, if (!rt) goto out; - net = dev_net(rt->dst.dev); + + if (rt->dst.dev) + net = dev_net(rt->dst.dev); + else if (skb_in->dev) + net = dev_net(skb_in->dev); + else + goto out; /* * Find the original header. It is expected to be valid, of course.