Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp686984pxv; Thu, 22 Jul 2021 09:43:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ1Y60X5crXetLyokpKb0UVL/zgyi5uay080BRFrnGC6cy+HWmtrOkrjAoirDHtnlvH+q8 X-Received: by 2002:aa7:d04d:: with SMTP id n13mr617087edo.31.1626972237320; Thu, 22 Jul 2021 09:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626972237; cv=none; d=google.com; s=arc-20160816; b=Zh/DL/0/qiR/PXN2uIg1vJxLuh+NI/1/pPvnL6PT66w5ARZKdo87/RTKei7IZSBPBs jOd00yY6ztDCaeCtaGmw6aB5y7qeC+ckSN6z2VBRrdlcaNwFDHyvku3UqYx4D1olofxL 9pmvcN0JsO882I2PJ7WVyQaTk9UTwmOttLc6yTpocTebUprxPSl77NcbKZpqmXmpvcIf muGeuZtcQ+5dItwyJSXpDIlVjv8SdFAFQeGOCWIswreY8HhXvx6htfF1KEA9zXrBjjvu cUOhY+kadhlKxa2W4DsHbo1a4n5fN7zenB9Ik3HqMH/ZWZuM3Z9YOhy+1F4tYqEgiLOS apFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uyYISl2zRXb1rAk0qMMqhguq18y3CODVkGFVjbj1EeE=; b=STMzfndzNyUn4tc0JLpRl8yzRAsgBoczreO+yrVQVPwgMSHXAf5tLp7NeIQJN8VQJl ar1gEtcCCnA8poLw+wGYSl7QSqn1aDfc3veDTcgSMT8XQLBcRhCeuzP0y84FA7k2P4j9 z/voPZ+gqaJ6Gj5r7asPapt99mGh7GuHZ9PkL5JqDUi99XML13XTfziT+RHCSx+1OCPA bk51mgm19o2ddDh68YKdvAvOKtLBendhykS3YYAsxsd1KX+1taCn0EvrmWonz2xPymuN cCPNm/cfXXCLvfqiB0zTkx8eWbYdAaRw9FI0ij8HqKVrap+kjnZSnOGMJpDsHJqmctSH DA6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bgaGCuxR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kf22si32621147ejc.5.2021.07.22.09.43.21; Thu, 22 Jul 2021 09:43:57 -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=@linuxfoundation.org header.s=korg header.b=bgaGCuxR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233129AbhGVQBd (ORCPT + 99 others); Thu, 22 Jul 2021 12:01:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:34386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233640AbhGVP7Y (ORCPT ); Thu, 22 Jul 2021 11:59:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1E06B6136D; Thu, 22 Jul 2021 16:39:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626971998; bh=vkWlvfb4ycAPPd45vepT5PJubllMfFDd1nNu40uhXqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bgaGCuxR/ziLhTAM/KFQ1fpqevFykqSCzpJjqTzjHeqZtLzBP8BsqCh/zmXFgFDu7 FUR9zNtCND49he386Vlcw+yZvkgNoT1KhT6bi1Qm5bJNjNhdQI+nl8wAcOE2blwkc1 6sHMqD2WmT9HTpZWPSSVxjr1DEBw+v7tZ43O6fm8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Taehee Yoo , "David S. Miller" Subject: [PATCH 5.10 107/125] net: validate lwtstate->data before returning from skb_tunnel_info() Date: Thu, 22 Jul 2021 18:31:38 +0200 Message-Id: <20210722155628.260260833@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210722155624.672583740@linuxfoundation.org> References: <20210722155624.672583740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Taehee Yoo commit 67a9c94317402b826fc3db32afc8f39336803d97 upstream. skb_tunnel_info() returns pointer of lwtstate->data as ip_tunnel_info type without validation. lwtstate->data can have various types such as mpls_iptunnel_encap, etc and these are not compatible. So skb_tunnel_info() should validate before returning that pointer. Splat looks like: BUG: KASAN: slab-out-of-bounds in vxlan_get_route+0x418/0x4b0 [vxlan] Read of size 2 at addr ffff888106ec2698 by task ping/811 CPU: 1 PID: 811 Comm: ping Not tainted 5.13.0+ #1195 Call Trace: dump_stack_lvl+0x56/0x7b print_address_description.constprop.8.cold.13+0x13/0x2ee ? vxlan_get_route+0x418/0x4b0 [vxlan] ? vxlan_get_route+0x418/0x4b0 [vxlan] kasan_report.cold.14+0x83/0xdf ? vxlan_get_route+0x418/0x4b0 [vxlan] vxlan_get_route+0x418/0x4b0 [vxlan] [ ... ] vxlan_xmit_one+0x148b/0x32b0 [vxlan] [ ... ] vxlan_xmit+0x25c5/0x4780 [vxlan] [ ... ] dev_hard_start_xmit+0x1ae/0x6e0 __dev_queue_xmit+0x1f39/0x31a0 [ ... ] neigh_xmit+0x2f9/0x940 mpls_xmit+0x911/0x1600 [mpls_iptunnel] lwtunnel_xmit+0x18f/0x450 ip_finish_output2+0x867/0x2040 [ ... ] Fixes: 61adedf3e3f1 ("route: move lwtunnel state to dst_entry") Signed-off-by: Taehee Yoo Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/dst_metadata.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/include/net/dst_metadata.h +++ b/include/net/dst_metadata.h @@ -45,7 +45,9 @@ skb_tunnel_info(const struct sk_buff *sk return &md_dst->u.tun_info; dst = skb_dst(skb); - if (dst && dst->lwtstate) + if (dst && dst->lwtstate && + (dst->lwtstate->type == LWTUNNEL_ENCAP_IP || + dst->lwtstate->type == LWTUNNEL_ENCAP_IP6)) return lwt_tun_info(dst->lwtstate); return NULL;