From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AB54C43381 for ; Mon, 18 Mar 2019 09:46:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CEFEA204FD for ; Mon, 18 Mar 2019 09:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552902388; bh=JcMZjeu2QCWgd6sGB7e6CU0Gk+Dni6psG2uSJC4gsLo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=DJ33yDVq07X9vJogK62oXF/qpbQQACekqLzlmqwN8g/EdmH6vyMGxRKjoAeqOc866 nZn73Pj7A4fFvkTNy7u7JAYbp1iUetxYl9TRaFGE4VwmwqeJJNpP5np1xgJDOaE4Pq rONo1nHZui9G9x2RGvOnI6srYS0M9Ywa7qN/KF+Q= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728422AbfCRJq1 (ORCPT ); Mon, 18 Mar 2019 05:46:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:35116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728158AbfCRJ26 (ORCPT ); Mon, 18 Mar 2019 05:28:58 -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 998D82075C; Mon, 18 Mar 2019 09:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901338; bh=JcMZjeu2QCWgd6sGB7e6CU0Gk+Dni6psG2uSJC4gsLo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GT/IA+NaXnDxTuUa+dIeGyQSL3lceK8K5daWNayeSXgPB7JZ5+Z/+ddR6LweVHb8n 7kJpQHShkPpLCBBRjYZpGt15XgAqa6pTwq46GhirvobSr6DXE4kY1lTLt5KKnjwUUu 54qoDmMjU6FrZLHR1hnyiT2cNwBYD+yphFjXwv0Y= 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.20 15/52] route: set the deleted fnhe fnhe_daddr to 0 in ip_del_fnhe to fix a race Date: Mon, 18 Mar 2019 10:25:02 +0100 Message-Id: <20190318083845.234281555@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318083843.398913295@linuxfoundation.org> References: <20190318083843.398913295@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.20-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 @@ -1303,6 +1303,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;