Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2182890ybm; Thu, 23 May 2019 12:43:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/edyY9a++ZGjoSFdfGuHJDppnFBXytM6lGbdqkVVi12IsHuptDAj8Hrv5LKhbu0sfO4Am X-Received: by 2002:a17:902:850a:: with SMTP id bj10mr32748105plb.196.1558640620012; Thu, 23 May 2019 12:43:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558640620; cv=none; d=google.com; s=arc-20160816; b=Qumzd1y/+qjTDOpnSvtNJy2anzYWTkjHGf6vk0UQAw8X0223Z80CZM3pDMIwfdCS2H nLB3A+bBnWYQ12osfo6VYKHtWF4cb7NnG1ve1rOczg+DNoTVuwEXJqmAB6b75eKYsRvF N/8Xxe3Mtf8ERwT7lN6bhu74kc0QgthMacnbHE1sHpeErO/Xap5rdnV/IKk6jWAv6VBv OZzMekESHOdPorRc95Y3hUmQsuoM5LOJo8LZqGNLr6bvsaD2bgAAnff0mWUU9jARa9ie M9Xqch2/HCUfUglBtfc19kIHOHhUZvaqQRvp6wQGCttTjgodEvvbG19Qz3UuEZQnCNHF nuUw== 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=PEF2afoIQzuoAitxbM6DhsrrYmsju4gpJO/VYx9PMn4=; b=pf5+HRs43Oct0EaXdntABVG6KzwGNEqUmDlfCoPMgL620edappc9RU9xB7BPdVlPEN so5siM/n3MYmQseG2CDOlP/Uo0Svk2KG6Ee4fv471im2RKczrgreTl6d2AmUsFo8UkYN vF584V9+JMY4Snq+c02mi3EMiTJwtagh6mFA/7E2GEa6O6xHPBbBT8Mcw56R1b/zY9+H GeKFLGwhHQZyYEjwBgTP2ugbNFIsesY/LwOjL6x2vqq/icYcVVsDkv6uVjSd5rTpFFyi eTMyqj8rhFcn6ZuvIH66K29Ir+6np5l2MSHeIWB26kRhHT1uL2HZc1Nrl2SqgCyH7z9N JUIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QzTbwweZ; 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 b20si282998pjo.107.2019.05.23.12.43.25; Thu, 23 May 2019 12:43:39 -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=QzTbwweZ; 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 S2390463AbfEWTla (ORCPT + 99 others); Thu, 23 May 2019 15:41:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:56300 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389233AbfEWTTy (ORCPT ); Thu, 23 May 2019 15:19:54 -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 9A7802133D; Thu, 23 May 2019 19:19:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639194; bh=nZGcgFc2z8V4eaNeBmEJckrEFcB5RsTgV1d1vKVSKko=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QzTbwweZKLyGstodRi1KDDU6LVul3fqBbVh4ZydsoYkah9+tmPkDt7txd5z5Qb+rP h9nqvvSm7CTASY0LWAccXOoC27CUuKxtJb1r61/nZi00U2DNX/Ts6LIfcUq7aIf0ZP 2ubh/wb6gPl4Prx3PdvmHcb4lw+1B8thHCFNC6Ho= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , Wei Wang , David Ahern , Martin Lau , "David S. Miller" Subject: [PATCH 5.0 002/139] ipv6: prevent possible fib6 leaks Date: Thu, 23 May 2019 21:04:50 +0200 Message-Id: <20190523181720.502832383@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181720.120897565@linuxfoundation.org> References: <20190523181720.120897565@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: Eric Dumazet [ Upstream commit 61fb0d01680771f72cc9d39783fb2c122aaad51e ] At ipv6 route dismantle, fib6_drop_pcpu_from() is responsible for finding all percpu routes and set their ->from pointer to NULL, so that fib6_ref can reach its expected value (1). The problem right now is that other cpus can still catch the route being deleted, since there is no rcu grace period between the route deletion and call to fib6_drop_pcpu_from() This can leak the fib6 and associated resources, since no notifier will take care of removing the last reference(s). I decided to add another boolean (fib6_destroying) instead of reusing/renaming exception_bucket_flushed to ease stable backports, and properly document the memory barriers used to implement this fix. This patch has been co-developped with Wei Wang. Fixes: 93531c674315 ("net/ipv6: separate handling of FIB entries from dst based routes") Signed-off-by: Eric Dumazet Reported-by: syzbot Cc: Wei Wang Cc: David Ahern Cc: Martin Lau Acked-by: Wei Wang Acked-by: Martin KaFai Lau Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/ip6_fib.h | 3 ++- net/ipv6/ip6_fib.c | 12 +++++++++--- net/ipv6/route.c | 7 +++++++ 3 files changed, 18 insertions(+), 4 deletions(-) --- a/include/net/ip6_fib.h +++ b/include/net/ip6_fib.h @@ -171,7 +171,8 @@ struct fib6_info { dst_nocount:1, dst_nopolicy:1, dst_host:1, - unused:3; + fib6_destroying:1, + unused:2; struct fib6_nh fib6_nh; struct rcu_head rcu; --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -909,6 +909,12 @@ static void fib6_drop_pcpu_from(struct f { int cpu; + /* Make sure rt6_make_pcpu_route() wont add other percpu routes + * while we are cleaning them here. + */ + f6i->fib6_destroying = 1; + mb(); /* paired with the cmpxchg() in rt6_make_pcpu_route() */ + /* release the reference to this fib entry from * all of its cached pcpu routes */ @@ -932,6 +938,9 @@ static void fib6_purge_rt(struct fib6_in { struct fib6_table *table = rt->fib6_table; + if (rt->rt6i_pcpu) + fib6_drop_pcpu_from(rt, table); + if (atomic_read(&rt->fib6_ref) != 1) { /* This route is used as dummy address holder in some split * nodes. It is not leaked, but it still holds other resources, @@ -953,9 +962,6 @@ static void fib6_purge_rt(struct fib6_in fn = rcu_dereference_protected(fn->parent, lockdep_is_held(&table->tb6_lock)); } - - if (rt->rt6i_pcpu) - fib6_drop_pcpu_from(rt, table); } } --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -1260,6 +1260,13 @@ static struct rt6_info *rt6_make_pcpu_ro prev = cmpxchg(p, NULL, pcpu_rt); BUG_ON(prev); + if (rt->fib6_destroying) { + struct fib6_info *from; + + from = xchg((__force struct fib6_info **)&pcpu_rt->from, NULL); + fib6_info_release(from); + } + return pcpu_rt; }