From patchwork Sat Apr 22 16:40:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 753786 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3w9JNB4ZC5z9s7d for ; Sun, 23 Apr 2017 02:44:10 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=cumulusnetworks.com header.i=@cumulusnetworks.com header.b="HMdZGUIy"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425792AbdDVQkp (ORCPT ); Sat, 22 Apr 2017 12:40:45 -0400 Received: from mail-it0-f48.google.com ([209.85.214.48]:36362 "EHLO mail-it0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1425777AbdDVQkn (ORCPT ); Sat, 22 Apr 2017 12:40:43 -0400 Received: by mail-it0-f48.google.com with SMTP id g66so17436435ite.1 for ; Sat, 22 Apr 2017 09:40:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cumulusnetworks.com; s=google; h=from:to:cc:subject:date:message-id; bh=MO8jJ1Oa5M2mZtps5Bs0nqGMgdyCFLNnNJSKY3CGuec=; b=HMdZGUIyFviUr1dx0e+d//E6Q7ETDwBLpOflof9mOdPfXV7NaP33+Zn0B/X0W8dAJc TiJXhKkeZxqxJG/53gem0fXW6CVz2KUm51rFaf3omyekuVWoWT7/InM6DfU7P/RyEXgd I6qGCJ89UuCxjR/vSu1jefvpZBeOReS9Mz8cY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=MO8jJ1Oa5M2mZtps5Bs0nqGMgdyCFLNnNJSKY3CGuec=; b=cPWe2xwOCCt1ZyZDir9SbU0lhblPT9ZYm+jGQlStBUcFjRff9COxq5YUe6WyZ5Dkua jJFbzl7fOhBq/9Ef0Xmy36BBK+navzewrOWpszHad58ivfUeDDLyCA5TBK06ANXDf1aI 1rewWHHvyqKiKLuy1YLOd3qEih9cRKcZR2EY0dwgevRmAzWneVw6GkpjalBZtyzTAvs3 W/TQLA332joaNvi2qL2RgpE8pWIygzrc4pJ9IjBrNHa2ibd8MqoV4TfFaqELCYEmLl+M 7dbVq/wqipkL4DTrf3yMXNHqj+q4+E9FMcyvEQXPIZMAjbPRNeJv9sMZ4+OPeccqqtCo GBPw== X-Gm-Message-State: AN3rC/6nswYjafEPs286Xn4NbILhoyMA4Q79kHEZrABY1pvXIHp/hbPO M2o1+Q5RNrrfnBWP X-Received: by 10.99.56.91 with SMTP id h27mr17134801pgn.97.1492879242369; Sat, 22 Apr 2017 09:40:42 -0700 (PDT) Received: from kenny.it.cumulusnetworks.com. ([216.129.126.126]) by smtp.googlemail.com with ESMTPSA id q1sm22342444pfl.89.2017.04.22.09.40.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 22 Apr 2017 09:40:41 -0700 (PDT) From: David Ahern To: netdev@vger.kernel.org Cc: dvyukov@google.com, andreyknvl@google.com, mmanning@brocade.com, David Ahern Subject: [PATCH v2 net] net: ipv6: regenerate host route if moved to gc list Date: Sat, 22 Apr 2017 09:40:37 -0700 Message-Id: <1492879237-31566-1-git-send-email-dsa@cumulusnetworks.com> X-Mailer: git-send-email 2.1.4 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Taking down the loopback device wreaks havoc on IPv6 routes. By extension, taking a VRF device wreaks havoc on its table. Dmitry and Andrey both reported heap out-of-bounds reports in the IPv6 FIB code while running syzkaller fuzzer. The root cause is a dead dst that is on the garbage list gets reinserted into the IPv6 FIB. While on the gc (or perhaps when it gets added to the gc list) the dst->next is set to an IPv4 dst. A subsequent walk of the ipv6 tables causes the out-of-bounds access. Andrey's reproducer was the key to getting to the bottom of this. With IPv6, host routes for an address have the dst->dev set to the loopback device. When the 'lo' device is taken down, rt6_ifdown initiates a walk of the fib evicting routes with the 'lo' device which means all host routes are removed. That process moves the dst which is attached to an inet6_ifaddr to the gc list and marks it as dead. The recent change to keep global IPv6 addresses added a new function fixup_permanent_addr that is called on admin up. That function restarts dad for an inet6_ifaddr and when it completes the host route attached to it is inserted into the fib. Since the route was marked dead and moved to the gc list, we get the reported out-of-bounds accesses. If the device with the address is taken down or the address is removed, the WARN_ON in fib6_del is triggered. All of those faults are fixed by regenerating the host route of the existing one has been moved to the gc list, something that can be determined by checking if the rt6i_ref counter is 0. Fixes: f1705ec197e7 ("net: ipv6: Make address flushing on ifdown optional") Reported-by: Dmitry Vyukov Reported-by: Andrey Konovalov Signed-off-by: David Ahern --- v2 - change ifp->rt under spinlock vs cmpxchg - add comment about rt6i_ref == 0 Dmitry / Andrey: can you guys add this patch to your tree and run syzkaller tests? I'd like to confirm that all of the fib traces are fixed. Thanks. net/ipv6/addrconf.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 08f9e8ea7a81..97e86158bbcb 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -3303,14 +3303,24 @@ static void addrconf_gre_config(struct net_device *dev) static int fixup_permanent_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) { - if (!ifp->rt) { - struct rt6_info *rt; + /* rt6i_ref == 0 means the host route was removed from the + * FIB, for example, if 'lo' device is taken down. In that + * case regenerate the host route. + */ + if (!ifp->rt || !atomic_read(&ifp->rt->rt6i_ref)) { + struct rt6_info *rt, *prev; rt = addrconf_dst_alloc(idev, &ifp->addr, false); if (unlikely(IS_ERR(rt))) return PTR_ERR(rt); + spin_lock(&ifp->lock); + prev = ifp->rt; ifp->rt = rt; + spin_unlock(&ifp->lock); + + if (prev) + ip6_rt_put(prev); } if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) {