Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp267794img; Mon, 18 Mar 2019 02:40:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTJZNMddeS1ZFm2c4iFl4IX27SB8nDCKt/m+bOZcMQjdNTEyItCWl2pYgowGIH0uVOqAWi X-Received: by 2002:a62:54c5:: with SMTP id i188mr17860428pfb.188.1552902050534; Mon, 18 Mar 2019 02:40:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552902050; cv=none; d=google.com; s=arc-20160816; b=tzim1vyp3X5UC36tWlVabACKG8o/d1rzoZY3G9IrKSHzgNMWwFEwCGBtogu+VItTHQ YJEU+C6vNvfcaeh/n63ISdslRVZ2RJTXE4IK0/lL8Mjj2tpPxT+ya7GaWtHt6eks4M8p J8BWfYTdrMi6P4DgOD04plZ9L+juiiMZu6RiCteTNELTKRQqkxwNpxw7DRuMTHV0G7Um 6yY6RhktVJ9Gwb0Bzn/5vfyZZQFGK3vjf8BMGKB3FHaXBfp5CsR3Ok7TFDbliibfTeu6 Kkg9dLRFxIIKm4Ebw/CXu3LalO9Qtu/sKeN8hMUak3MVUgRaMjTy+T8RmXunDKwWK+px lGgQ== 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=txw8HgxVTD1JQuOOqmkU7yQILqLhjimD8GuHTiBkfiE=; b=kRD/d9TSYqYLZ2cvDOUPF4Dw5hWF9WemGEW41t1tgRMicF9WXe2+O14JRLdgvho3Zq M/+QX6gUvh8RB7QTV6RlONH6gFfTFyEDuaMaKa4wnOFz1bYjUbs99DH/1gZF0dbSxlOv nwoPcUlN1e9Kk2EJkXEQu2bR9Qb26+PJ9AHQ+pO3U8GPWqLD12aGucm80lJdv6HpCE64 apSkV/N8KhuDdCu1eNvdiYS9kdSHQS4V5HPNnpOBjT8Rzzdggq+RcR6C0hFSyQk3f0ce uBb+3HsrgQwtj12c2IRKIi5GnDC/4kVDYSGHxI2vxPK9X0icIMsGu30sRQNphq5pucYs DIig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uGnUalXG; 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 j26si9070620pfe.175.2019.03.18.02.40.35; Mon, 18 Mar 2019 02:40:50 -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=uGnUalXG; 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 S2387636AbfCRJgT (ORCPT + 99 others); Mon, 18 Mar 2019 05:36:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:44632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387628AbfCRJgS (ORCPT ); Mon, 18 Mar 2019 05:36:18 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.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 F07592075C; Mon, 18 Mar 2019 09:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901777; bh=Y7slDSS7yhLr63Fwuoe2chnmWbzkPAB9T0JbA216mmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uGnUalXGWGGJY7aQgHF5h6vf2uDOFZtFlGGhd4YJ1b2bRGz0kUkC9Kqfp0SlKqTzu vpo7Vk9nal0qz9tohujmlEjpqaSJYNHI4x3F2kXItbD8nP8pMqGB63xLehcVYywhuT 4N8hlxjatriqu1RqcMjvXbNtMN9TQ0LNvvtzLUvc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jon Maxwell , Xin Long , David Ahern , "David S. Miller" Subject: [PATCH 4.9 11/31] route: set the deleted fnhe fnhe_daddr to 0 in ip_del_fnhe to fix a race Date: Mon, 18 Mar 2019 10:25:46 +0100 Message-Id: <20190318084210.849638740@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318084210.397476003@linuxfoundation.org> References: <20190318084210.397476003@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Xin Long [ Upstream commit ee60ad219f5c7c4fb2f047f88037770063ef785f ] The race occurs in __mkroute_output() when 2 threads lookup a dst: CPU A CPU B find_exception() find_exception() [fnhe expires] ip_del_fnhe() [fnhe is deleted] rt_bind_exception() In rt_bind_exception() it will bind a deleted fnhe with the new dst, and this dst will get no chance to be freed. It causes a dev defcnt leak and consecutive dmesg warnings: unregister_netdevice: waiting for ethX to become free. Usage count = 1 Especially thanks Jon to identify the issue. This patch fixes it by setting fnhe_daddr to 0 in ip_del_fnhe() to stop binding the deleted fnhe with a new dst when checking fnhe's fnhe_daddr and daddr in rt_bind_exception(). It works as both ip_del_fnhe() and rt_bind_exception() are protected by fnhe_lock and the fhne is freed by kfree_rcu(). Fixes: deed49df7390 ("route: check and remove route cache when we get route") Signed-off-by: Jon Maxwell Signed-off-by: Xin Long Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/route.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1613,6 +1613,10 @@ static void ip_del_fnhe(struct fib_nh *n if (fnhe->fnhe_daddr == daddr) { rcu_assign_pointer(*fnhe_p, rcu_dereference_protected( fnhe->fnhe_next, lockdep_is_held(&fnhe_lock))); + /* set fnhe_daddr to 0 to ensure it won't bind with + * new dsts in rt_bind_exception(). + */ + fnhe->fnhe_daddr = 0; fnhe_flush_routes(fnhe); kfree_rcu(fnhe, rcu); break;