From patchwork Thu Oct 3 15:49:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 175143 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp569023ill; Thu, 3 Oct 2019 09:39:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGcutqd/Bfupi+eAeVObNauJ25Ky+lGRvSCXHZkxjk34chWA6cDBz+64+F8D3DEdLL/2TB X-Received: by 2002:a05:6402:1a45:: with SMTP id bf5mr10243665edb.275.1570120761313; Thu, 03 Oct 2019 09:39:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570120761; cv=none; d=google.com; s=arc-20160816; b=UyFRGOa2HBFtmO2o6v9QKO5u9tUy8QMu0tqYdNko2KI4/CU74SI/1I+Z/Ecp0WMsqN YXyN0LSU/0f/GdZ+npAI0wTNkz+mP9C/sluBtV2KH/0T1Rv9Wp0nygsc6ODRRiB2dd4I xwjthrHDwmuTqhsUZglIBlIWl4O6Sm+YLsTQ8zYKRiLHdMa+ROatqnmgVlAQtFV1w0Vu /cz0a/QdU8wKzXaOoltcd3ehCZnwmxXMKhviXkDIZN0e1p1Pz//cGlxo2shk4bNAVFXa YTUMIU0geZmoewQBZ3IcNngUuITOzzUxW19ERb964Lfh8FpXvANpDeCMQLIbN1n8ZBgH HGIQ== 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=IQKa6JfM66a3dJn2xS/t3Fkh9JZJ54/vFGqhvlrKSKY=; b=d1j4YUSzlEVzz33go7h7Gip1XGluz+jHutYraFMShVg56hxBho6iGPUrElptQrPX1U bEJ2HIe/7PiOYY4kZ1TSqao2sxjdjRxAZtJ/tgMi2985Hpq7k6uv796POBWR6vH998xQ bELR523Qd5EM2lFDFV3cOuKvmzHb2+1GYTehc66ArzgXIEInw6ofx+zRKAkzT5EYhwXn PrXqDFXdBG+xRqi6clgEB/sCO0kGDAzjlSL1XONySL5L6Akj231cAxthve15OanBgCTI G80CakZTfEU5xqbcYag+l7UehuvNYX3iNFAn3zYCIZ1jY9yTNmY2Rgi2kP657xF0pmAs mP7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jyKWV5yx; 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 o27si1483647ejr.304.2019.10.03.09.39.21; Thu, 03 Oct 2019 09:39:21 -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=jyKWV5yx; 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 S2404732AbfJCQjT (ORCPT + 27 others); Thu, 3 Oct 2019 12:39:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:49164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404041AbfJCQjR (ORCPT ); Thu, 3 Oct 2019 12:39:17 -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 AC72E20830; Thu, 3 Oct 2019 16:39:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570120756; bh=LAc87+6+D18o5QYyIggT21SCRMDuq8+tv+1iJvp/tug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jyKWV5yx4fbKIx4F/qLXM4q/xUirKOup1RpwXIjZZ/k3Qq10l/b0r4q3N16EYFX79 4KQ+lpC1RVZ5ZwOl5V/Zzn++PKibzSMoWH7d92Qty7pcOMbBhvgsOyDVQtilMkT+s0 0WO3QKJUIrPNWeovzGVoJfNHCHzlaf+oTtOY/pnI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" , Wei Wang , "David S. Miller" Subject: [PATCH 5.3 003/344] ipv6: do not free rt if FIB_LOOKUP_NOREF is set on suppress rule Date: Thu, 3 Oct 2019 17:49:28 +0200 Message-Id: <20191003154540.394699981@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154540.062170222@linuxfoundation.org> References: <20191003154540.062170222@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Jason A. Donenfeld" [ Upstream commit ca7a03c4175366a92cee0ccc4fec0038c3266e26 ] Commit 7d9e5f422150 removed references from certain dsts, but accounting for this never translated down into the fib6 suppression code. This bug was triggered by WireGuard users who use wg-quick(8), which uses the "suppress-prefix" directive to ip-rule(8) for routing all of their internet traffic without routing loops. The test case added here causes the reference underflow by causing packets to evaluate a suppress rule. Fixes: 7d9e5f422150 ("ipv6: convert major tx path to use RT6_LOOKUP_F_DST_NOREF") Signed-off-by: Jason A. Donenfeld Acked-by: Wei Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv6/fib6_rules.c | 3 ++- tools/testing/selftests/net/fib_tests.sh | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) --- a/net/ipv6/fib6_rules.c +++ b/net/ipv6/fib6_rules.c @@ -287,7 +287,8 @@ static bool fib6_rule_suppress(struct fi return false; suppress_route: - ip6_rt_put(rt); + if (!(arg->flags & FIB_LOOKUP_NOREF)) + ip6_rt_put(rt); return true; } --- a/tools/testing/selftests/net/fib_tests.sh +++ b/tools/testing/selftests/net/fib_tests.sh @@ -9,7 +9,7 @@ ret=0 ksft_skip=4 # all tests in this script. Can be overridden with -t option -TESTS="unregister down carrier nexthop ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter" +TESTS="unregister down carrier nexthop suppress ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter" VERBOSE=0 PAUSE_ON_FAIL=no @@ -614,6 +614,20 @@ fib_nexthop_test() cleanup } +fib_suppress_test() +{ + $IP link add dummy1 type dummy + $IP link set dummy1 up + $IP -6 route add default dev dummy1 + $IP -6 rule add table main suppress_prefixlength 0 + ping -f -c 1000 -W 1 1234::1 || true + $IP -6 rule del table main suppress_prefixlength 0 + $IP link del dummy1 + + # If we got here without crashing, we're good. + return 0 +} + ################################################################################ # Tests on route add and replace @@ -1591,6 +1605,7 @@ do fib_carrier_test|carrier) fib_carrier_test;; fib_rp_filter_test|rp_filter) fib_rp_filter_test;; fib_nexthop_test|nexthop) fib_nexthop_test;; + fib_suppress_test|suppress) fib_suppress_test;; ipv6_route_test|ipv6_rt) ipv6_route_test;; ipv4_route_test|ipv4_rt) ipv4_route_test;; ipv6_addr_metric) ipv6_addr_metric_test;;