Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp669028ybg; Mon, 1 Jun 2020 11:13:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIK73FM37eO9DjlXM2ba2w/e18tyP4ADXW11j+kNzUtyljCa0edaM0ymaQwm3RXBrha970 X-Received: by 2002:aa7:c944:: with SMTP id h4mr22355854edt.383.1591035214129; Mon, 01 Jun 2020 11:13:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591035214; cv=none; d=google.com; s=arc-20160816; b=LdTzE4AhZuVycKMewoAcOnE09N+9a97LDFx3DS6xOWKm3SlFQ2DGlI5mzmwUYmh2aU 7pM89/v7UQ5Yo+EsZqovMw57gny1pCEyIX8VNmjTFKBTdq8dxBE4lSiEYD2DpSL+N3fI /4kFVvQXvuXIJE3kCFd0A9UliezrCxp6ae03zKBMwA4MB7yR7vqImxihWcKF39NY6n8u W5Km1ajBTMhNJxivVFnTObyiWjebr5m3/E+fPn+RJ7y0jRWoo5Q8dVpJya20384Qe2mW Yp+3AB1P6wELkfS53IAG+YhuFNfMmwUMFZq/e01RNPaF6qE+P5pNw8bICeF1xRUpv1Do LDuA== 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=1E5mCAM94qMo+pR7tMQWA7idIzcIQ6m9WXtZEcfbAQ8=; b=mw0vmVHlMcDVBnukWatM2JRb9dAz02KYTK7yrVDmWf3f2wOazNtfqPAvitKPvcliRl gpj5GQNqUETNB9zdSMu1UnMrjRMOd7BpEZ4pzwX1lm2LQX4LSo5NeU0+dW1nfFBmrrDz CpXNm/5AVljQvw4L1n7aU46AYr9kc6fyrXRV2nQN41Ouq7Sr2y/QXTTnttzTMXbJkPRF KvmQeu2PYxKXhK2j4KtWdv5HoaFGzWsf7UeVcSQZrpmBSLW2I4E3IAakUqYblnFhVl5U Azcpv5m9HKbdQEz+iUM7MQEo1zdkhLrylG4NLHM4O6O1WfMDqRWH8y7M4wOi4b0J0Hln HJyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rMaetlvg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g15si139892ejo.321.2020.06.01.11.13.09; Mon, 01 Jun 2020 11:13:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rMaetlvg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731010AbgFASKi (ORCPT + 99 others); Mon, 1 Jun 2020 14:10:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:57160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730990AbgFASKX (ORCPT ); Mon, 1 Jun 2020 14:10:23 -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 8E76E2077D; Mon, 1 Jun 2020 18:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591035022; bh=mSY6GPV+wUi0r7Ri6uN32T0DfG/wRgeooF1ikJq+pIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rMaetlvgNtPDBSndyGg15M6bfbj4hIdKSDN351c76IXK01lDyNDS9iASNFhAyNj6+ Bdurz2JTWJ2+CkblOm9IER+OpMqG+JBv7i+hEI0ZQWxdGGKlqibfSZop9Q+I/CbHeK xtW2akv1zo/w45bYkZ+kxj5rMGufE3ZrxD9RuXGY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiumei Mu , Xin Long , Steffen Klassert Subject: [PATCH 5.4 118/142] xfrm: fix a NULL-ptr deref in xfrm_local_error Date: Mon, 1 Jun 2020 19:54:36 +0200 Message-Id: <20200601174050.079724026@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200601174037.904070960@linuxfoundation.org> References: <20200601174037.904070960@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 f6a23d85d078c2ffde79c66ca81d0a1dde451649 upstream. This patch is to fix a crash: [ ] kasan: GPF could be caused by NULL-ptr deref or user memory access [ ] general protection fault: 0000 [#1] SMP KASAN PTI [ ] RIP: 0010:ipv6_local_error+0xac/0x7a0 [ ] Call Trace: [ ] xfrm6_local_error+0x1eb/0x300 [ ] xfrm_local_error+0x95/0x130 [ ] __xfrm6_output+0x65f/0xb50 [ ] xfrm6_output+0x106/0x46f [ ] udp_tunnel6_xmit_skb+0x618/0xbf0 [ip6_udp_tunnel] [ ] vxlan_xmit_one+0xbc6/0x2c60 [vxlan] [ ] vxlan_xmit+0x6a0/0x4276 [vxlan] [ ] dev_hard_start_xmit+0x165/0x820 [ ] __dev_queue_xmit+0x1ff0/0x2b90 [ ] ip_finish_output2+0xd3e/0x1480 [ ] ip_do_fragment+0x182d/0x2210 [ ] ip_output+0x1d0/0x510 [ ] ip_send_skb+0x37/0xa0 [ ] raw_sendmsg+0x1b4c/0x2b80 [ ] sock_sendmsg+0xc0/0x110 This occurred when sending a v4 skb over vxlan6 over ipsec, in which case skb->protocol == htons(ETH_P_IPV6) while skb->sk->sk_family == AF_INET in xfrm_local_error(). Then it will go to xfrm6_local_error() where it tries to get ipv6 info from a ipv4 sk. This issue was actually fixed by Commit 628e341f319f ("xfrm: make local error reporting more robust"), but brought back by Commit 844d48746e4b ("xfrm: choose protocol family by skb protocol"). So to fix it, we should call xfrm6_local_error() only when skb->protocol is htons(ETH_P_IPV6) and skb->sk->sk_family is AF_INET6. Fixes: 844d48746e4b ("xfrm: choose protocol family by skb protocol") Reported-by: Xiumei Mu Signed-off-by: Xin Long Signed-off-by: Steffen Klassert Signed-off-by: Greg Kroah-Hartman --- net/xfrm/xfrm_output.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/net/xfrm/xfrm_output.c +++ b/net/xfrm/xfrm_output.c @@ -645,7 +645,8 @@ void xfrm_local_error(struct sk_buff *sk if (skb->protocol == htons(ETH_P_IP)) proto = AF_INET; - else if (skb->protocol == htons(ETH_P_IPV6)) + else if (skb->protocol == htons(ETH_P_IPV6) && + skb->sk->sk_family == AF_INET6) proto = AF_INET6; else return;