Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6567579ybx; Mon, 11 Nov 2019 11:05:06 -0800 (PST) X-Google-Smtp-Source: APXvYqwcnW3HoqlMc4uSHBGmeqvEicWYDev090mtNRlzD329TEM663dV17jND+9mR3KpP2jCBSwS X-Received: by 2002:a17:906:454a:: with SMTP id s10mr5346595ejq.60.1573499106655; Mon, 11 Nov 2019 11:05:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573499106; cv=none; d=google.com; s=arc-20160816; b=YXLWD5QfFMGkLgecT704Xp9SgXOCZDWhlzw11n5//9f6QOPP/OhvY/deQCLTxhEi1r rp8KbW5RG/adnmE1kuYf+eaUlyPN2forNbGvqUzpyawOjPyeN1slUy0q8EQOPhpFtePK deZvVwYIoepRSkwL2Cy65CGj1FhsbxypVZrBWaxOfNpKFwsjtHGpDNyB6FaBqMV1QbB/ P52ohDgn+1T0J81ENtXvkNT1ti6Fz6Vq85vNtn2H9ic2BelmvBAjR2E/1hqmm0UUvjXV 3rrBAINZFD1nNI1drRTyWsIdOGWdeaR/f/H3o2BydL3RUP+aZb7FUtU/fNCTbSfluGrT pJKA== 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=mO764RvgfFSVhUd2nxNLojpXQwCDp/ev6teS8WEZTvg=; b=z91bD5//K+KvV4vlExuodLaHYDf06s7MwNH+hTxdWnomHs5Hq+6G+a+lxe5EfPKlJL BjJOh1mh24yq9Nxy/yF84PzFYzhWH3e2JC3VZw4Nd3VBzDNYP1zDEY8yDX6t7qzMRM41 GaRtilBfSPftKd7WyAT1fmZRe2ao0u6zMxk2vVboa26dKDO0sAmNtqQTt5QAmfzUlwNF Zpa2b9XJPb9Vpvk9xSEmFAQeLaBV12Kf7RSGqpfyQ+aGtlrnt4wAS8lJNoU5XwEdvmXu ngFaZ/icf12FvVQYNu5+6Tg0GfnxAmcD5zqh54mO8U10QDFYijzR1KOOYZHNTodJ+W8n 5x3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ioFb8Cl9; 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 p20si10092502edq.121.2019.11.11.11.04.30; Mon, 11 Nov 2019 11:05:06 -0800 (PST) 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=ioFb8Cl9; 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 S1730507AbfKKSw3 (ORCPT + 99 others); Mon, 11 Nov 2019 13:52:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:46778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729608AbfKKSw0 (ORCPT ); Mon, 11 Nov 2019 13:52:26 -0500 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 8C97E214E0; Mon, 11 Nov 2019 18:52:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498346; bh=jpbIPP49zvHFC2TMrGanJSqYYGPqKzLDrVU9Or1jmEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ioFb8Cl9c4GfSESA0vP+eVSdva2JNMRZpTxDYi/bPnZmQBuzns8to8YO96pxYplgO 7dJofPN+LnsEw8OnKxceHhqWBOOfncvSrV4rO060gCMZTySjVSvKD6biXNIAgRWrk7 365L7GLPSGwA5QOHuJUDf3e9ZXp4A1FkSd/DNZ7A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Benc , Alexei Starovoitov , Peter Oskolkov , Sasha Levin Subject: [PATCH 5.3 093/193] bpf: lwtunnel: Fix reroute supplying invalid dst Date: Mon, 11 Nov 2019 19:27:55 +0100 Message-Id: <20191111181508.002089805@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@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: Jiri Benc [ Upstream commit 9e8acd9c44a0dd52b2922eeb82398c04e356c058 ] The dst in bpf_input() has lwtstate field set. As it is of the LWTUNNEL_ENCAP_BPF type, lwtstate->data is struct bpf_lwt. When the bpf program returns BPF_LWT_REROUTE, ip_route_input_noref is directly called on this skb. This causes invalid memory access, as ip_route_input_slow calls skb_tunnel_info(skb) that expects the dst->lwstate->data to be struct ip_tunnel_info. This results to struct bpf_lwt being accessed as struct ip_tunnel_info. Drop the dst before calling the IP route input functions (both for IPv4 and IPv6). Reported by KASAN. Fixes: 3bd0b15281af ("bpf: add handling of BPF_LWT_REROUTE to lwt_bpf.c") Signed-off-by: Jiri Benc Signed-off-by: Alexei Starovoitov Acked-by: Peter Oskolkov Link: https://lore.kernel.org/bpf/111664d58fe4e9dd9c8014bb3d0b2dab93086a9e.1570609794.git.jbenc@redhat.com Signed-off-by: Sasha Levin --- net/core/lwt_bpf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c index f93785e5833c1..74cfb8b5ab330 100644 --- a/net/core/lwt_bpf.c +++ b/net/core/lwt_bpf.c @@ -88,11 +88,16 @@ static int bpf_lwt_input_reroute(struct sk_buff *skb) int err = -EINVAL; if (skb->protocol == htons(ETH_P_IP)) { + struct net_device *dev = skb_dst(skb)->dev; struct iphdr *iph = ip_hdr(skb); + dev_hold(dev); + skb_dst_drop(skb); err = ip_route_input_noref(skb, iph->daddr, iph->saddr, - iph->tos, skb_dst(skb)->dev); + iph->tos, dev); + dev_put(dev); } else if (skb->protocol == htons(ETH_P_IPV6)) { + skb_dst_drop(skb); err = ipv6_stub->ipv6_route_input(skb); } else { err = -EAFNOSUPPORT; -- 2.20.1